472,328 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Populate dictionary with text file VB

GTXY20
29
Hi All,

I have been able to create a successful application with Python but I am being asked to create in VB.

I have a text file with the following data:

1,a
1,b
1,c
2,a
2,a
2,b
3,a
3,c

I need to create a dictionary in VB so that I can then iterate over it so that my key is the first field and my item is the concatenation of unique items for each key in the text file:

In Python I would have:

Expand|Select|Wrap|Line Numbers
  1. {1:(a,b,c), 2:(a,b), 3:(a,c)}
I am starting with the following in VB:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ImpFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImpFile.Click
  2.         Dim uhdict As Dictionary(Of Integer, String) = New Dictionary(Of Integer, String)
  3.         Dim openimp As New OpenFileDialog()
  4.         If openimp.ShowDialog() = DialogResult.OK Then
  5.             Dim sr As New System.IO.StreamReader(openimp.FileName)
  6.             sr.Close()
  7.         End If
  8.     End Sub
  9.  
How do I begin to assign a variable for the key, assign a variable for the items and then add to the dictionary uhdict.

Any help and guidance wher to start is very much appreciated.

Thanks again.
Oct 17 '07 #1
3 3192
Shashi Sadasivan
1,435 Expert 1GB
Hi All,

I have been able to create a successful application with Python but I am being asked to create in VB.

I have a text file with the following data:

1,a
1,b
1,c
2,a
2,a
2,b
3,a
3,c

I need to create a dictionary in VB so that I can then iterate over it so that my key is the first field and my item is the concatenation of unique items for each key in the text file:

In Python I would have:

Expand|Select|Wrap|Line Numbers
  1. {1:(a,b,c), 2:(a,b), 3:(a,c)}
I am starting with the following in VB:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ImpFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImpFile.Click
  2.         Dim uhdict As Dictionary(Of Integer, String) = New Dictionary(Of Integer, String)
  3.         Dim openimp As New OpenFileDialog()
  4.         If openimp.ShowDialog() = DialogResult.OK Then
  5.             Dim sr As New System.IO.StreamReader(openimp.FileName)
  6.             sr.Close()
  7.         End If
  8.     End Sub
  9.  
How do I begin to assign a variable for the key, assign a variable for the items and then add to the dictionary uhdict.

Any help and guidance wher to start is very much appreciated.

Thanks again.
Are you having issues with reading the text file and extracting its values or with adding elements into the dictionary? Or all of it?
Dictionary has an Add method

Expand|Select|Wrap|Line Numbers
  1. int x = 0;//put your number here
  2. string val = "value";//
  3. uhdict.Add(x,val);
(Do apply the conversion to vb .net from one of the online converters)
Oct 17 '07 #2
GTXY20
29
Thanks but I am having difficulty assigning the variables to the text file so that if I use split by "," the first variable say a is assigned that value and that will be the key and the next value after the comma is assigned to say variable b and it will be the value for the key - I then need to append to the values where the key is the same when reading the text file and splitting using comma. Something like:

1,a
1,b
1.c


Key = 1

Value = a,b,c

So can I use a for loop to say if Key is present append value if it doesn't currently exist and sort values.

Thanks.
Oct 17 '07 #3
Shashi Sadasivan
1,435 Expert 1GB
Thanks but I am having difficulty assigning the variables to the text file so that if I use split by "," the first variable say a is assigned that value and that will be the key and the next value after the comma is assigned to say variable b and it will be the value for the key - I then need to append to the values where the key is the same when reading the text file and splitting using comma. Something like:

1,a
1,b
1.c


Key = 1

Value = a,b,c

So can I use a for loop to say if Key is present append value if it doesn't currently exist and sort values.

Thanks.
Hi ,
PLease have a look at some tutorials on how to use a Dictionary.
By the way you speak, I dont think you have looked at this datattype.

good luck
Oct 17 '07 #4

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

Similar topics

11
by: alex | last post by:
Hi, I am looking for a way to populate an HTML table from an external local text file which looks like this: DATE/TIME LAT. ...
1
by: t0M | last post by:
It's nearly impossible to find anything on this because of the Dictionary class, included within the dotnet framework, that pollutes any search...
2
by: Berimor | last post by:
Hey guys, has anybody scripted online translators? I got the task to build one but it should traslate big pieces of text at once - up to 5000...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i...
9
by: oz | last post by:
Hi All, I want to make a dictionary with windows application. My data is html format. therefore, i use webBrowser control on my windows form. If...
2
by: Andy B | last post by:
I don't know if this is even working or not but here is the problem. I have a gridview that I databound to a dictionary<string, stringcollection: ...
20
by: Simon Strobl | last post by:
Hello, I tried to load a 6.8G large dictionary on a server that has 128G of memory. I got a memory error. I used Python 2.5.2. How can I load my...
4
by: John Townsend | last post by:
Joe had a good point! Let me describe what problem I'm trying to solve and the list can recommend some suggestions. I have two text files. Each...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

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.