Results 1 to 6 of 6

Thread: eVB - IF statement on text box

  1. #1

    Thread Starter
    New Member spitfire77's Avatar
    Join Date
    Dec 2005
    Location
    Pensacola, Florida, USA
    Posts
    6

    eVB - IF statement on text box

    Hi, This may seem simple to some, but I can't get it working. I need to load different sets of lists into a combo box depending on the value code that is in a text box (this is just 2 sets below).

    On the form, the text box "txtEventType.Text" gets loaded by a process on a previous form. Then once on this form, that box's value is shown on this form. Then the Form_Load() sub needs to read that text box and load the values of the combo box depending on the contents of the text box. Simple enough, but I can't get it to work. Here is my code, can you make it better?

    Private Sub Form_Load()
    If txtEventType.Text = "SWQ" Then
    ResultsComboBox.AddItem ("2ND")
    ResultsComboBox.AddItem ("3RD")
    ResultsComboBox.AddItem ("INC")
    ElseIf txtEventType.Text = "WF1" Then
    ResultsComboBox.AddItem ("PASS")
    ResultsComboBox.AddItem ("FAIL")
    End If
    End Sub

    Since the form object that I am trying to access is a text box and what I am trying to compare it with is a text string literal in quotes, why is that not working? Teach me something, please.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: eVB - IF statement on text box

    Hi spitfire77, welcome to VBForums!

    I have done some work in eVB before, and I know it is very similar to VB6.

    Your code should be ok, apart from the brackets around "2ND" etc, which are not needed.

    Are you sure that the value in the textbox is exactly SWQ or WF1? (eg: not sWQ, and no extra spaces)

  3. #3

    Thread Starter
    New Member spitfire77's Avatar
    Join Date
    Dec 2005
    Location
    Pensacola, Florida, USA
    Posts
    6

    Re: eVB - IF statement on text box

    Thank you

    Yes, those codes are exact, the correct case, and those are only 2 of the several sets that I have. If I can't get it to work for 2, then it can't work for several.

    The similarity of VB6 to eVB is that embedded VB is a sub-set of full Visual Basic. Embedded Visual Tools 3.0 has the editor that looks just like VB6. It's just that in eVB, I don't have the full functionality that VB6 does.

    I was confused about removing the quotes because that makes it a string literal. But I tried to remove the double-quotes on the 2ND, 3RD, INC, PASS, FAIL. The editor gave me errors when removing the quotes from the 2ND and 3RD but not the others. So I commented out the 2ND and 3RD and tried anyway for the others, but when I ran the program, none of the info does appears in the combo box. So there is something else that it still needs.

    Thank you for the reply.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: eVB - IF statement on text box

    What I meant was keep the quotes, just remove the brackets, eg:
    VB Code:
    1. ResultsComboBox.AddItem "2ND"


    I've actually realised why this isn't working, the problem is that the code is in form_load.

    When the textbox value is being set by the other form, the first thing it does is to load the form (thus running form_load) before the value is set.

    What I would recommend you do to instead is to declare a variable in a module (as Public, so both forms can see it) and set it in the other form. You can then read it safely, eg:

    VB Code:
    1. 'At the top of a Module:
    2. Public StartUpValue as String
    3.  
    4. 'In the "other" form:
    5. StartUpValue = "SWQ"
    6. Load [i]thisform[/i]   '(not sure of eVB syntax for this, just use what you currently use!)
    7.  
    8. 'In this form:
    9. Private Sub Form_Load()
    10. If StartUpValue = "SWQ" Then
    11.   ResultsComboBox.AddItem "2ND"
    12. ...

  5. #5

    Thread Starter
    New Member spitfire77's Avatar
    Join Date
    Dec 2005
    Location
    Pensacola, Florida, USA
    Posts
    6

    Re: eVB - IF statement on text box

    Ok, great! So Form_Load is not receiving the variable info yet even though it's pushed from the previous form. I just tested it by placing code to copy the event code to a different text box in Form_Activate and that worked. So it didn't work in Form_Load but it might work in Form_Activate.

    I'll re-arrange some form code and use the method you suggest and put it in a global instead of directly into the next form's display text box. Then text from that global. That's a good idea. I wish I would have thought of that before, but that's why I'm here.

    So you have taught me something!

    That does help! And quick too! I've been on other forums where I received no answer at all to my questions.

    Thank you!

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: eVB - IF statement on text box

    Good stuff, I hope all goes well


    This place is busy (49 registered members logged in at the moment!), so most questions are answered (to some degree) pretty quickly.. unfortunately some don't get answers for various reasons, but luckily that is a small percentage

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