#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0

    Need some pointers


    I have just started studying VB 2010 for my online programming class and am having to teach myself with the internet and a crappy book as a resource. I have only been coding for about 4 days now and think I may be patchworking this stuff together for my assignments and/or straight up butchering it. Anyway if a few of you would look over my code and give me some pointers I would appreciate it.

    Code:
    Public Class Form1
    
        Private Sub btnDispbill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDispbill.Click
            Dim customer As String = txtCustomer.Text
            Dim phone As String = mtbPhone.Text
            Dim hrsPay As Double = 35
            Dim addTax As Double = 0.05 + CDbl(txtParts.Text)
            Dim hours As Double = CDbl(txtHours.Text) * hrsPay
            Dim parts As Double = CDbl(txtParts.Text) * addTax
            Dim total As Double = parts + hours
            Dim promptOne As String = "Enter Service Date"
            Dim title As String = "Date"
            Dim srvcDate As Date = CDate(InputBox(promptOne, title))
            Dim duedate As Date = srvcDate.AddDays(30)
    
    
    
            If (txtCustomer.Text = "") Then
                MessageBox.Show("Please Enter Customer's Name")
            ElseIf (mtbPhone.Text = "") Then
                MessageBox.Show("Please Enter Phone #")
            ElseIf (txtHours.Text = "") Then
                MessageBox.Show("Please Enter Hours")
            ElseIf (txtParts.Text = "") Then
                MessageBox.Show("Please Enter Cost of Parts")
            End If
    
    
            lstBill.Items.Clear()
            lstBill.Items.Add("Customer" & vbTab & vbTab & vbTab & customer.ToUpper)
            lstBill.Items.Add("Phone Number:" & vbTab & vbTab & phone)
            lstBill.Items.Add("Service Date:" & vbTab & vbTab & srvcDate)
            lstBill.Items.Add("Invoice Due:" & vbTab & vbTab & dueDate)
            lstBill.Items.Add("Labor Cost:" & vbTab & vbTab & hours.ToString("c"))
            lstBill.Items.Add("Parts and Supplies Cost:" & vbTab & parts.ToString("c"))
            lstBill.Items.Add("Total Cost:" & vbTab & vbTab & total.ToString("c"))
    
    
    
    
        End Sub
    
         
        
        
        
    End Class
    Thanks in advance to anyone who has the time to look this over and give me some advice!!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Location
    Terlingua, TX
    Posts
    15
    Rep Power
    0
    Originally Posted by JRey
    I have just started studying VB 2010 for my online programming class and am having to teach myself with the internet and a crappy book as a resource. I have only been coding for about 4 days now and think I may be patchworking this stuff together for my assignments and/or straight up butchering it. Anyway if a few of you would look over my code and give me some pointers I would appreciate it.

    Code:
    Public Class Form1
    
        Private Sub btnDispbill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDispbill.Click
            Dim customer As String = txtCustomer.Text
            Dim phone As String = mtbPhone.Text
            Dim hrsPay As Double = 35
            Dim addTax As Double = 0.05 + CDbl(txtParts.Text)
            Dim hours As Double = CDbl(txtHours.Text) * hrsPay
            Dim parts As Double = CDbl(txtParts.Text) * addTax
            Dim total As Double = parts + hours
            Dim promptOne As String = "Enter Service Date"
            Dim title As String = "Date"
            Dim srvcDate As Date = CDate(InputBox(promptOne, title))
            Dim duedate As Date = srvcDate.AddDays(30)
    
    
    
            If (txtCustomer.Text = "") Then
                MessageBox.Show("Please Enter Customer's Name")
            ElseIf (mtbPhone.Text = "") Then
                MessageBox.Show("Please Enter Phone #")
            ElseIf (txtHours.Text = "") Then
                MessageBox.Show("Please Enter Hours")
            ElseIf (txtParts.Text = "") Then
                MessageBox.Show("Please Enter Cost of Parts")
            End If
    
    
            lstBill.Items.Clear()
            lstBill.Items.Add("Customer" & vbTab & vbTab & vbTab & customer.ToUpper)
            lstBill.Items.Add("Phone Number:" & vbTab & vbTab & phone)
            lstBill.Items.Add("Service Date:" & vbTab & vbTab & srvcDate)
            lstBill.Items.Add("Invoice Due:" & vbTab & vbTab & dueDate)
            lstBill.Items.Add("Labor Cost:" & vbTab & vbTab & hours.ToString("c"))
            lstBill.Items.Add("Parts and Supplies Cost:" & vbTab & parts.ToString("c"))
            lstBill.Items.Add("Total Cost:" & vbTab & vbTab & total.ToString("c"))
    
    
    
    
        End Sub
    
         
        
        
        
    End Class
    Thanks in advance to anyone who has the time to look this over and give me some advice!!
    A couple of comments about variable names:
    hrsPay = try dblRatePerHour because you actually calculate the pay later and call it "Hours" which I'd call dblLabour

    give yourself a hand in this early stage and make your variable names mean what you intend them to mean. This little program isn't any problem, but when you're looking back across a program that's grown to a couple of thousand pages - well, be nice to yourself. Like many oldtimers, I use the data type as a prefix to my variables. Saves memory later on trying to remember whether "this" is a double or a string!!
  4. #3
  5. I <3 ASCII
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2003
    Posts
    2,399
    Rep Power
    1232
    Before blindly adding 'dbl' to the beginning of all your doubles please read up a bit on hungarian notation, or more specifically misconceptions about it. Here's a good link. Skip down to the "I'm Hungary" section if you don't have a lot of time.

    TL;DR: In using Hungarian notation you're supposed to denote the 'kind' of variable, not the type of variable. This is doubly true since the advent of intellisense where you can see the variable type at a hover of the mouse.

    -MBirchmeier

IMN logo majestic logo threadwatch logo seochat tools logo