Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

advice? Passing ByRef...

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
HI,

On my application I need to make some validations. If I put all the code in the same window, it will be difficult to mantain it. So I thought on making some sub in a module where I would validate the user inputs.

The problem is that I will need to pass byRef the various textBoxes I want to validat, because if I not pass them I will need to, again, put a lot of code in the form´s window.

The question is: Do you think that passing textboxes ByRef is not a good programming technic? Any ideias on this?

Thank you
 
Hi,

You could access the textbox values in the module like:

with MyForm
...
.text1.text
...
.text13.text
...
end with


I would prefer that to passing everything byref.

Sunaj
 
I would prefer ByRef as then when you change Text1 to NewText47 you only need to change the code once. Is there any reason they have to go ByRef instead of ByVal? What problems is it causing you? I'd be interested too as I'm not that experienced either,

Andy
 
Hi Landy,

That would depend a lot on the circumstances, somewhere you have to pass the value:

Myfunc(Text10.Text)

And if you want to change the name of the textbox you would have to change it there as well....
I would say that the easiest way to change a name of a control is to do a search and replace in the entire project - in which case it does not matter that you have references to a control in a module.

Sunaj
 
Hi Sunaj,

thankyou for the reply, do you know anywhere i can look up the dangers of passing byref as opposed to explicit hardcoding? I've always been too scared of messing up Text1 and Text10 to do a global replace ( and no, i don't really name by controls quite like that but you know what i mean ). It's probably something i should find out before i create too many monsters over here!

TIA for any pointers you have

Andy
 


No I don't know of any references - sorry.
I do agree that there are dangers by doing global search and replace, but I try to minimize them by searching for 'Text1.' which should be safe (of course that demands that you don't use Text1 as a shorthand for Text1.Text...)


Sunaj

 
I've had problems in the past passing references to controls to functions. Sometimes putting an extra set of parenthesis helps. Othertimes I have to use an intermediary variable.
[tt]
Call MyFunc((Text1.Text))

sTemp = Text1.Text
Call MyFunc(sTemp)[/tt]

It just seems to vary depending on how VB is feeling that day. My advice would be to make sure you've got an On Error Goto set up.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top