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
LVL 9
william007Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
You just need to remove the parenthesis around Text1:

Private Sub Command1_Click()
    Handletxt Text1
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonMiddle School Assistant TeacherCommented:
Or leave the parenthesis and use the Call statement:

Private Sub Command1_Click()
    Call Handletxt(Text1)
End Sub
0
B_M_WestonCommented:
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

william007Author Commented:
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?
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Use the parenthesis when you want to STORE the return value of a function:

Private Sub Command1_Click()
    Dim str As String
    str = Foo("Echo...")
    MsgBox str
End Sub

Private Sub Command2_Click()
    Foo "Echo..."
End Sub

Private Function Foo(ByVal inValue As String) As String
     Foo = inValue
End Function



In the Command2_Click() example, we are not storing the return of Foo() so we don't need the parenthesis.

If you prefer to use parenthesis because it looks nicer but don't care about the return value, then use the Call statement:

    Call Foo("Echo...")
0
william007Author Commented:
Excellent, thanks:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.