Link to home
Start Free TrialLog in
Avatar of BryanKipp
BryanKipp

asked on

Load Column Data into a ComboBox from a .csv file

I have a .CSV file that has 5 columns. I want to populate a ComboBox with just the first "Column" data. I am using the following code:

Private Sub Display_AnimationStart()

 Dim strHeadings, strContent() As String
 Dim iCtr As Integer

 Open "C:\RSLogix 5000\Projects\ArrayTags.csv" For Input As #1
  Line Input #1, strHeadings
 Close #1

 strContent = Split(strHeadings, ";")
 For iCtr = 0 To UBound(strContent)
  Pen1_ComboBox.AddItem strContent(iCtr)
 Next
 
 On Error Resume Next
For iCtr = 0 To UBound(strContent)
 Pen1_ComboBox.AddItem strContent(iCtr)
Next
On Error GoTo 0

End Sub

This appears to open the file, but loads the combobox with the data in the first row of the file two times rather than loading just the items in the first column.

The file data is:

Annapolis Hill Discharge Pressure;AH_DISCHARGE_PRESSURE;PSI;0;500
Annapolis Hill Suction Pressure;AH_SUCTION_PRESSURE;PSI;0;500
Annapolis Hill Tank Level;AH_TANK_LEVEL;FT;-25;-5
Backwash Flow Control Valve Position;BKWASH_FCV_POS_IN;Percent;0;100
Backwash Flow;BKWASH_FLOW;GPM;0;250
Backwash Flow Set Point;BKWASH_FLOW_SP;GPM;0;250
Chaffee Hill Discharge Pressure;CH_DISCHARGE_PRESSURE;PSI;0;500
Chaffee Hill Suction Pressure;CH_SUCTION_PRESSURE;PSI;0;500
Chaffee Hill Tank Level;CH_TANK_LEVEL;FT;-25;-5
Clear Well Level 1;CLEARWELL1_LEVEL;FT;0;10
Clear Well Level 2;CLEARWELL2_LEVEL;FT;0;10
Clear Well Level 3;CLEARWELL3_LEVEL;FT;0;10

What I am looking for is to have the combobox poulated with everything in the first column.

Thanks
Avatar of dqmq
dqmq
Flag of United States of America image

Try this:
Private Sub Display_AnimationStart()

 Dim strHeadings, strContent() As String
 Dim iCtr As Integer

 Open "C:\RSLogix 5000\Projects\ArrayTags.csv" For Input As #1
  Line Input #1, strHeadings

While Not Eof(1)
   strContent = Split(strHeadings, ";")
   For iCtr = 0 To UBound(strContent)
      Pen1_ComboBox.AddItem strContent(iCtr)
   Next  
   Line Input #1, strHeadings
Wend

Close #1

 End Sub

Open in new window

Avatar of BryanKipp
BryanKipp

ASKER

That added all the rest of the data, but I'm still getting one line item in the combo box for every item in the .CSV file.....i. e.
 the combobox looks like this

Annapolis Hill Discharge Pressure
AH_DISCHARGE_PRESSURE
PSI
0
500
Annapolis Hill Suction Pressure
AH_SUCTION_PRESSURE
PSI
0
500
....etc.

What I'm looking for is:

Annapolis Hill Discharge Pressure
Annapolis Hill Suction Pressure
....etc.
ASKER CERTIFIED SOLUTION
Avatar of dqmq
dqmq
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks! This solves part one of my problem.....now on to part two.