Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleQuickly load an array with values in VB3
Keywordsarray, load, values, data
CategoriesTips and Tricks, Software Engineering
 
Visual Basic does not have a DATA statement. VB3 does not have array variants which make this easy in VB4 and VB5. This program uses a function to read the parse comma-separated values from a text string.
 
Sub LoadNumbers (arr() As Integer, ByVal txt As String)
Dim pos1 As Integer
Dim pos2 As Integer
Dim txtlen As Integer
Dim num_commas As Integer
Dim num_txt As String
Dim i As Integer

    ' Count the commas.
    num_commas = 0
    pos1 = InStr(txt, ",")
    Do While pos1 > 0
        num_commas = num_commas + 1
        pos1 = InStr(pos1 + 1, txt, ",")
    Loop

    ' Make room for the numbers.
    ReDim arr(1 To num_commas + 1)
    
    ' Read the numbers.
    txtlen = Len(txt)
    i = 1
    pos2 = 0
    Do While pos2 < txtlen
        pos1 = pos2 + 1
        pos2 = InStr(pos1, txt, ",")
        If pos2 = 0 Then pos2 = txtlen + 1
        num_txt = Mid$(txt, pos1, pos2 - pos1)
        arr(i) = CInt(num_txt)
        i = i + 1
    Loop
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated