Simple VB Code Problem

Discussion in 'OT Technology' started by Fase, Apr 7, 2005.

  1. Fase

    Fase Your Face, In A Pickle Jar.

    Joined:
    Apr 6, 2004
    Messages:
    29,540
    Likes Received:
    0
    Location:
    Windsor, Ont, Canada.
    I don't understand why it won't work

    If hisvis = 0 Then
    hisvis = 1
    Form1.Height = 3300
    Text3.Visible = False
    ElseIf hisvis = 1 Then
    hisvis = 0
    Form1.Height = 6945
    Text3.Visible = True
    End If

    It seems it doesn't do the elseif, even if I change it to an else.
     
  2. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    I bet hisvis never equals 1 then. Put a debug.print hisvis before the code to find out
     
  3. Fase

    Fase Your Face, In A Pickle Jar.

    Joined:
    Apr 6, 2004
    Messages:
    29,540
    Likes Received:
    0
    Location:
    Windsor, Ont, Canada.
    Yea I'm pretty sure it never does but why the hell not!?
     
  4. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Well what the hell is hisvis? Is it a public or private variable? If this is a functiona and you've declared the value locally, everytime you enter the function it won't remember the previous value.
     
  5. badjasper

    badjasper Guest

    hisvis will never equal 1 because after the elseif statement your telling it that if it equals 1 then make it 0 after you first told it that if it equals 0 then it equals 1. You are caught in a vicious circle.
     
  6. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    No. Once you go down one path of an if..elseif...else statement, it will not fire the rest of it.
     
  7. badjasper

    badjasper Guest

    Oops, My bad....Severe Brain fart!
     
  8. Fase

    Fase Your Face, In A Pickle Jar.

    Joined:
    Apr 6, 2004
    Messages:
    29,540
    Likes Received:
    0
    Location:
    Windsor, Ont, Canada.
    I declared it in my form load as equal to 0.

    Anyone know of just a better way to do this then?
     
  9. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    At the very top of the module window under the Option Explicit and before the funtions, you have to declare it as a public variable:

    Public hisvis as Long

    Make sure you remove your other declaration.
     
  10. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    skipvis = 0

    If hisvis = 0 Then

    hisvis = 1
    skipvis = 1
    Form1.Height = 3300
    Text3.Visible = False

    End If

    If hisvis = 1 AND skipvis = 0 Then

    hisvis = 0
    Form1.Height = 6945
    Text3.Visible = True

    End If


    You declare skipvis and then you set it to 1 in the first IF statement so your code knows the skip the second statement.
     
  11. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA

Share This Page