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.
Thanks in advance to anyone who has the time to look this over and give me some advice!!
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")
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"))
September 18th, 2012, 09:26 PM
A couple of comments about variable names:
Originally Posted by JRey
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!!
September 21st, 2012, 01:29 PM
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.