473,466 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Visual Basic - Help with class project

4 New Member
I'm in a visual basic programming class at my community college and I'm having one hell of a time trying to figure this out. I'm supposed to create a weekly pay calculator as a project for class, so here's my dilemma:

I have this code thus far figured out:

Expand|Select|Wrap|Line Numbers
  1. Public Class Frmweeklypaycalculator
  2.  
  3.     Private Sub btnweeklypay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnweeklypay.Click
  4.         ' This event handler is executed when the user clicks the
  5.         ' Weekly Pay button. It calculates and displays the 
  6.         ' amount to be paid (number of minutes times hourly rate).
  7.  
  8.         Dim strTotalMinutesWorked As String
  9.         Dim strTotalHourlyRate As String
  10.         Dim intTotalMinutesWorked As Integer
  11.         Dim intTotalHoursWorked As Integer
  12.         Dim decTotalWeeklyPay As Decimal
  13.  
  14.         strTotalMinutesWorked = Me.Txtminworked.Text
  15.         strTotalHourlyRate = Me.Txthourpay.Text
  16.         intTotalMinutesWorked = Convert.ToInt32(strTotalMinutesWorked)
  17.  
  18.         intTotalHoursWorked = CInt((intTotalMinutesWorked / 60))
  19.         decTotalWeeklyPay = CDec(intTotalHoursWorked * CDbl(strTotalHourlyRate))
  20.  
  21.         Me.Lblhrsworkednum.Text = intTotalHoursWorked.ToString("c")
  22.         Me.Lblweeklypaynum.Text = decTotalWeeklyPay.ToString("c")
and this is how the form looks so far:



Now what I want to do is get rid of the dollar signs for Hours Worked and instead of it saying 2.00, just say 2. Also since I put it 125 minutes I would like it to say 5 next to Minutes worked instead of 999. Then end up with the correct amount to be paid. Sorry for my extremely poor explanation, I barely grasp the concept of what I'm saying. But any help would be greatly appreciated.
Mar 11 '07 #1
6 2561
willakawill
1,646 Top Contributor
Hi. To get the 'remainder' from a division such as 125 / 60 you would use the modulus operator.
To avoid the dollar sign you would omit the "c" (currency) format character
Where did this code come from?
Mar 11 '07 #2
mrtopher
4 New Member
I used the MOD operator to get the minutes. Also I removed the "c" and replaced it with "f" and that seemed to work for getting rid of the dollar sign. Thanks alot for your help. This is my code, I'm just trying to figure it out by reading my text book. Everything seems to work except one thing. The hours worked is always rounded up. Since I want it to have hours worked and minutes worked, that doesn't work so well when the hours are just rounded. I realize that I can make it say (i.e.) 2.65 rather than rounding it up to 3, but I want it to say 2 hours and 39 minutes. I've got the minutes to work but it still rounds the hours. Is there a way to stop it from rounding? This is the code I have now:


Expand|Select|Wrap|Line Numbers
  1. Option Strict On
  2.  
  3. Public Class Frmweeklypaycalculator
  4.  
  5.     Private Sub btnweeklypay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnweeklypay.Click
  6.         ' This event handler is executed when the user clicks the
  7.         ' Weekly Pay button. It calculates and displays the
  8.         ' number of hours worked (total minutes worked divided by
  9.         ' 60), the number of minutes worked (use mod operator to
  10.         ' times hour remainder by 60), and the Total amount to
  11.         ' be paid (hours worked times hourly pay rate).
  12.  
  13.         Dim strTotalMinutesWorked As String
  14.         Dim strTotalHourlyRate As String
  15.         Dim intTotalMinutesWorked As Integer
  16.         Dim intMinutes As Integer
  17.         Dim decTotalHoursWorked As Decimal
  18.         Dim decTotalWeeklyPay As Decimal
  19.  
  20.         strTotalMinutesWorked = Me.Txtminworked.Text
  21.         strTotalHourlyRate = Me.Txthourpay.Text
  22.         intTotalMinutesWorked = Convert.ToInt32(strTotalMinutesWorked)
  23.  
  24.         decTotalHoursWorked = CDec((intTotalMinutesWorked / 60))
  25.         intMinutes = intTotalMinutesWorked Mod 60
  26.         decTotalWeeklyPay = CDec(decTotalHoursWorked * CDbl(strTotalHourlyRate))
  27.  
  28.         Me.Lblhrsworkednum.Text = decTotalHoursWorked.ToString("f0")
  29.         Me.Lblweeklypaynum.Text = decTotalWeeklyPay.ToString("c2")
  30.         Me.Lblminsworkednum.Text = intMinutes.ToString("f0")
  31.  
  32.         Me.Lblhrsworkednum.Visible = True
  33.         Me.Lblminsworkednum.Visible = True
  34.         Me.Lblweeklypaynum.Visible = True
  35.  
  36.  
  37.  
  38.     End Sub
  39.  
  40.     Private Sub Btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnclear.Click
  41.         ' This Event Handler is executed when the user clicks the
  42.         ' clear button. It clears the number of mintutes worked text box,
  43.         ' the text property of minutes worked, the hourly rate text box,
  44.         ' the textproperty of hours worked, and the text propoerty of
  45.         ' weekly pay.
  46.  
  47.         Me.Txtminworked.Clear()
  48.         Me.Txthourpay.Clear()
  49.         Me.Lblminsworkednum.Text = ""
  50.         Me.Lblhrsworkednum.Text = ""
  51.         Me.Lblweeklypaynum.Text = ""
  52.         Me.Txtminworked.Focus()
  53.  
  54.     End Sub
  55.  
  56.     Private Sub Btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnexit.Click
  57.         ' This event handler is executed when the user clicks the
  58.         ' Exit button. It closes the window and terminates the
  59.         ' application.
  60.  
  61.         Me.Close()
  62.  
  63.     End Sub
  64. End Class
Mar 12 '07 #3
willakawill
1,646 Top Contributor
If you think about it, you are almost there with the mod operator.
(minutes - (minutes mod 60)) / 60
Mar 12 '07 #4
mrtopher
4 New Member
ok but if I do that then the weekly pay (decTotalHoursWorked * strTotalHourlyRate) comes out incorrect. If the person worked 2.67 hours, it will only calculate the 2 hours and not include the minutes in the total weekly pay.
Mar 12 '07 #5
willakawill
1,646 Top Contributor
You don't have to calculate the pay and display the hours etc in the same process. Work them out separately
Mar 12 '07 #6
mrtopher
4 New Member
Oh, awesome. Thanks a bunch!
Mar 13 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Christian Mendieta | last post by:
Hi In VB6 there was a class builder... is there any tool in Visual Basic .NET that can do the same? Generate classes Thanks Christian Mendieta
12
by: Nick Stansbury | last post by:
Hi, Access 2003. Running over terminal server on a Windows Server 2003 box. The error occurs on every machine that I've tried copying the file to. Latest Jet SP & Office SP. Database hasn't been...
4
by: Harris | last post by:
Can anyone please help? I have read the postings on the error "The Visual Basic for Applications Project in the database is corrupt" but none report the particular problem I am experiencing, i.e.,...
2
by: Newbie19 | last post by:
I was wondering what is the best concept or idea to mixing visual basic with ASP.net page that runs a SQL query on a database. The Visual Basic would be pulling data from another source that is not...
0
by: ladar | last post by:
Hi, i need a help how to connect visual basic 6 with oracle. I have a little knowledge about visual basic and i want to connect it to the oracle in the server side, so give me so hint.
2
by: jayantim | last post by:
Hi ! I want to know the connection code for connecting visual basic and microsoft access. plese give the detail code for this connection. Actually I tried one code which is as follows: Dim cn...
1
pentahari
by: pentahari | last post by:
i create many forms in visual basic 6.0. i am new to VB. i am used msaccess as backend, but the client have not msaccess or any runtime add ons. So how will they run my project. but the client have...
1
by: sivadhanekula | last post by:
Hi all, I have a 'Mysql' database with lots of tables. I want to extract some of the data from that with the help of Visual basic. Can you please help me how Mysql library can be called from...
0
by: srwa hawez | last post by:
Hello everybody iam working on a project now and i did create a database with Visual basic ,but i want to connect this database with codes that i wrote it in visual C# how can i do this connection...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.