weird but serious combo box problem

J

jeffery

i need help with a combo box and this same code works on my first tab with a
combo box. The error or problem i have is this code causes an index out of
range error when i run it on my second combo box:
(errored code) Select Case ComboBox2.text
Case Is ="Execute Program"
'code to execute program here
Case Is ="Other Command that executes code at a certain time"

' code below the same as above except that it works
But not my first(this code works fine):
Select Case ComboBox.text

i tryed changeing my selected index so it would always have a zero or first
item in the index subscript and checking index properties but i still get
this error and i put my selected index in a combo box just to see if thats
not the error and it is not the index is equal to -1.

any help as to why this happens because i dont know why but every time i get
this error

thanks for any help that can be offered,
jeffery the planner
 
F

Family Tree Mike

Using the debugger, what is the value of ComboBox2.text at the Select Case
statement? What are the values of the ComboBox2.Items list? Does the
ComboBox2.text show up in your list of cases for the Select statement?
 
J

jeffman

i do have the strings in my select case in my combo box too and the index and
text i select are correct too. i tryed using Combobox.items.item property and
selecteditem and they both caused errors for me.
 
F

Family Tree Mike

Can you post a complete code example that fails?

jeffman said:
i do have the strings in my select case in my combo box too and the index and
text i select are correct too. i tryed using Combobox.items.item property and
selecteditem and they both caused errors for me.
 
J

jeffery

this is the code that causes errors:
Select Case ComboBox2.text

Case Is ="Execute Program"

'commands to select program to execute
'code brevity because i dont have the time to give full code
ListCommands.items.Add("Execute Program")
'other list box adds here like adding the time to execute the task
'use a open file dialog box to select a program to execute
ListPrograms.items.add(OpenFileDialog1.FileName)
'add code here to lock the timed event as i said i the comment above i have
code abrevity or in this line i just tell what other code would go here.

Case Is ="Auto-Type into Program"

'Other cases for other commmands here

ComboBox2.text equals the correct value i selected from combobox2 at
runtime. Example: I select ""execute program"" (for emphais so someone will
pay attention) from the combo box and it is supposed to execute a program.
But the selectedindex is correct for combo box2 when my selected index
changed event fires. for instance execute program would be first in combo
box2 so the selectedindex would be 0 for execute program. can someone help me
because this is all i know and i am not a professional programmer either and
not a beginner programmer either but i dont know everything but i know a lot
of programming tasks.

this is all i know if you know anything else i can add please tell me i have
run out of things to tell you and i think my problem could have already been
answered by now.

can anyone provide an answer it is just so fustrating programming with weird
errors like this becuase the text property shouldnt cause a error because it
should come up with a string value of a item i select out of items i add
statically and shouldnt be changed if i dont tell it to.

iam sorry but this sounds like something simple the error it gives me is:
"index out of range index is less then zero or greater then list count - 1" i
tryed what you said about checking the index to see if its correct and that
and incorrect text or blank text are not problems either so iam guessing or
thinking it is a simple problem.

thanks for any help because this is so fustrating , but i still cant figure
it out

jeffery
 
A

Andrew Morton

jeffery said:
this is the code that causes errors:

Get it to tell you what the value is before you try using it:

MsgBox(ComboBox2.text)
Select Case ComboBox2.text
Case "Execute Program"
<snip>

And make sure to use Option Strict On, which will catch a lot of errors.

Andrew
 
J

jeffery

the message box didnt help i still have a error and i have another group i
posted to and i am wanting to go professional and iam not spamming just so
you all can know. the other group said i should try the collections of the
combobox. i dont know what properties they were wanting me to use to do this
the only propertys i would know how to use is most of the propertys in the
items class. i heard about other propertys about dealing with collection in
list and combboxs in msdn help but dont know how to use them but dont know
how to use them.
 
F

Family Tree Mike

We would be guessing at what the other group meant so you need to ask them.
Items, however is a property returning a collection. They may have meant
that property.

When you say the message box did not help, do you mean it errors on that
line (the messagebox)? If it does not error on the message box, but errors
on the line immediately after it (the Select statement), I would be at a loss
to explain this.

Here is an off the wall thought. Is this code in an event handler for the
selectedindexchanged? I don't recall the order of events when a combo box
selection is changed, but you may be in the gray area where there is a
difference in the selectindex, and the text value.
 
J

jeffery

this is the line of code for the messagebox : Msgbox(Combbox2.text)
and family tree mike do you mean that there is a gray area between my index
and text properties on my combo box or do you mean there is something wrong
happening in my selected index changed event for my combo box and the last
time i checked my selected index changed event on combobox2 it didnt work and
it only wants to work periodcally i dont know if this will help any but i
figured out that thisis a problem too. do you think this would help me solve
my problem either? any help would be nice this problem is beginning to be a
pain in the butt but iam confident the more i and you find out we might
eventually find a problem.

jeffman
the planner
 
F

Family Tree Mike

Jeffery,

Sorry it took me a bit to get back. What I was refering to is the order
that events fire from a user changing the combobox. It is important to know
the order they fire or you could get into a mismatch of the state of the
control. Take a look at the following link if you have not seen it.
Basically, you want to make sure all events from a combobox change by the
user have fired before you look at the SelectedIndex, SelectedItem, Text and
other properties. I hope this helps explain the gray area that I was
describing. What I was getting at was the selectedindex may have changed,
but no the text, or vice versa.

http://technet.microsoft.com/en-us/....forms.combobox.selectionchangecommitted.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top