• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1036
  • Last Modified:

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
0
BryanKipp
Asked:
BryanKipp
  • 2
  • 2
1 Solution
 
dqmqCommented:
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

0
 
BryanKippAuthor Commented:
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.
0
 
dqmqCommented:
My bad. Change this


While Not Eof(1)
   strContent = Split(strHeadings, ";")
   Pen1_ComboBox.AddItem strContent(0)
   Line Input #1, strHeadings
Wend
 
0
 
BryanKippAuthor Commented:
Thanks! This solves part one of my problem.....now on to part two.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now