Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 5th, 2012, 10:17 AM
JRey JRey is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 1 JRey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 49 sec
Reputation 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!!

Reply With Quote
  #2  
Old September 18th, 2012, 09:26 PM
aljones aljones is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Location: Terlingua, TX
Posts: 15 aljones User rank is Sergeant (500 - 2000 Reputation Level)aljones User rank is Sergeant (500 - 2000 Reputation Level)aljones User rank is Sergeant (500 - 2000 Reputation Level)aljones User rank is Sergeant (500 - 2000 Reputation Level)aljones User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 50 m 3 sec
Reputation Power: 0
Quote:
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!!

Reply With Quote
  #3  
Old September 21st, 2012, 01:29 PM
MBirchmeier's Avatar
MBirchmeier MBirchmeier is offline
I <3 ASCII
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Posts: 2,395 MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level)MBirchmeier User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 18 h 33 m 9 sec
Reputation Power: 1231
Send a message via AIM to MBirchmeier
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
__________________
My fiancee's transition from accountant to writer
0x4279 7465 204D 6521

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > Need some pointers

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap