Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo box (list index? compare value and display default)

Status
Not open for further replies.

cyberbiker

Programmer
Mar 16, 2001
431
US
This is either very simple or crazy but here goes.
I am reading a text file and placing values in an array.
(one full record, sort of a working storage)
I then process the data in the array depending on the value of the second field (Subscript 1 in the array) in the text file record.
The third field (array sub 2) is a default value that varies on each record
If that is a record type is an enumerated list then I fill a combobox (style property set to "dropdown list" text property is read only when that style is selected) using the additem method.
Now the problem. How do I manage to get the combo box to select the value in the list that matches the default field?
I do not wish to change the style property to dropdown combo since I do not wish my users to be able to enter any value except what is on the list.
For various reasons I must use this text file and some form of drop down box but any solution that permits that is most welcome
Terry (cyberbiker)
 
I'm not sure i understand your question, but if i do this should work.
Assuming your Enum looks like this:
Code:
Public Enum SomeList 
   Item1 = 1 
   Item2 = 2 
   Item3 = 3 
End Enum
Fill the combo like this:
Code:
cboListValues.AddItem "Item1" 
cboListValues.ItemData(cboListValues.NewIndex) = 1 
cboListValues.AddItem "Item2" 
cboListValues.ItemData(cboListValues.NewIndex) = 2
cboListValues.AddItem "Item3" 
cboListValues.ItemData(cboListValues.NewIndex) = 3
Now you can select a default by the value
Code:
For Count = 0 To cboListValues.ListCount - 1 
   If cboListValues.ItemData(Count) = YourDefaultValue Then 
      cboListValues.ListIndex = Count    
   End If 
Next Count
Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
Appreciate the info. I will look at this further Monday.
I am afraid I do not communicate well.
The situation is that I read a text file with an unpredictable number of fields per record with an unpredictable length.
All fields ae encased in quotes which is how I parse it.
The values are stored in array which I redim each loop through reading the record. I then read the array values into a sorted drop down list box. I need to have them sorted but they may be in the text file in any possible order. From what I am interpreting of your code, it looks like I would put the items in and assign the list index in that order? Am I correct on that assumption? I do not have a way to determine the list index that I can think of as yet if sorted. Perhaps I can change the sort property to sorted after the ADDITEM takes place????
I have just thought of that as I am typing this message and will try that first thing Monday AM .

Terry (cyberbiker)
 
Thanks for the help on this. I studied what you had written and that lead me to using this code Which works quite well

Dim i As Integer
Dim Count As Integer
Dim intNumVal As Integer

DisplayLbl 'calls display routine and creates control on the fly
displayCbo' ditto

'varFields is an array position 0 to 3 are other values position 3 is the 'default' value
For i = 4 To intFieldCount - 1
frmUpdate.cboParam(intParamCount).AddItem varFields(i)
If varFields(i) = varFields(3) Then
intNumVal = i - 4
End If
Next i
frmUpdate.cboParam(intParamCount).ListIndex = intNumVal
End Sub Terry (cyberbiker)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top