VB Help

yohanns23

Disciple
We Just Finished Writing Our Computer Exam For Class IX...

I just Wanted To Ask If This VB Code Is Fine.

(Program to calculate area of a rectangle)

------------------------------------------

Dim L, B, A As Single

-----------------------------------------------

Private Sub Command1_click()

L = InputBox("enter Length") 'for length

B = InputBox("Enter Height/Breadth") 'Enter Breadth

A = Val(L.text) * Val(B.text) 'Calculating Area

Print Val(A)

End Sub

------------------------------------------

The Problem Is They Said That The .text part in val is not correct....

the teacher said that when you use L.text or b.text you need to use variables...and he said that the code is wrong....is this so?..
 
kekerode said:
Try this

A = Val(L) * Val(B) 'Calculating Area

+1

the .Text property is only applicable for components such as TextBox, ListBox etc. (eg: TextBox1.Text)

in your program, L and B are variables and hence should be referred to directly.
 
Back
Top