Programming help: Visual Basic 5

imported_rod

Golden Member
Apr 13, 2005
1,788
0
0
Hey all,
I'm trying to get a file of comma seperated values, and read them into an array.

So if my data file contained the following line:
00,11,22,33,44

Then the array should contain:
Array(0) = 00
Array(1) = 11
Array(2) = 22
Array(3) = 33
Array(4) = 44

I have tried using the "Line Input" command, but VB is seeing the comma's in the data file as string characters, not as seperators for the array.

Does anyone know how to so this? I don't program that much, and this has got me really stuck?...

Thanks all,
RoD
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
The stuff in the file is just text. VB doesn't know anything about your chosen seperator character.

In general you need to read the file data into a buffer, then start at the beginning and parse out the substrings that contain the numbers, and convert each into a numeric value before sticking it into the appropriate array index.

Fortunately VB makes this very easy with functions like Split() and Replace().

Here's an example showing how Split is used to parse an array of strings seperated by commas. You should be able to extrapolate from this to doing the same thing with numbers.

Dim s As String
s = "Chilkat Mail, ActiveX Component, $99, free upgrades, 1-Year Support"

Dim fields() As String

' Split the string at the comma characters and add each field to a ListBox
fields() = Split(s, ",")

For i = 0 To UBound(fields)
List1.AddItem Trim$(fields(i))
Next

 

imported_rod

Golden Member
Apr 13, 2005
1,788
0
0
That's what I've read elsewhere, but when i try to use the split command, i get "Compile Error: Sub or Function not defined". Do i need to load a package or something? Also, I can't find anything in the help fils about split.

Thanks for the suggestion. Any others?

RoD
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Which begs the question ... why in the world aren't you using at LEAST VB6? VB5 is 4 generations old now.
 

imported_rod

Golden Member
Apr 13, 2005
1,788
0
0
Originally posted by: MrChad
Which begs the question ... why in the world aren't you using at LEAST VB6? VB5 is 4 generations old now.
Well, I haven't done much programming recently, and VB5 is what i already had.

What more recent versions of VB are there? What would you recommend?

RoD
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Originally posted by: rod
Originally posted by: MrChad
Which begs the question ... why in the world aren't you using at LEAST VB6? VB5 is 4 generations old now.
Well, I haven't done much programming recently, and VB5 is what i already had.

What more recent versions of VB are there? What would you recommend?

RoD

Well, VB6 is the last unmanaged version of VB. After that, there's VB.NET 1.0 (2002), 1.1 (2003) and 2.0 (2005). Each of the .NET versions requires the .NET Framework and runs managed code (ala Java). VB.NET can be quite a bit different from its predecessors, but it's also more powerful in my opinion.

You can download a trimmed down version of Microsoft's full Visual Studio 2005 IDE for free.

http://msdn.microsoft.com/vstudio/express/vb/

Check it out and see how you like VB.NET.
 

imported_rod

Golden Member
Apr 13, 2005
1,788
0
0
OK cool.

I had a look at the screen shots and it looks like VB5 combined with HTML-type tags. And the features like Autocorrecting errors could help.

I can buy Visual Studio 2005 (academic edition) for AU$85 (~US$65). Would that be the best version to get if i decided to buy it?

RoD