Log in

View Full Version : Solved: Don't know how to define it?



clifton.leo
02-01-2012, 08:45 AM
I have a lot of repetitive code occuring throughout a project I'm doing and I'm sure I can cut it down but don't know how to refer to certain types of variable. I'm not able to explain this very well so I'll demonstrate.

As a simple example, I might have the following code:

If X = 42 then
txtMain.text = "It's the answer to everything"
End If

If X = 49 then
txtSub.text = "That doesn't mean much"
End If

Now I want to call a sub which does this more quickly, for example:

Sub TextChange (Y as Integer, Tbox as Textbox, Answer as String)
If X = Y then
Tbox.text = Answer
End If
End Sub

And then call it thus:

Call TextChange (42,txtMain,"It's the answer to everything")
Call TextChange (48,txtSub,"That doesn't mean much")

As you can see the textbox changes and this is where I'm having problems, I need to know how to define this in the sub so that I can refer to multiple differnt textboxes when calling it (or a variety of other types of objects and variables for that matter)

I hope all this makes sense

Tommy
02-02-2012, 11:29 AM
Hi Clifton,

Attached you will find a macro that I threw together. This shows you how to do what you are asking. In short the define is control. :)

HTH

clifton.leo
02-03-2012, 02:06 AM
Thanks that's great