putting functions in modules.

genu

Well-known member
Joined
Jun 9, 2005
Messages
94
Programming Experience
1-3
If I want to put a function in a module, how can I access a control on the form from that function which is inside the module. is there a way that I can reference the form to the module?
 
Everything you put in a module is available from entire application. And you don't need any additional task to get the code within. Just declare your func with public scope i.e.

Public Function myFunction()
'code ....
End Function


and then you can call this func from every form in your app ... just say: myFunction()

I hope it helps ... cheers ;)
 
ok thanks...but I still cant change for example the contents of textbox1.text of form1 from my function. It becomes as undeclared in my module
 
Ok add this in a module1 ...

'btw, this is very unuseful and stupid example but i hope it's good enough to provide you with basic concept ...
PHP:
Public Sub mySub(ByVal txt As textBox, ByVal str As String) 
txt.Text = str 
End Sub

usage:

put this code in one of your forms

mySub(textBox1, "this text goes in the textBox1")


Cheers ;)
 
Back
Top