tags:

views:

147

answers:

3

Thanks for your help guys, I've managed to solve the problem now.

It was merely a matter calling loops at the right point in time.

A: 

http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.textfieldparser.aspx

I think your main problem is understanding how arrays work (hence the error message).

You can use split and join functions to convert strings into and out of arrays

dim s() as string = split("1,2,3",",") gives and array of strings with 3 elements
dim ss as string = join(s,",") gives you the string back

bugtussle
Sorry, I'm literally learning programming from scratch - I can't overstate how new to this I am, and so I really don't understand what you're saying. That MSDN site is the guide I've been using to get this far - and frankly I understand v. little of what it says!Surely split and join would just take my lines and split them up or join them together? If that assumption is correct, I don't understand how that would help me, as I'd just take a line and divide it; I don't want to formatting my text, but simply take one line at a time then basically paste it into an array. :\
Ryan
A: 

Firstly, it's actually really good that you are using the TextFieldParser for reading CSV files - most don't but you won't have to worry about extra commas and quoted text etc...

The Readline method only gives you the raw string, hence the "Error 1 Value of type 'String' cannot be converted to '1-dimensional array of String'."

What you may find easier with combo boxes etc is to use an object (e.g. 'systemspecs') rather than strings. Assign the CSV data to the objects and override the "ToString" method of the 'systemspecs' class to display in the combo box how you want with formatting etc. That way when you handle the SelectedIndexChanged event (or similar) you get the "SelectedItem" from the combo box (which can be Nothing so check) and cast it as the 'systemspecs' to use it. The advantage is that you are not restricted to display the exact data in the combo etc.

' in "systemspecs"...
   Public Overrides Function ToString() As String
      Return Name ' or whatever...
   End Function ' ToString

e.g.

dim item as new systemspecs
item.ID = csvalue(1)
item.Name = csvalue(2)
' etc...

combobox1.Items.Add(item)

Let me know if that makes sense!

PK :-)

Paul Kohler
This may be handy if you have not messed around with casting objects much: http://www.codeproject.com/KB/dotnet/CheatSheetCastingNET.aspx
Paul Kohler
I assume the item.id, item.name etc lines are references to a structure? Thankfully, I actually have something like this already in place; omitted it for brevity - structure systemspecs -- used as such: systemspecs.number = csvalue(0) systemspecs.name = csvalue(1)...and so on... textbox1.appendtext(string.format(..., _enviornment.newline, _ systemspecs.name, _ systemspecs.procspeed)( etcUnfortunately, though: "Type 'CsvObject' is not defined." Plus I don't know how to "handle" "selectedindexchanged". Or how to override "ToString" methods... or how to cast "selecteditem"... :P
Ryan
CsvObject is made by - sounds like the `systemspecs` structure you are using. The "selectedindexchanged" is a combo box event I assumed you were using, have a look at the combobox overview an it's members. events etc in MSDN. See updated answer...
Paul Kohler
Okay, inserting the Public Overrides etc inside my systemspecs structure has broken it. I also don't know what a return name is. I really can't stress how new I am to VB - indeed, you may just be better off rewriting my code to something that works, adding comments to explain the changes. :P (though I don't want to appear like I'm asking people to do my work for me!)
Ryan
Ha ha- I know what you mean! if any of these concepts are new probably 'research' them first, e.g. if you are not sure about "Overrides" read up on it etc. When you know the base class libraries it makes things alot easier to know when we are talking your code vs ours etc.
Paul Kohler
I've updated my original post to display my current code. Unfortunately even the simplest of programming articles are way over my head, and time is at a premium, so research is a bit out of the option. I'm shocked there isn't some simple line of code that can do this kind of thing; -- csvalue(count) = csvtranslator.readline ... count = count + 1 -- would work wonders, and make my life so much easier. One day of my life has now been wasted on this crucial segment of code! Thanks for your help so far, Paul :) ...but any further assistance would be appreciated!
Ryan
Just check that you are creatting the structs inside your loop, otherwise it's the same object you are adding. I can't actually compile code at the moment but I'll look again tomorrow... PK :-)
Paul Kohler
A: 

I would recommend using FileHelpers (filehelpers.com) to do the reading. The binding shouldn't be an issue after that.

Here is the Quickstart for Delimited Records

Dim engine As New FileHelperEngine(GetType( Customer))
// To Read Use:
Dim res As  Customer() = DirectCast(engine.ReadFile("FileIn.txt"), Customer())
// To Write Use:
engine.WriteFile("FileOut.txt", res)

When you get the file read, put it into a normal class and just bind to the class or use the list of items you have to do custom stuff with the combobox. Basically, get it out of the file and into a real class asap, then things will be easier.

At least take a look at the library. After using it, we use a lot more simple flat files since it is so easy, and we haven't written a file access routine since (for that kinda stuff).

Andrew Backer
Sorry, external libraries and that sort of stuff is way above my level right now.
Ryan
and frankly, I'd rather get my head around the basics of VB before I start messing around that kind of stuff. Thanks for your help anyway though!
Ryan
Well, all of System.* is a library, so better be careful then :) This is probably the easiest and safest way, but I understand the desire to do it myself. Best 'o luck!
Andrew Backer