Visual Basic - Help with class project

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mrtopher
    New Member
    • Mar 2007
    • 4

    #1

    Visual Basic - Help with class project

    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:

    Code:
    Public Class Frmweeklypaycalculator
    
        Private Sub btnweeklypay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnweeklypay.Click
            ' This event handler is executed when the user clicks the
            ' Weekly Pay button. It calculates and displays the 
            ' amount to be paid (number of minutes times hourly rate).
    
            Dim strTotalMinutesWorked As String
            Dim strTotalHourlyRate As String
            Dim intTotalMinutesWorked As Integer
            Dim intTotalHoursWorked As Integer
            Dim decTotalWeeklyPay As Decimal
    
            strTotalMinutesWorked = Me.Txtminworked.Text
            strTotalHourlyRate = Me.Txthourpay.Text
            intTotalMinutesWorked = Convert.ToInt32(strTotalMinutesWorked)
    
            intTotalHoursWorked = CInt((intTotalMinutesWorked / 60))
            decTotalWeeklyPay = CDec(intTotalHoursWorked * CDbl(strTotalHourlyRate))
    
            Me.Lblhrsworkednum.Text = intTotalHoursWorked.ToString("c")
            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.
    Last edited by willakawill; Mar 11 '07, 11:10 PM. Reason: please use [code]...[/code] tags when posting code
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    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?

    Comment

    • mrtopher
      New Member
      • Mar 2007
      • 4

      #3
      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:


      Code:
      Option Strict On
      
      Public Class Frmweeklypaycalculator
      
          Private Sub btnweeklypay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnweeklypay.Click
              ' This event handler is executed when the user clicks the
              ' Weekly Pay button. It calculates and displays the
              ' number of hours worked (total minutes worked divided by
              ' 60), the number of minutes worked (use mod operator to
              ' times hour remainder by 60), and the Total amount to
              ' be paid (hours worked times hourly pay rate).
      
              Dim strTotalMinutesWorked As String
              Dim strTotalHourlyRate As String
              Dim intTotalMinutesWorked As Integer
              Dim intMinutes As Integer
              Dim decTotalHoursWorked As Decimal
              Dim decTotalWeeklyPay As Decimal
      
              strTotalMinutesWorked = Me.Txtminworked.Text
              strTotalHourlyRate = Me.Txthourpay.Text
              intTotalMinutesWorked = Convert.ToInt32(strTotalMinutesWorked)
      
              decTotalHoursWorked = CDec((intTotalMinutesWorked / 60))
              intMinutes = intTotalMinutesWorked Mod 60
              decTotalWeeklyPay = CDec(decTotalHoursWorked * CDbl(strTotalHourlyRate))
      
              Me.Lblhrsworkednum.Text = decTotalHoursWorked.ToString("f0")
              Me.Lblweeklypaynum.Text = decTotalWeeklyPay.ToString("c2")
              Me.Lblminsworkednum.Text = intMinutes.ToString("f0")
      
              Me.Lblhrsworkednum.Visible = True
              Me.Lblminsworkednum.Visible = True
              Me.Lblweeklypaynum.Visible = True
      
      
      
          End Sub
      
          Private Sub Btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnclear.Click
              ' This Event Handler is executed when the user clicks the
              ' clear button. It clears the number of mintutes worked text box,
              ' the text property of minutes worked, the hourly rate text box,
              ' the textproperty of hours worked, and the text propoerty of
              ' weekly pay.
      
              Me.Txtminworked.Clear()
              Me.Txthourpay.Clear()
              Me.Lblminsworkednum.Text = ""
              Me.Lblhrsworkednum.Text = ""
              Me.Lblweeklypaynum.Text = ""
              Me.Txtminworked.Focus()
      
          End Sub
      
          Private Sub Btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnexit.Click
              ' This event handler is executed when the user clicks the
              ' Exit button. It closes the window and terminates the
              ' application.
      
              Me.Close()
      
          End Sub
      End Class
      Last edited by willakawill; Mar 12 '07, 04:56 PM. Reason: reminder: use [code]...[/code] tags when posting code

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        If you think about it, you are almost there with the mod operator.
        (minutes - (minutes mod 60)) / 60

        Comment

        • mrtopher
          New Member
          • Mar 2007
          • 4

          #5
          ok but if I do that then the weekly pay (decTotalHoursW orked * strTotalHourlyR ate) 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.

          Comment

          • willakawill
            Top Contributor
            • Oct 2006
            • 1646

            #6
            You don't have to calculate the pay and display the hours etc in the same process. Work them out separately

            Comment

            • mrtopher
              New Member
              • Mar 2007
              • 4

              #7
              Oh, awesome. Thanks a bunch!

              Comment

              Working...