Results 1 to 20 of 20

Thread: Calling procedures

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Calling procedures

    Hi,

    Anyone figured out if you can call a PUBLIC procedure in one form from an event or procedure in another form?

    Taxes
    Last edited by taxes; Dec 31st, 2003 at 04:09 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  2. #2
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    the procedure would have to be declared Public

    'Calling form

    VB Code:
    1. 'Function that calls function
    2. Private Function CallFunction()
    3.  
    4. Dim frm2 as New Form2
    5.  
    6. frm2.FunctionToCall

    something like that would work if the second form was called "From2" and the Public Function was Called "FunctionToCall"
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  4. #4
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    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>.
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    <ABX's code is right correct .

    <comment removed by admin>and make sure your responses are accurate?
    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 .

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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
    Last edited by taxes; Dec 31st, 2003 at 09:28 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  7. #7
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    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:
    1. Pubic Sub messagealert()
    2.   messagebox.show("hi from FORMa")
    3. 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:
    1. myFORMa.messagealert()

    If you don't have a FORMa instantiated, you must instance it before you call it:
    VB Code:
    1. Dim myFORMa As New FORMa
    2.  myFORMa.messagealert()

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    This demo shows <ABX is correct .
    Attached Files Attached Files

  9. #9
    ex-Administrator brad jones's Avatar
    Join Date
    Nov 2002
    Location
    Indianapolis
    Posts
    6,614
    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
    Have you given out your reputation points today? Select the Rate This Post link to give points for good posts!
    -------------------------------------------------------------
    Brad! Jones
    Lots of Software, LLC
    (I wrote: C Programming in One Hour a Day) (Dad Jokes Book) (Follow me on Twitter)

    --------------------------------------------------------------

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi Brad Jones.

    O.K. Point taken. I guess I over reacted. My apologies to any offended by my responses.

    Taxes
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  11. #11
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Did you get it resolved?

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  13. #13
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    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:
    1. 'BELONGS IN "FORM1"
    2. 'Function that calls function
    3. Private Function CallFunction()
    4.  
    5. Dim frm2 as New Form2
    6.  
    7. frm2.FunctionToCall
    8.  
    9. '....

    VB Code:
    1. 'Belongs In "Form2"
    2. Public Function FunctionToCall
    3.  
    4. 'This is the Function That MUST be Public
    5.  
    6. Msgbox("HELLO")
    7.  
    8. 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 )
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  14. #14
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    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
    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.

    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.

  15. #15
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    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.
    what do you mean by my addtional remarks?

    these....
    something like that would work if the second form was called "From2" and the Public Function was Called "FunctionToCall"
    or my signature?

    Upload your project, mabe we can get a better understanding of what you are trying to do.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  18. #18

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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!!!

    Thanks everyone and apologies for so much time consumed.

    Regards,
    Taxes.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  19. #19
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    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.
    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.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  20. #20
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    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
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width