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
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