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

Creating a Public Function on a Form 1

Status
Not open for further replies.

RITE1

IS-IT--Management
Oct 25, 2003
91
US
Hello,

I want to create a public function on my form as to make use of a data adapter on that form.

I can make public functions in a module but not on my particular forms.

Can anyone help me out? Thanks
 
You can declare it as a public function but no other forms recognize it. They say Name "youFunctionName" is not declared.

If you define them the same way in a module they work fine.

Basically, I want to be able to create a function that uses a parameterized query that's in a data adapter for use with multiple asp pages with VB back coding.

Did I misinterpret Pankaj?


 
Yes, that’s true no other form would be able to recognize the function because it was declared public rather than Public Shared.

Ok, let’s say you have Form1 and Form2. You have declared the function "youFunctionName" in Form1 and now you want to access in Form2.

You can achieve this in two ways:

1. Either create an instance to Form1 before calling the function in Form2:

Dim str As String
Dim frm As New Form1

str = frm.youFunctionName


2. Declare you function as Public Shared in Form1.

Public Shared Function youFunctionName() As Boolean
'Your function code.

End Function

Then in Form2 include reference to Form1 using Imports statement

Imports yourProject.Form1

'Now you can say.
Dim str As String
str = youFunctionName()


 
It works!

While we are on the subject, I am doing this because I dont want to re-write a function that returns data from a parameterized query that is inside a data adapter.

Should I create a form will all my data sets and adapters, and create my functions there and just use those functions through the rest of the project or is there a better way?

Im a pretty green programmer and just starting to play with the idea of OOP, would this be a good opportunity?

Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top