william007
asked on
How to pass textbox as parameter?
Text1 is a textbox. I want to pass it as parameter, but it gets me the error below, I think this is because it treats text1 as text1.text, but how to solve it?
-------------------------- -
Microsoft Visual Basic
-------------------------- -
Compile error:
Type mismatch
-------------------------- -
OK Help
-------------------------- -
Followed is the code,
Private Sub Command1_Click()
Handletxt (Text1)
End Sub
Private Sub Handletxt(ByVal txt As TextBox)
MsgBox txt.Text
End Sub
--------------------------
Microsoft Visual Basic
--------------------------
Compile error:
Type mismatch
--------------------------
OK Help
--------------------------
Followed is the code,
Private Sub Command1_Click()
Handletxt (Text1)
End Sub
Private Sub Handletxt(ByVal txt As TextBox)
MsgBox txt.Text
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
get rid of the brackets
Private Sub Command1_Click()
Handletxt Text1
End Sub
Private Sub Handletxt(ByVal txt As TextBox)
MsgBox txt.Text
End Sub
Private Sub Command1_Click()
Handletxt Text1
End Sub
Private Sub Handletxt(ByVal txt As TextBox)
MsgBox txt.Text
End Sub
ASKER
Thanks,
But I am quite confusing with the bracket convention in VB.
1. What is this mean(If it do not mean it taking a parameter text1)
Handletxt (Text1)
2. Is there a guideline for when to use bracket and and when do not?
But I am quite confusing with the bracket convention in VB.
1. What is this mean(If it do not mean it taking a parameter text1)
Handletxt (Text1)
2. Is there a guideline for when to use bracket and and when do not?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent, thanks:-)
Private Sub Command1_Click()
Call Handletxt(Text1)
End Sub