Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hey guys, got a small vb program to create and am receving a compile error. here is the code..tell me what i'm doing wrong. the program is basically 2 text boxes, 1 label box and a command button.
code:Private Sub cmdStart_Click()
intNum1 = InputBox("Please enter a number.", "First Number")
intNum2 = InputBox("Please enter a second number.", "Second Number")
If intNum1 > intNum2 Then
l1.Caption = ">"
t1.Text = intNum1
t2.Text = intNum2
ElseIf intNum2 > intNum1 Then
l1.Caption = ">"
t1.Text = intNum2
t2.Text = intNum1
Else
l1.Caption = ">"
t1.Text = intNum2
t2.Text = intNum1
End IfEnd Sub

what the error? i tried it and it works, except for the part where u didnt declare the variables intnum1 and intnum2.

i did declare them jus forgot to put it here.
Dim intNum1 As Integer
Dim intNum2 As Integer
still dont work :(

---------------------------
Microsoft Visual Basic
---------------------------
Compile error:Method or data member not found
---------------------------
OK Help
---------------------------

The inputbox function returns a STRING
ergo you must declare your variable as such
frx:dim strNum1 as string
strNum1=InputBox("Please enter a number.", "First Number")

Try This
Private Sub Command1_Click()
Dim t1, t2, intNum1, intNum2 As String
intNum1 = InputBox("Please enter a number.", "First Number")
intNum2 = InputBox("Please enter a second number.", "Second Number")
If CInt(intNum1) > CInt(intNum2) Then
l1.Caption = ">"
Me.t1.Text = intNum1
Me.t2.Text = intNum2
ElseIf intNum2 > intNum1 Then
l1.Caption = ">"
Me.t1.Text = intNum2
Me.t2.Text = intNum1
Else
l1.Caption = ">"
t1.Text = intNum2
t2.Text = intNum1
End IfEnd Sub

This works just fine.
Private Sub cmdStart_Click()
IntNum1 = InputBox("Please enter a number.", "First Number")
IntNum2 = InputBox("Please enter a second number.", "Second Number")
If IntNum1 > IntNum2 Then
Label1.Caption = " IntNum1 Then
Label1.Caption = "Lessor-->"
Text1.Text = IntNum2
Text2.Text = IntNum1
Else
Label1.Caption = ""
Text1.Text = IntNum2
Text2.Text = IntNum1
End IfEnd Sub

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |