September 18th, 2012, 09:26 PM
Join Date: Sep 2012
Location: Terlingua, TX
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.
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"))
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!!