|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
call method on passed formhi 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 ..Just use the type you created for your form instead of the "Form" type
provided by the framework. -- Patrice "Tim" <Citizen10Be***@gmail.com> a écrit dans le message de news: 1143722072.058468.13***@i40g2000cwc.googlegroups.com...Show quoteHide quote > 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 > 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?! 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! 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" <Citizen10Be***@gmail.com> a écrit dans le message de news: 1143725330.677981.204***@j33g2000cwa.googlegroups.com...Show quoteHide quote > 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! > 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 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" <Citizen10Be***@gmail.com> a écrit dans le message de news: 1143733043.827435.289***@u72g2000cwu.googlegroups.com...Show quoteHide quote > 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 > Hi,
If the methods in the called form are marked "Public Shared", then they can be called by other forms. HTH, Regards, Cerebrus. "Cerebrus" <zorg***@sify.com> wrote in message Why "Public /Shared/", specifically?news:1143723199.535946.63400@i39g2000cwa.googlegroups.com... > If the methods in the called form are marked "Public Shared", then they > can be called by other forms. 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.
Show quote
Hide quote
"Tim" <Citizen10Be***@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/>
VB .Net with ADSI problem
Capitalize Variable Names Convert IsMissing, IsNull, VBempty to vb.net Easily upgrade B to VB.NET Basic Question - Working with forms Selected a USB flash drive by default WinForm app memory continually grows 3rd party grid control in Visual Basic.net 2005 Showing a web page in VB.Net form? Noise |
|||||||||||||||||||||||