Beginner VB Question

Status
Not open for further replies.

goomba82

Ars Scholae Palatinae
636
Sorry to ask such a question, but I'm not a programming guy. I'm stuck on a problem with one of my programs though. What is wrong with this line of code?

subtotal = Val(lblCoretotal.Caption) + Val(lblAvtotal.Caption) + Val(lblMisctotal.Caption) + Val(lblStoragetotal.Caption) + Val(Extcomptotal.Caption)

All the controls are there. I have defined subtotal. Anyone?
 

goomba82

Ars Scholae Palatinae
636
Private Sub Command2_Click()
Dim taxrate As Single
Dim subtotal As Single

lblCoretotal.Caption = Val(txtProcessor.Text) + Val(txtMobo.Text) + Val(txtMem.Text)
lblCoretotal.Caption = Format(lblCoretotal.Caption, "currency")

lblAvtotal.Caption = Val(txtVideo.Text) + Val(txtAudio.Text) + Val(txtCapture.Text)
lblAvtotal.Caption = Format(lblAvtotal.Caption, "currency")

lblMisctotal.Caption = Val(txtMonitor.Text) + Val(txtFans.Text) + Val(txtFloppy.Text) + Val(txtSpeakers.Text)
lblMisctotal.Caption = Format(lblMisctotal.Caption, "currency")

lblStoragetotal.Caption = Val(txtHarddisk.Text) + Val(txtCdrom.Text) + Val(txtCdrw.Text)
lblStoragetotal.Caption = Format(lblStoragetotal.Caption, "currency")

lblExtcomptotal.Caption = Val(txtCase.Text) + Val(txtKeyboard.Text) + Val(txtMouse.Text)
lblExtcomptotal.Caption = Format(lblExtcomptotal.Caption, "currency")

taxrate = Val(txtTaxrate.Text) / 100

subtotal = Val(lblCoretotal.Caption) + Val(lblAvtotal.Caption) + Val(lblMisctotal.Caption) + Val(lblStoragetotal.Caption) + Val(Extcomptotal.Caption)
lblTax.Caption = subtotal * taxrate
 

bw

Ars Tribunus Angusticlavius
7,308
subtotal = Val(lblCoretotal.Caption) + Val(lblAvtotal.Caption) + Val(lblMisctotal.Caption) + Val(lblStoragetotal.Caption) + Val(Extcomptotal.Caption)

should be.....

subtotal = Val(lblCoretotal.Caption) + Val(lblAvtotal.Caption) + Val(lblMisctotal.Caption) + Val(lblStoragetotal.Caption) + Val(lblExtcomptotal.Caption)

I think Jackass JoeJoe mentioned this on his post....
 

adx200

Ars Scholae Palatinae
764
Subscriptor
My standard technique has been to name objects and define variables using a few capital letters interspersed in the name: lbltaxrate would be named lblTaxRate. dim holdthat as integer would be dim HoldThat as integer.
Then when coding, I always use lowercase. If I properly typed an object or variable, when I move to the next line, everything will be auto-corrected to it's "partial capitals" name. Makes for quick spot checking before run-time.
 
Status
Not open for further replies.