473,322 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Combobox not populating with values from text file

13
Hi guys

need your help with a project im working on.

I have 2 comboboxes that are not getting the values from a CSV text file.

I have no errors during debug.


CSV text file text
Expand|Select|Wrap|Line Numbers
  1.  Category,Weight
  2. Category,Distance
  3. Weight,LB to KG,0.45359237
  4. Weight,KG to LB,2.20462262
  5. Distance,Mile to KM,1.609344
  6. Distance,KM to Mile,0.621371192

Code

Expand|Select|Wrap|Line Numbers
  1.  Option Strict On
  2. Option Explicit On
  3. Public Class Form1
  4.     Dim UnitConvVal As Double ' Global Variable for Unit Value.
  5.  
  6.     Public Sub DataLoad(ByVal Switch As String)
  7.         Dim tfLines() As String = System.IO.File.ReadAllLines("data.txt") ' File to load.
  8.         For Each line As String In tfLines ' Load and read all lines in file.
  9.             Dim field As String() = line.Split(","c) ' Split using ,.
  10.  
  11.             Select Case Switch
  12.                 Case "LoadCategory"
  13.                     If field(0) = "Category" Then
  14.                         cboCategory.Items.Add(field(1))
  15.                         cboCategory.SelectedIndex = 0 ' Auto Select first Category.
  16.                     End If
  17.  
  18.                 Case "LoadUnits"
  19.                     If field(0) = CStr(cboCategory.SelectedItem) Then
  20.                         cboConvertTo.Items.Add(field(1))
  21.                         cboConvertTo.SelectedIndex = 0 ' Auto Select first Unit.
  22.                     End If
  23.  
  24.                 Case "SelectUnit"
  25.                     If field(1) = CStr(cboConvertTo.SelectedItem) Then
  26.                         UnitConvVal = CDbl(field(2)) ' Load Unit's Conversion value, store in UnitConvVal as Double.
  27.                     End If
  28.             End Select
  29.         Next
  30.  
  31.     End Sub
  32.  
  33.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
  34.         DataLoad("LoadCategory") ' Switch to DataLoad to load Categories on form load.
  35.     End Sub
  36.  
  37.     Private Sub cboCategory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
  38.         cboConvertTo.Items.Clear() ' Clear cboConvertTo Combobox when re-loading units after selection change.
  39.         DataLoad("LoadUnits")
  40.     End Sub
  41.  
  42.     Private Sub cboConvertTo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboConvertTo.SelectedIndexChanged
  43.         DataLoad("SelectUnit")
  44.     End Sub
  45.  
  46.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
  47.         If txtInputVal.Text = Nothing Then
  48.             MessageBox.Show("Please Enter A Value to Convert") ' Display message if no value is entered.
  49.         Else
  50.             txtResult.Text = CStr(CDbl(txtInputVal.Text) * UnitConvVal) ' If Value has been entered, compute conversion for unit.
  51.         End If
  52.     End Sub
  53. End Class
  54.  


Thanks in advance
Jul 3 '12 #1
0 1649

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Paul C-T | last post by:
Hi, Am I trying to be too clever here? I am trying to write a PHP page to enable me to enter values into a form then write those values to a text file. I want to use the form & table that...
1
by: freddy | last post by:
I would like to load items to a combobox from a text file.
7
by: Chris | last post by:
Hi I can use a text file as a datasource but am unable to get the datatable to see the text file as having multiple columns. Everything gets put into the first column in the datatable. Sample of...
2
by: kohoutec | last post by:
I have a combobox that populates its items from a text file when its form loads. I have added to one of my buttons click events some code to add any entrys that are manually entered to the combo -...
7
by: George | last post by:
Hi, Does anyone know how to bind text file to a datasource (of a combobox in my case)? I went through the properties, but it seems like the only "boundable" sources are databases such as...
5
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
0
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
0
by: fedroque | last post by:
heres the scenario: i have a book and i scanned its barcode to get all the information using app A, but i need all these info, plus more to print a new barcode using a barcode software, app B. i...
2
by: vanea | last post by:
Hy. I have a little problem with a comboBox on my form, and i want to ask if anyone could help me. I'm writing a DB application and i am populating my comboBoxes with an ArrayList object and a...
1
by: Audie7734 | last post by:
I have a comboBox in which a store individual's names. Upon loading the program, I want the comboBox loaded from a text file. Note: the first line of the txt file is: <Enter New Name>. I want to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.