I'm just starting out in VB by taking an online course. The project I'm supposed to make will not run, and i cant figure out why. Here's what I have:

Private Sub cmdCalculate_Click()
'Declare variables
    Dim curPrice As Currency
    Dim curCost As Currency
    Dim curComm As Currency
'Set variable values to entered data
    curPrice = Val(txtPrice)
    curCost = Val(txtCost)
'Calculates and displays commission
    curComm = 0.2 * (curPrice - curCost)
    lblCommissiondisplay = FormatCurrency(curComm)
    lblNamedisplay = txtName
End Sub

First error that comes up is "Arument not optional" with the txtboxes highlighted after the Val functions. Second, in the last two lines of code, it claims an "Invalid use of property" highlighting the two lbl boxes and the text box.

Not understanding this. Some of those exact lines of code are in my study guide. PLz Help

Hi,

Give this way,

curPrice = Val(txtPrice.Text)
curCost = Val(txtCost.Text)

curComm = 0.2 * (curPrice - curCost)
lblCommissiondisplay.Caption = FormatCurrency(curComm,"0.00")
lblNamedisplay.Caption = txtName.Text


Regards
Veena

Have you created the controls referred to in your code? Unless you have a text box that is named txtPrice and another named txtCost, plus the lblCommissionDisplay and lblNameDisplay labels, that code will be unable to run.

Something to check.

- Sen

This article has been dead for over six months. Start a new discussion instead.