Results 1 to 8 of 8

Thread: VB 6 Array Problems

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    3

    VB 6 Array Problems

    Hello,

    I'm new to these boards so if I'm doing anything wrong here please let me know.

    I'm currently trying to produce a word game in VB 6, very much like Word Challenge on Facebook for those familiar. ATM I'm making a test program which loads a dictionary file into a 2D array so (4, 1) is 4 letter word, (5, 1) 5 letter word and so on. Code below

    Code:
    Option Explicit
    
    Dim WordDictionary As String
    Dim DictionaryWord As String
    Dim Words() As String
    Dim Index(3 To 6) As Integer
    Dim WordLength As Integer
    Dim ArrayUpper As Integer
    Dim ArrayLower As Integer
    Dim ArrayRange As Integer
    
    
    Private Sub Form_Load()
    WordDictionary = App.Path & "\WordDictionaryFiles\Dashed.txt"
    End Sub
    
    Private Sub cmdTest_Click()
    Index(3) = 1
    Index(4) = 1
    Index(5) = 1
    Index(6) = 1
    
    Open WordDictionary For Input As #1
        Do While Not EOF(1)
            Line Input #1, DictionaryWord
            WordLength = Len(DictionaryWord)
            ReDim Preserve Words(3 To 6, 1 To Index(WordLength)) As String
            Words(WordLength, Index(WordLength)) = DictionaryWord
            Index(WordLength) = Index(WordLength) + 1
        Loop
    Close #1
    From my tests this should work (setting watches on the different variables as filling in a grid as it loads each cell of the array). However from here I made a test in order to return the 3 to 6 letter words each individually on click of each command button. This seems to work fine for the 3 letter words but 4, 5 and 6 are all presenting issues, printing just one word and a series of blank lines. Code as follows,

    Code:
    Private Sub cmd3Letters_Click()
    ArrayLower = LBound(Words, 2)
    ArrayUpper = UBound(Words, 2)
    
    For ArrayRange = ArrayLower To ArrayUpper
        Form1.Print Words(3, ArrayRange)
    Next ArrayRange
    
    End Sub
    
    Private Sub cmd4Letters_Click()
    
    ArrayLower = LBound(Words, 2)
    ArrayUpper = UBound(Words, 2)
    
    For ArrayRange = ArrayLower To ArrayUpper
        Form1.Print Words(4, ArrayRange)
    Next ArrayRange
    
    End Sub
    
    Private Sub cmd5Letters_Click()
    
    ArrayLower = LBound(Words, 2)
    ArrayUpper = UBound(Words, 2)
    
    For ArrayRange = ArrayLower To ArrayUpper
        Form1.Print Words(5, ArrayRange)
    Next ArrayRange
    
    End Sub
    
    Private Sub cmd6Letters_Click()
    
    ArrayLower = LBound(Words, 2)
    ArrayUpper = UBound(Words, 2)
    
    For ArrayRange = ArrayLower To ArrayUpper
        Form1.Print Words(6, ArrayRange)
    Next ArrayRange
    
    End Sub
    Atm I'm pretty stumped and I've been thinking on this for several days, I have a suspicion that I need to use a variable (jagged) array, but I am not aware of how to do this. I've attatched a zip with the files so you can view the program in it's entirety.

    Can anyone help me out here?

    Thank you in advance,

    Danimono
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width