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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a Function 1

Status
Not open for further replies.

vmaruv

Programmer
Apr 8, 2002
102
US
Hi,
In one of the modules in my VB code, I have a function that returns a string. But I want to use this from another form's code. How is it possible ? when I say frmmain. it does not get listed. I cannot convert this function to a sub as it has to return a string . What is the way I can handle this..

Please help !!
 
Nope !! I tried but it does not list this function in the list [sad]

What do I do now ? [ponder] Pleae help !!

I cannot change this function to a sub becoz I want it to return a string and with sub I cannot have a return value.


 
Yes..I defined it as a private function. Will making it public help ??
 
Stick the function in a code module and declare it as Public - you can then re-use it from anywhere in the project. You can also include the same module in other projects.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

Essex Steam UK for steam enthusiasts
 
If you take the Private off it or change it to Public you will be able to use it in your other forms. When it is declared as Private nothing outside where it is declared is able to use it.

Harleyquinn

---------------------------------
For tsunami relief donations
 
What I forgot to mention is that if you take the prefix off all together it is declared as Global. So it is your own personal choice how you do it.

Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
Thanks a Ton...it worked. Thank you Harleyquinn, johnwm and everyone else who helped me !! [smile2]
 
You probably have your application startup object set to Sub Main. Click Project -> Properties On the general tab, the Startup Object is displayed. In your Sub Main (declared in a module somewhere), you are probably creating an instance of your main form, but with a different name ex: fMainForm. You can access controls and public functions and subroutines on your main form by typing fmainform.

If all this is true, it probably happened because you used to application wizard within vb. You've already been helped by JohnM and HarlyeQuinn. I mention this only for clarification purposes. For example, you could put a status bar or progress bar on your main form and then call it from any form by using fMainForm.Progress1.Min = 0 (as an example).

Hope it helps.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top