473,396 Members | 2,108 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,396 software developers and data experts.

call method on passed form

Tim
hi all

If I pass a form to a sub as a parameter:
eg

call mysub(me)

how can I call methods on that form?

eg
sub mysub(FRM as system.windows.forms.form)
x=FRM.getxvalue()
end sub

I can get generic stuff like FRM.controls, or FRM.name, but nothing
that I have created my self. Any clues?

thanks in advance

Mar 30 '06 #1
9 1135
Hi,

If the methods in the called form are marked "Public Shared", then they
can be called by other forms.

HTH,

Regards,

Cerebrus.

Mar 30 '06 #2
..Just use the type you created for your form instead of the "Form" type
provided by the framework.

--
Patrice

"Tim" <Ci************@gmail.com> a écrit dans le message de news:
11*********************@i40g2000cwc.googlegroups.c om...
hi all

If I pass a form to a sub as a parameter:
eg

call mysub(me)

how can I call methods on that form?

eg
sub mysub(FRM as system.windows.forms.form)
x=FRM.getxvalue()
end sub

I can get generic stuff like FRM.controls, or FRM.name, but nothing
that I have created my self. Any clues?

thanks in advance

Mar 30 '06 #3
Tim
can you explain a bit more?

I don't actually now the location of the calling form.
All the info I have is the form passed as a parameter?!

Mar 30 '06 #4
Tim
actually I got there!

answer:

instead of dimming FRM as a windows.form, I left the "as" part off
(leaving it as a variant?!)
I wasn't then restricted to picking items from the windows.form list, I
could then reference my own sub.

thanks for you help!

Mar 30 '06 #5
I wouldn't do that either. Here you are not restricting at all what you are
able to pass to your sub (this is "As Object").

I meant that when you create a form, you are actually creating a new class
(see the Class statement at the top of your form file). This is this class
name that you should use as the type of the argument for this sub :
- you'll be able to have intellisense providing the new members you added
- you won't be able to pass by mistake something else (such as a form that
wouldn't provide these members)

Previously the problem was that you were passing a "System.Windows.Form"
that doesn't have the members you added. The class *you* created is the one
that have these new members, not the built in Form class provided by the
framework...

--
Patrice

"Tim" <Ci************@gmail.com> a écrit dans le message de news:
11**********************@j33g2000cwa.googlegroups. com...
actually I got there!

answer:

instead of dimming FRM as a windows.form, I left the "as" part off
(leaving it as a variant?!)
I wasn't then restricted to picking items from the windows.form list, I
could then reference my own sub.

thanks for you help!

Mar 30 '06 #6
"Tim" <Ci************@gmail.com> schrieb:
If I pass a form to a sub as a parameter:
eg

call mysub(me)

how can I call methods on that form?

eg
sub mysub(FRM as system.windows.forms.form)
x=FRM.getxvalue()
end sub

I can get generic stuff like FRM.controls, or FRM.name, but nothing
that I have created my self. Any clues?


\\\
Public Sub MySub(ByVal frm As Form1)
x = frm.GetXValue()
End Sub
....
MySub(Me)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Mar 30 '06 #7
Tim
slight problem is...

I have no idea of the calling exe or dll.
I have no idea of the type of form, where it is or where it comes from.
The only single solitary thing I have is the form object passed as a
parameter to an unrelated sub in an unrelated exe.
I have no other reference at all to the calling exe or form.

Tim

Mar 30 '06 #8
"Cerebrus" <zo*****@sify.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
If the methods in the called form are marked "Public Shared", then they
can be called by other forms.


Why "Public /Shared/", specifically?
You can call Public methods on a Form provided you have a reference
to an instance of it (as in the OP's case). Explicitly making the method
Shared in unnecessary.

Public Class SubForm
Inherits Form

Public Function GetXValue() As ...
.. . .

Public Class MainForm
Inherits Form

Public Sub MySub( ByVal oForm As SubForm )
Debug.Writeline( oForm.GetXValue() )
End Sub
.. . .

Regards,
Phill W.
Mar 30 '06 #9
If you don't know at all about the form type how do you know it will provide
methods such as "GetXValue" ?

Clearly it won't work with a from that doesn't provide this method.

I'm still not sure about what you are doing but generally this is done in a
way such as :
- you create a class MyForm that inherits from Form and you add the required
functionnality
- the "sub" uses a MyForm type form as an argument

Now if someone calls your sub, he have to use a MyForm (or a MyForm child
class) object. Inheriting from MyForm will guarantee the form has the
methods required by tour sub...

The caller is not the problem. The argument itself is not really a problem
as it is passed to you. A possible problem is to be able to ensure as soon
as possible that the form has the required methods added to it (it seems to
me that your sub requires the form to have additional methods). Would be
cleaner...

--
Patrice

"Tim" <Ci************@gmail.com> a écrit dans le message de news:
11**********************@u72g2000cwu.googlegroups. com...
slight problem is...

I have no idea of the calling exe or dll.
I have no idea of the type of form, where it is or where it comes from.
The only single solitary thing I have is the form object passed as a
parameter to an unrelated sub in an unrelated exe.
I have no other reference at all to the calling exe or form.

Tim

Mar 30 '06 #10

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

Similar topics

2
by: Titus Cheung | last post by:
Hello, I want to write some code such that it'll update (ie insert, delete, etc) some data to/from a mySQL database whenever a user hit an HTML form button (ie Submit). Now what I find annoying...
15
by: Thomas Scheiderich | last post by:
I am trying to understand Session variables and ran into a question on how they work with data that is passed. I have an HTM file that calls an ASP file and sends the name either by GET or POST....
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
7
by: Malcolm Cook | last post by:
Hi, I've created and installed a custom UDF to populate my combobox, and have defined it per :...
26
by: Paul | last post by:
public class A { public A () { // here I would like to call the second version of _ctor, how to accomplish this ? } public A (int a, int b, int c) {
4
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where...
8
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
1
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I have a class that Form1 calls to do some work. I would like to report back progress from the class to a richtextbox, will call it m_report, on the form. Like in the class, Form1.m_report.Text=...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.