In the mid-'90s I wrote in Quick Basic some lab simulations for science classes I was teaching. I want to rewrite them in VB and thought that I could just paste old QB code into VB... not so, of course.

I want to know how to read data from within the program into an array. Below is a sample of the old QBasic code I'm trying to duplicate.

DATA 32
'DATA is Name, kingdom, p for photosynthesis, s for single celled
DATA Smeglitious nobilis,monera,,s
DATA Computicus garianus,monera,,s
DATA Fastidyus hassica,monera,p,s
DATA Diminutia scotia,protista,p,s
DATA Strongellica sphinctius,protista,,s

DIM org$(5, 4)
ReadOrganismData:
  READ d
    FOR organisms = 1 TO d
        FOR organisminfo = 1 TO 4
          READ org$(organisms, organisminfo)
        NEXT organisminfo
    NEXT organisms
orgName = 1
Kingdom = 2
photo = 3
singleCelled = 4

There are several ways in which to add data to an array...

Dim S As String, MyArray() As String
S = "test1,test2,test3,test4"
MyArray = Split(S, ",")
Dim MyArray() As Integer
ReDim MyArray(3) As Integer
MyArray(0) = 0
MyArray(1) = 12
MyArray(2) = 34
MyArray(3) = 43
Dim I As Integer, MyArray() As String

For I = 0 To 10
  ReDim Preserve MyArray(I) As String
  MyArray(I) = CStr(I)
Next I

So, from what I can see is that you are using a two dimensional array and you are also populating this information from a file or some source. I'm guessing it is a file as I don't quite remember what the read statement is for in qbasic.

The following is for a file in the following format...
Data1Line1,Data2Line1,Data3Line1,Data4Line1
Data1Line2,Data2Line2,Data3Line2,Data4Line2
'...
Data1Line5,...

Dim FName As String, FNumb As Integer
Dim LineContents As String, PiecesOfData() As String, ForLoopCounter As Integer
Dim CapturedData(0 To 4, 0 To 3) As String, LineCnt As Integer 'or 1 to 5, 1 to 4

FNumb = FreeFile
FName = "Path File Name"

Open FName For Input As #FNumb
Do While Not EOF(FNumb)
  Line Input #FNumb, LineContents
  PiecesOfData = Split(LineContents, ",")
  For ForLoopCounter = 0 to 3 'or 1 to 4
    CaptureData(LineCnt, ForLoopCounter) = PiecesOfData(ForLoopCounter)
  Next ForLoopCounter
Loop

Close #FNumb

Good Luck

The READ command in old QBasic looked within the program itself, not an external file, for the "DATA" and read it in the order it appeared. So, in my old code below, the first READ d put the number 32 into the variable d. Then the READ within the FOR...NEXT loop put the rest of the DATA into the array.

So, how do put my "DATA" into the program itself, then have VB read the data into the two dimensional array?

(I know the syntax for the string variables in my old code are wrong for VB)

Thanks for any advice... as you can see, I am truly a novice.

:-) Don't feel bad. I'm ashamed myself that I could not remember the read command from QB but hey that is the way things go.

Okay, is this data static? Never changes? Then in a bas module this might be the easiest...

Option Explicit
Public Org(1 to 5, 1 to 4) As String 'integer, long, double...

Public Sub InitializeOrgArray()
Org(1, 1) = "Some value"
Org(1, 2) = "Some Value"
'...
Org(2, 1) = "Some Value"
'...
Org(5, 4) = "Some Value"
End Sub

However, if this data is not static... Then how do you plan on getting the data?

Good Luck

This question has already been answered. Start a new discussion instead.