PC Review


Reply
Thread Tools Rate Thread

Calling a function from another form

 
 
Kevin Humphreys
Guest
Posts: n/a
 
      2nd Feb 2007
Hi There,
I have 2 forms and I need to execute a subroutine on formA from FormB
passing specific parameters. Can this be done using VB.NET?
I would prefer not to use a global function. Just something local to 2
forms.

Thanks,
Kevin.


 
Reply With Quote
 
 
 
 
Tim Mackey
Guest
Posts: n/a
 
      2nd Feb 2007
hi kevin,
since the forms are objects, it is a simple matter of ObjectB having a
reference to ObjectA, which can be done with any object-oriented programming
language. In other words, you need a variable of type ObjectA contained in
Object B, initialised to the instance of ObjectA that you want to invoke the
method on.

in depends on which way your forms are created, but you need to ensure that
ObjectB contains a correctly initialised variable for ObjectA.

if you need help setting it up, post the code that you use to create both
the forms (and your main() code if either A or B are your main form). here
is some pseudo code anyway:

function main()
dim form1Object as new form1() 'create a form1
dim form2Object as new form2() 'create a form2, but don't show it yet
form1Object.Form2Reference = form2Object 'set the reference to
form2Object
form1Object.showdialog()
'now inside form1 you can do things like:
me.Form2Reference.whatever(whatever)
end function

your form 2 should look like this:

class form2
..... other variables here etc
public form2 Form2Reference

end class

there are some design patterns like Model View Controller which have a
technique for achieving this.

hope this helps
tim


"Kevin Humphreys" <(E-Mail Removed)> wrote in message
news:OwaIr%(E-Mail Removed)...
> Hi There,
> I have 2 forms and I need to execute a subroutine on formA from FormB
> passing specific parameters. Can this be done using VB.NET?
> I would prefer not to use a global function. Just something local to 2
> forms.
>
> Thanks,
> Kevin.
>


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling function form within sub Dirk Microsoft Excel Programming 1 16th Mar 2006 01:27 PM
calling a function from another form Michael S. Montoya Microsoft Access Forms 2 29th Sep 2005 07:28 AM
calling a function in another form Geoff Jones Microsoft VB .NET 7 28th Dec 2004 09:28 AM
Calling Function on other Form C# Ed West Microsoft Dot NET Framework Forms 3 8th Aug 2004 12:45 AM
Calling a form function from a button click on a user defined control placed on the form Scott Schade Microsoft C# .NET 3 20th Feb 2004 01:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:17 PM.