Link to home
Start Free TrialLog in
Avatar of william007
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
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or leave the parenthesis and use the Call statement:

Private Sub Command1_Click()
    Call Handletxt(Text1)
End Sub
Avatar of B_M_Weston
B_M_Weston

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
Avatar of william007

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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent, thanks:-)