Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2003
    Posts
    47

    Unanswered: variables loose their values. strange.

    Heya.

    Situation:
    Form1 has a button. When clicked Form2 pops-up. Form2 makes a call to Form1's public sub.

    When control flow enters Form1's public sub all global variable values in Form1's VB module
    are re-set to 'empty' even though Form1 is still opened. I remember having this problem before.
    I can't think of what caused it.

    Any idea anybody?
    F..ck it, gimme a beer... Jimi Hendrix RULES!

  2. #2
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    421
    the variables probably are global at FORM level thus beeing reset at run from form2.

  3. #3
    Join Date
    Aug 2003
    Posts
    47
    yes, you're correct.

    How do I prevent them from being re-set?

    Does declaring them in Form_Load sub as 'static' help?
    F..ck it, gimme a beer... Jimi Hendrix RULES!

  4. #4
    Join Date
    Aug 2003
    Posts
    47
    on the second though these variables are used in more then one sub and have to be visible
    outside 'Form_Load' sub.
    F..ck it, gimme a beer... Jimi Hendrix RULES!

  5. #5
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    421
    Calling a 'public' sub in a form is 'bad practice' anyway. Anything public and/or global should be put into modules.... Doing so will/should also eliviate the problem

    Regards

  6. #6
    Join Date
    Aug 2003
    Posts
    47
    why is it a "bad practice"?!

    that public sub is only called by second form.

    If you don't have any solution then stop wasting my time and keep your opinions all to yourself.
    F..ck it, gimme a beer... Jimi Hendrix RULES!

  7. #7
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Originally posted by sup
    why is it a "bad practice"?!

    that public sub is only called by second form.

    If you don't have any solution then stop wasting my time and keep your opinions all to yourself.
    Sup,

    I have to agree with namliam ... Calling a sub of a form from another form should be done with extreme care ... I have done the same thing a couple times but on subs that do not initialize variables in the called form ... Why are you doing this anyways?

  8. #8
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    421
    Originally posted by sup
    why is it a "bad practice"?!

    that public sub is only called by second form.

    If you don't have any solution then stop wasting my time and keep your opinions all to yourself.
    Listen friend if you dont appreciate my time and effort thats your porogative.... however i am just (trying hard to not get mad) trying to help... As you may note, in my original post
    he variables probably are global at FORM level thus beeing reset at run from form2.
    I did use PROBABLY, meaning to most ppl I think, but am not sure.... Its a possible source of your trouble.

    Anything public should be public.... NOT inside a form.... When doing so I KNOW there will not be any problem, hence your sollution. Not an opinion but a FACT!

    I will even bet there are better ways of doing this, than using publics...

    Regards

    The Opinionator

Posting Permissions

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