Click to See Complete Forum and Search --> : still compile error


kazooie21
September 29th, 1999, 09:12 PM
I have the following code:

[vbcode]Private Sub cmdCalc_Click()
'calculate value of paperbacks
lblVpaper.Caption = Val(txtCpaper.Text) * Val(txtNpaper.Text)
'calculate value of hardcovers
lblVhard.Caption = Val(txtNhard.Text) * Val(txtChard.Text)
'calculate total value of paperbacks and hardcovers
lblTotv.Caption = Val(lblVpaper.Caption) + Val(lblVhard.Caption)
'calculate total
lblTot.Caption = Val(txtNpaper.Text) + Val(txtNhard.Text)

The problem occurs in the lblVpaper.Caption = Val(txtCpaper.Text) * Val(txtNpaper.Text)
I get a compile error: method or data number cannot be found


kazooie21

Ravi Kiran
September 29th, 1999, 11:11 PM
First make sure all your control names are correct, and no typing errors. One way to do this is type "me." before the control name and if the control is defined in the form ( and intellisense ON) it should pick up the name for you. Select from that list. But make sure you remove the "me."s later, because it will add unnecessary de-referencing.

Sometimes VB's functions may give the error " Function not defined", if you take a project and open it (under different settings) and while loading VB couldn't find some libraries of the original project. To Check this delete the "val(" and retype it. It should give you the syntax after you type '(' telling you that VB recognised the function.

You can also use Format() before assigning it to caption. But i checked it, it didn't make a difference on my machine!.

All you are using is Caption and Text members and Val() function. I dont see why it should give a problem?!

RK