473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

pass form to function

Hi!

I am new to vb.net and have a question on how to pass a form to a function.
Could someone point me to an example or give me a quick example on how to do
this.

Thank you
Stacy
Nov 20 '05 #1
4 7371
private function fntMyFunction (objForm as object)
'my function getting a form as paramater
end function

than you can call the function like this:
fntMyFunction (frmMyForm)
If you know alreaddy what kidn of form you're going to use you better use:
private function fntMyFunction (objForm as frmMyForm)
-> This way you can use the methods of the form.
"stanuf" <sf*******@samsa.com> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
Hi!

I am new to vb.net and have a question on how to pass a form to a function. Could someone point me to an example or give me a quick example on how to do this.

Thank you
Stacy

Nov 20 '05 #2
Ouch. You should never pass something around as an object that has a deeper
base class. Clearly all Windows forms derive from
System.Windows.Forms.Form, so you should have defined the object as that
instead. Something like this:
Sub MyFunction (passedForm as System.Windows.Forms.Form)
' Do Something with passedForm
End Sub

You could also do this, if you have already imported a reference to
System.Windows.Forms

Sub MyFunction(passedForm as Form)
' Do something with passedForm
End Sub

If you are looking for a particular instance of a form, or a particular form
class, you could define the referenced object in that particular class. The
other choice you could have is to check the type of the passedForm object,
and see if it implements the class or interface you are expecting, and then
cast it into that class. All depends on what you're trying to do... just
don't pass it as an object!

Ryan Gregg

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:Ox**************@TK2MSFTNGP11.phx.gbl...
private function fntMyFunction (objForm as object)
'my function getting a form as paramater
end function

than you can call the function like this:
fntMyFunction (frmMyForm)
If you know alreaddy what kidn of form you're going to use you better use:
private function fntMyFunction (objForm as frmMyForm)
-> This way you can use the methods of the form.
"stanuf" <sf*******@samsa.com> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
Hi!

I am new to vb.net and have a question on how to pass a form to a function.
Could someone point me to an example or give me a quick example on how

to do
this.

Thank you
Stacy


Nov 20 '05 #3
Cor
Hi Stanuf,

A real agresive sample, it set all text on your form to "Stanuf"

Private Sub Load_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim nada As New doCtr(Me)
End Sub
End Class
Public Class doCtr
Public Sub New(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
ctr.Text = "Stanuf"
Dim newdoCtr As _
New doCtr(ctr)
Next
End Sub
End Class

I hope this helps a little bit?

Cor
Nov 20 '05 #4
* "stanuf" <sf*******@samsa.com> scripsit:
I am new to vb.net and have a question on how to pass a form to a function.
Could someone point me to an example or give me a quick example on how to do
this.


\\\
DoSomething(Me)
..
..
..
Public Function DoSomething(ByVal f As MainForm) As ...
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Yangang Bao | last post by:
I have a simple test program. It doesn't work. I want to know what is the reason and how to fix it. Maybe I should use template function to do it. But I don't know how. Here is the simple...
3
by: M | last post by:
i am using submit buttons to send the user to different parts of a wizard. i am using if (if attribute.step1 exists) statements to send them to the appropriate section based on which submit button...
6
by: _andrea.l | last post by:
I'd like to write a function like: function f(){ ... bla ...} f_example(f); function f_example($function_to_execute) {...bla... $function_to_execute() ...bla....} AND how to pass the...
2
by: Jeff Wilson | last post by:
Lots of posts explained to me how to invoke a function inside a form from another form. Unfortunately, it appears that a function inside a form can have at most 1 argument. I can create a form...
2
by: Ronnie Smith | last post by:
I am trying to pass a function (method) address to a user control to associate with an event. The small user control which sends events is contained in a larger user control group which is in...
2
by: KFactor | last post by:
Is it possible to pass form variables to a page on another server using response.redirect? Or is there a secure way of passing sensitive information from one site to another such as a userID? ...
8
by: laredotornado | last post by:
Hi, I want to pass my function myFunc('a', 'b', 'c') as an argument to another function. However, this will not work doStuff('x', 'y', myFunc('a', 'b', 'c'))
1
by: shalini jain | last post by:
Hi, I am facing the problem with eval function. I want to know how to pass a function in eval() when we have to create the function itself. I would better explain my problem with the help of an...
10
by: iskhan | last post by:
Is it possible that pass a function name as a argument in an other function? e.g. MainMenu($SubMenu) { //Main menu designing start if(.......&&......||.......&&.......) { $this->$Submenu;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.