Hi,
Anyone figured out if you can call a PUBLIC procedure in one form from an event or procedure in another form?
Taxes
Printable View
Hi,
Anyone figured out if you can call a PUBLIC procedure in one form from an event or procedure in another form?
Taxes
the procedure would have to be declared Public
'Calling form
VB Code:
'Function that calls function Private Function CallFunction() Dim frm2 as New Form2 frm2.FunctionToCall
something like that would work if the second form was called "From2" and the Public Function was Called "FunctionToCall"
HI ABX,
Using a Public dimension dose not help. I know it did in VB6 but it does not in VB.NET (unless you have adifferent version to me).
<- comment removed by admin - negative comments towards others not allowed - see Acceptable Usage Policy for forum ->
taxes.
i think you'll find it does <comment removed by admin>. There is no need to answer to someone like that if they are trying to help you.....even if you do think they are wrong!!!!!!!!!! The only bit he got wrong was the private bit in front of the function should have been public. An easy typo and one that should be easy to understand <comment removed by admin>.
<ABX's code is right correct .
huh ? accurate ? He's trying to help and if he gave you the full working code , you're not going to pay him . So he helps , you should appreciate . That's what the forums meant to be .Quote:
<comment removed by admin>and make sure your responses are accurate?
Hi all,
Re. Pirate:
Unless there is something wrong with my VB.NET 2003, ABX is wrong. You can ONLY, as far as I can see, refer from a form to a procedure in a module and not to one in another form, no matter what the declaration.
What annoys me is when someone treats me as an idiot without testing the problem and produces an "answer" without bothering to check if it is true.
I am sorry if my comments annoyed you but the entire tone of ABX's response was inaccurate, flippant and rude. All I did was to suggest he refrained from rude remarks. I was not criticising his technical knowledge.
Did you check the problem out before you responded?
The whole point of a technical forum is that we may share our practical experiences in programming matters. If I want to be insulted or used as a testing ground for puerile comedy there are many non technical boards available.
Re: nswan
May I have the extreme temerity to draw your attention to the slight possibility that I did realise ABX meant "Public" ?. Did you bother to read my response to ABX where I used the word "Public" in spite of his having used "Private"? May I also be allowed to ask if you have checked out the problem in VB.NET 2003? If I have less than 2 brain cells, how many have you got?
To ABX:
Please may I make it quite clear that my response was not directed at your answer but at your additional remarks, to which I took offence.
Regards,
taxes
Well, ABX code (minus the typo) is correct. You must be doing something else that is irking it.
If you have a FORMa with a procedure like this:
VB Code:
Pubic Sub messagealert() messagebox.show("hi from FORMa") End Sub
If you have an instance of FORMa already, and you want to call it from Formb. you simply write in Formb somewhere:
VB Code:
myFORMa.messagealert()
If you don't have a FORMa instantiated, you must instance it before you call it:
VB Code:
Dim myFORMa As New FORMa myFORMa.messagealert()
This demo shows <ABX is correct .
This thread needs to focus on the problem being presented and not on negative comments towards those trying to help -- whether their help is accurate or not.
Negative comments towards others -- whether they started them or not -- are a violation of this site's usage policy.
Thanks for focusing on the technical issues going forward.
Brad
Admin
Hi Brad Jones.
O.K. Point taken. I guess I over reacted. My apologies to any offended by my responses.
Taxes
Did you get it resolved?
Hi nemaroller
"If you don't have a FORMa instantiated, you must instance it before you call it:"
I have instantiated the form in a module. Also, the way I got round it (showing the form containing the code and referencing it in the activated event) proves that the form is available.
Have you actually tried this? If so, then I must re-install VB.NEt 2003.
Thanks,
taxes
Ok, I i think you took my code wrong I meant this:
I Assumed you would understand that this was the form that was calling the function from "Form1" so this snippit is an example of how to call a function in "Form2". I am Sorry for any Confusion but you should really be more tolerant to mistakes as others have said, I AM NOT GETTING PAID, I am merely doing this out of my own free will and anthing I post may or may not work (if its something im not sure about it check in VS but this time i didnt think i had to and if i did you just mis-interpreted what I meant.
This should clear up what I mean't
VB Code:
'BELONGS IN "FORM1" 'Function that calls function Private Function CallFunction() Dim frm2 as New Form2 frm2.FunctionToCall '....
VB Code:
'Belongs In "Form2" Public Function FunctionToCall 'This is the Function That MUST be Public Msgbox("HELLO") End Function
Thanks Pirate, nemaroller, nswan
and taxes no hard fellings, i guess i wasnt thinking when i made the example (it seemed clear to me :D)
What I mean is... if you added two forms to a project. And simply put messgebox.show(form2.text) in a button-click event in Form1, you would get a reference not instance of an object error.Quote:
Originally posted by taxes
Hi nemaroller
"If you don't have a FORMa instantiated, you must instance it before you call it:"
I have instantiated the form in a module. Also, the way I got round it (showing the form containing the code and referencing it in the activated event) proves that the form is available.
Have you actually tried this? If so, then I must re-install VB.NEt 2003.
Thanks,
taxes
If you declared the form2 in a module that runs at startup, and expose the form2 instance publicly in the module, then yes, you would not need to instantiate it again, because it is available globally (not recommended.), and the sample in the first paragraph would execute without fail.
Anyway, the question really is.. what is it about the code in form2 that you need to call from form1. If its code that may be needed at any time, you should stick it in a class of its own, so you don't waste resources by creating a whole form class, just to call a piece of code. But that's just me, my mindset... if its not related to UI events, and not particular to the form itself, stick it in its own class, then create the class when necessary.
what do you mean by my addtional remarks?Quote:
To ABX:
Please may I make it quite clear that my response was not directed at your answer but at your additional remarks, to which I took offence.
these....
or my signature?Quote:
something like that would work if the second form was called "From2" and the Public Function was Called "FunctionToCall"
Upload your project, mabe we can get a better understanding of what you are trying to do.
Hi nemaroller,
I have spent the last hour trying out the various suggestions. I agree with your comments on using a message box to show the text of another form but that does not seem to relate to my problem.
"Anyway, the question really is.. what is it about the code in form2 that you need to call from form1. "
Form1 contains a datagrid which can be used by any one of six other forms, which will pass parameters to a procedure in Form1 determining the size of the datagrid and the records to be displayed therein, which then displays the datagrid. Whatever I do I cannot access that procedure from another form. (You can do this in VB6 by using something like Form1.proceed (assuming "proceed" is the name of the procedure required) but not in VB.NET).
As I have said, to get round it I have placed the required code in the Form1 activate event and used the code "frm1.ShowDialog" in the calling form event.
Is that any clearer?
Taxes
Hi ABX,
This being my first venture into this Forum I was not aware that some of your remarks were part of a signature. I assumed they were personally directed at me.
Guess it's my misunderstanding. If my arm was long enough I'd reach out and say let's shake and start again.
taxes.
Hi All,
As several of you just did not seem to be experiencing the problem I was having, re installing was the only option. Guess what? I can now, using the same project as before, reference the procedure from outside the form!!!:confused: :confused:
Thanks everyone and apologies for so much time consumed.
Regards,
Taxes.
I knew that some one would get offended by those one of these days, I made my signature a little more clearer so that hopefully that won't happen again.Quote:
Originally posted by taxes
Hi ABX,
This being my first venture into this Forum I was not aware that some of your remarks were part of a signature. I assumed they were personally directed at me.
Guess it's my misunderstanding. If my arm was long enough I'd reach out and say let's shake and start again.
taxes.
Hi taxes,
I apologise as well. I just thought you were being a bit harsh to ABX when he was only trying to help.
Anyway, glad you got your problem sorted.
Nick