Converting Data to an Array and Displaying It

Joined
Oct 28, 2006
Messages
19
Programming Experience
Beginner
Hi, I'm doing an assignment as some of you would have read in my previous post. I now have my data writing to my file fine and reading from it into a text box (used only to confirm its being read). All the data is saved using comma delimited format so i attempted to turn the read data into a one dimensional array by using

test = strA.Split(","c)

Where strA is the data being brought in. It doesnt seem to work because when i attempt to call the values from test it says theres nothing there. Can anyone help me work this out and also is there a way to display a two dimensional array in a form or if not how should i display a large slab of information which is stored in a two dimensional array
 
Hi,
I think you miss the Index because String Splitter result String Array!
it is have to be:
test = strA.Split(","c)(0)
or
dim test() as String = strA.Split(","c)

try it!
 
To have a look at the split array you can assign it to the DataSource of a ListBox.
VB.NET:
Dim strA As String = "one,two,three"
Dim test() As String = strA.Split(","c)
ListBox1.DataSource = test
You can also set a breakpoint in code after the array has been assigned and just mouse hover over the variable to have a look at the items. If you only purpose to display the items was debugging this would be preferable over displaying in Listbox control.
 
You guys are the best. I got that bit working now i just dont know how to put the result of my query (stored in a two dimensional array) into an object on the form where all data in the array can be seen. Im sure with a loop and using variables i could do it but is there an easier way?
 
I'm not sure if a 2D array can be used as a data source for a DataGrid, but grids are used to display 2D (rectangular) blocks of data. If the array cannot be used directly, you should consider storing the data in a datatable instead - that can be used as a data source for a DataGrid
 
You can bind a datagrid to an array, just not with one or two lines of code. But as it looks like the fellow in the following article has done all the hard work already, you probably can do it with one or two lines of code...

http://www.codeproject.com/cs/database/BindArrayGrid.asp
 
While that page would be very useful if i was doing Visual C#, i am only allowed to use Visual Basic.NET 2003 for this task so is there anyway to do it in VB?
 
The way the article is written implies the author is using .NET 1.1
It is of no concern that the syntax in use is C# because, u8nderneath, C# and VB.NET are the same language and can interoperate. Additionally, you do not have to convert the C# to VB to use it.. Simply download the source code, choose File..Open Project from your IDE, and select the C# project. Ensure that "Add to solution" is chosen (rather than "close solution") and the C# project will be added to your VB solution. Then review the "how to use the code" - it contains only one line that is of importance, and easily converted to vb:

dataGrid1.DataSource = new ArrayDataView(array);


replace datagrid1 with your datagrid's name, array with your array name, and remove the semicolon. The C# project will contain a definition for ArrayDataView.

You may find it interesting to watch, as you single step the code, that your vb code steps into C# and back again seamlessly.


The following article will help you learn the differences between C# and vb:
http://www.harding.edu/USER/fmccown/WWW/vbnet_csharp_comparison.html

being able to read C# is a skill worth acquiring. You may even realise that it's so similar to VB.NET that you can program in it with the same competence as VB
 
ps, if your IDE is visual basic only (i.e. not Visual Studio) then it may not be able to use the C# source, but it wont have a problem using the pre-compiled DLLs from the DEMO version of the project. Simply add a reference to the DLL instead of adding the project to the solution
 
ok i did what u said to open it and add it to my project, but i still get
ArrayDataView is not defined when i add that code in my form. So can u run be through step by step how to do it incase im screwing it up
 
I'd have thought the reference was implicitly created but maybe not. Open a file in your VB project (it makes sure the vb project is the active one). On the project menu, choose Add Reference, choose the Projects. Listed in there will be the C# project.. Add the reference so that the VB project has a reference to the C# project.

If the C# project has a namespace then you will either need to import it at the top of the code or specify it when you create the component..

i.e. the C# project is made by ACME Solutions and its namespace is ACMESol.DataComponents:


Imports ACMESol.DataComponents 'at the top of the file or
dataGrid1.DataSource = new ACMESol.DataComponents.ArrayDataView(array);


programmingstudent said:
thanks for replying to my message, the only thing is im doing a visual basic course and i have to submit my assignment online would that cause any problems and is there a way to do it in vb without using c?

Check the rules surrounding use of components created by third parties. If you are thus restricted, you'd be better off tossing out the idea of a 2D array all together, and just using a DataTable.. it's a rectangular block of data that is fixed horizontally (like an array) but can grow vertically (more useful than an array)



Maybe noone mentioned before but with OLE DB access you can actually attach to a CSV file as though it were a database. The data access methods in VB.NET mean that reading the file, splitting it into cells, and turning it in a datatable and showing it in a datagrid can be achieved in about 15 lines of code
 
i managed to get the dataview working using that code you gave me after i fixed my array. In the code it makes minor mention of setting column names but im still not sure how to do it. If you could help me with this it would be great. Also theres no way to make a 2 dimensional array resize itself automatically is there?
 
Back
Top