|
-
Dec 8th, 2005, 02:25 PM
#1
Thread Starter
New Member
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.
-
Dec 8th, 2005, 03:36 PM
#2
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)
-
Dec 8th, 2005, 04:24 PM
#3
Thread Starter
New Member
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.
-
Dec 8th, 2005, 04:45 PM
#4
Re: eVB - IF statement on text box
What I meant was keep the quotes, just remove the brackets, eg:
VB Code:
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:
'At the top of a Module:
Public StartUpValue as String
'In the "other" form:
StartUpValue = "SWQ"
Load [i]thisform[/i] '(not sure of eVB syntax for this, just use what you currently use!)
'In this form:
Private Sub Form_Load()
If StartUpValue = "SWQ" Then
ResultsComboBox.AddItem "2ND"
...
-
Dec 8th, 2005, 05:37 PM
#5
Thread Starter
New Member
-
Dec 8th, 2005, 05:43 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|