Results 1 to 14 of 14

Thread: Array already dimensioned? AHHHHH!

  1. #1

    Thread Starter
    Member cramtheman's Avatar
    Join Date
    Dec 2000
    Posts
    43

    Exclamation

    Why whenever I want to ReDim Preserve an array it says the array is already dimensioned. Does this mean I cant redim?

    Thanks
    cram
    [email protected]
    _ _ _ _ _ _ _ _ _ _ _ _ _ _
    Things to Ponder

    |Man who stands on toilet,
    Is high On pot|
    |Baseball Wrong,
    Man with four balls cannot walk|

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    It sounds like you are trying to Redimension an array that was not declared dynamically, for example

    You can't redimension an array declared like this...

    Code:
    Dim sArray(1 to 10)
    This is the proper way to declare an array dynamically (if you want to change it's dimensions later using the Redim statment)....

    Code:
    Dim sArray()
    If you still can't get it to work, post the code.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3

    Thread Starter
    Member cramtheman's Avatar
    Join Date
    Dec 2000
    Posts
    43
    Well if I make it dynamic it always goes subscript out of range for this:

    For i = 0 To UBound(strPuzzle)

    Next i



    Thanks
    cram
    [email protected]
    _ _ _ _ _ _ _ _ _ _ _ _ _ _
    Things to Ponder

    |Man who stands on toilet,
    Is high On pot|
    |Baseball Wrong,
    Man with four balls cannot walk|

  4. #4
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987

    LBound

    Try this...

    Code:
    For i = LBound(strPuzzle) to Ubound(strPuzzle)
    
      ' your code
    
    next i
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  5. #5

    Thread Starter
    Member cramtheman's Avatar
    Join Date
    Dec 2000
    Posts
    43
    It STILL gives me subscript out of range, can anyone tell me why?

    Thanks
    cram
    [email protected]
    _ _ _ _ _ _ _ _ _ _ _ _ _ _
    Things to Ponder

    |Man who stands on toilet,
    Is high On pot|
    |Baseball Wrong,
    Man with four balls cannot walk|

  6. #6
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Post the code where you are receiving the error.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  7. #7

    Thread Starter
    Member cramtheman's Avatar
    Join Date
    Dec 2000
    Posts
    43
    Well its much longer than this but Ill give you the part that I need

    Code:
    Private Sub cmdNew_Click()
    Dim intRepeat As Integer
    Dim i As Integer
    
    For i = LBound(strPuzzle) To UBound(strPuzzle)
    intRandom1 = Int((10 - 1 + 1) * Rnd + 1)
    If strPuzzle(i) <> strWord Then
    Exit For
    End If
    Next i
    
    If intRandom1 = 1 Then
        lbl1.Caption = "h"
        lbl2.Caption = "a"
        lbl3.Caption = "p"
        lbl4.Caption = "p"
        lbl5.Caption = "y"
        lblSubject.Caption = "Emotion"
        strWord = "happy"
    ElseIf intRandom1 = 2 Then
        lbl1.Caption = "t"
        lbl2.Caption = "e"
        lbl3.Caption = "d"
        lbl4.Caption = "d"
        lbl5.Caption = "y"
        lblSubject.Caption = "Thing"
        strWord = "teddy"
    ElseIf intRandom1 = 3 Then
        lbl1.Caption = "b"
        lbl2.Caption = "l"
        lbl3.Caption = "i"
        lbl4.Caption = "m"
        lbl5.Caption = "p"
        lblSubject.Caption = "Thing"
        strWord = "blimp"
    ElseIf intRandom1 = 4 Then
        lbl1.Caption = "l"
        lbl2.Caption = "e"
        lbl3.Caption = "a"
        lbl4.Caption = "f"
        lbl5.Caption = "s"
        lblSubject.Caption = "Sports"
        strWord = "leafs"
    ElseIf intRandom1 = 5 Then
        lbl1.Caption = "s"
        lbl2.Caption = "m"
        lbl3.Caption = "a"
        lbl4.Caption = "r"
        lbl5.Caption = "t"
        lblSubject.Caption = "Adjective"
        strWord = "smart"
    ElseIf intRandom1 = 6 Then
        lbl1.Caption = "s"
        lbl2.Caption = "t"
        lbl3.Caption = "a"
        lbl4.Caption = "m"
        lbl5.Caption = "p"
        lblSubject.Caption = "Thing"
        strWord = "stamp"
    ElseIf intRandom1 = 7 Then
        lbl1.Caption = "h"
        lbl2.Caption = "o"
        lbl3.Caption = "o"
        lbl4.Caption = "p"
        lbl5.Caption = "s"
        lblSubject.Caption = "Sports"
        strWord = "hoops"
    ElseIf intRandom1 = 8 Then
        lbl1.Caption = "c"
        lbl2.Caption = "h"
        lbl3.Caption = "a"
        lbl4.Caption = "i"
        lbl5.Caption = "r"
        lblSubject.Caption = "Thing"
        strWord = "chair"
    ElseIf intRandom1 = 9 Then
        lbl1.Caption = "p"
        lbl2.Caption = "a"
        lbl3.Caption = "r"
        lbl4.Caption = "i"
        lbl5.Caption = "s"
        lblSubject.Caption = "Place"
        strWord = "paris"
    ElseIf intRandom1 = 10 Then
        lbl1.Caption = "p"
        lbl2.Caption = "i"
        lbl3.Caption = "l"
        lbl4.Caption = "o"
        lbl5.Caption = "t"
        lblSubject.Caption = "Job"
        strWord = "pilot"
    End If
    
    intRepeat = UBound(strPuzzle) + 1
    ReDim Preserve strPuzzle(intRepeat)
    strPuzzle(intRepeat) = strWord
    End Sub
    and in General I declare
    Code:
    Dim strPuzzle() as string
    please help,
    Thanks,
    cram
    [email protected]
    _ _ _ _ _ _ _ _ _ _ _ _ _ _
    Things to Ponder

    |Man who stands on toilet,
    Is high On pot|
    |Baseball Wrong,
    Man with four balls cannot walk|

  8. #8

    Thread Starter
    Member cramtheman's Avatar
    Join Date
    Dec 2000
    Posts
    43
    Now that you have my code, can you tell me how I wouldnt have two puzzles come up twice, thanks, this is really what ive been striving at.

    thanks
    cram
    [email protected]
    _ _ _ _ _ _ _ _ _ _ _ _ _ _
    Things to Ponder

    |Man who stands on toilet,
    Is high On pot|
    |Baseball Wrong,
    Man with four balls cannot walk|

  9. #9
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Sorry I'm not quite sure what you are trying to accomplish with your code, could you give a description and what do you mean by not having the puzzle come up twice.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  10. #10
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>


    For i = LBound(strPuzzle) To UBound(strPuzzle)

    you are having a problem reading which is probably a result of how you are loading the array.

    What code are you using to load the array?
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  11. #11

    Thread Starter
    Member cramtheman's Avatar
    Join Date
    Dec 2000
    Posts
    43
    Well Im lodaing the array by typing dim strPuzzle() in the general procedures. And what I mean by not having a puzzle come twice, is that each intRandom1 number is a different puzzle.For example: intRandom1 = 1 is happy and
    intRandom1 = 5 is smart. I would like it so that each puzzle only comes up once. So I think I have to keep it looping the randomizer until it reaches a number it hasnt done before. Or something like that.

    Thanks a bunch,
    cram
    [email protected]
    _ _ _ _ _ _ _ _ _ _ _ _ _ _
    Things to Ponder

    |Man who stands on toilet,
    Is high On pot|
    |Baseball Wrong,
    Man with four balls cannot walk|

  12. #12
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Here's a thought, why not everytime a puzzle is choosen, dump it into an invisible list box, and the next time another puzzle is choosen, compare it to the listbox, if it exists in the list, grab the next puzzle. Just a thought

  13. #13

    Thread Starter
    Member cramtheman's Avatar
    Join Date
    Dec 2000
    Posts
    43
    Would you or someone be able to show me the code of how I would compare it to the listbox to see if its there?I think I will put this into a new thread

    Thanks

    [Edited by cramtheman on 12-31-2000 at 04:18 PM]
    cram
    [email protected]
    _ _ _ _ _ _ _ _ _ _ _ _ _ _
    Things to Ponder

    |Man who stands on toilet,
    Is high On pot|
    |Baseball Wrong,
    Man with four balls cannot walk|

  14. #14
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    I didn't want to completely rewrite the code for you so I know this is not complete but it should give you an idea of how to use the puzzles without repeating any of them.

    Code:
    Private strPuzzle(1 To 10)
    
    Private Sub cmdNew_Click()
     Static iCurrent As Integer
     Dim sStr As String
     
     If Not iCurrent = 10 Then
        
        iCurrent = iCurrent + 1
        sStr = strPuzzle(iCurrent) ' get current element in array
        
        lbl1.Caption = Mid(sStr, 1, 1)
        lbl2.Caption = Mid(sStr, 2, 1)
        lbl3.Caption = Mid(sStr, 3, 1)
        lbl4.Caption = Mid(sStr, 4, 1)
        lbl5.Caption = Mid(sStr, 5, 1)
        
    Else
    
        MsgBox "ALL PUZZLES HAVE BEEN DISPLAYED"
        
    End If
        
     
    End Sub
    
    Private Sub Form_Load()
     Dim iCt As Integer
     
     'assign strings to the array
     strPuzzle(1) = "happy"
     strPuzzle(2) = "teddy"
     strPuzzle(3) = "blimp"
     strPuzzle(4) = "leafs"
     strPuzzle(5) = "smart"
     strPuzzle(6) = "stamp"
     strPuzzle(7) = "hoops"
     strPuzzle(8) = "chair"
     strPuzzle(9) = "paris"
     strPuzzle(10) = "pilot"
     
     'shuffle the elements in the array around
     ShuffleArray strPuzzle, 100
     
     'display the results
     For iCt = 1 To 10
        
        Debug.Print iCt & " " & strPuzzle(iCt)
        
     Next iCt
     
    End Sub
    
    Private Sub ShuffleArray(ByRef arr(), ByVal iShuffleTimes As Integer)
    Dim iCt As Integer
    Dim iRandElem As Integer
    Dim vTemp
    
    'assure we don't get the same set of random numbers
    Randomize
    
    For iCt = 1 To iShuffleTimes
        
        iRandElem = (Rnd * (UBound(arr) - LBound(arr))) + LBound(arr) ' get an element within the bounds of the array randomly
        vTemp = arr(LBound(arr)) ' assign the value of the first element in the array to the temporary variable
        arr(LBound(arr)) = arr(iRandElem) ' shuffle the values
        arr(iRandElem) = vTemp
        
    Next iCt
    
    End Sub
    It shouldn't be that hard to apply this to your code, if you need anymore help don't hesitate to ask.



    [Edited by YoungBuck on 01-04-2001 at 12:11 PM]
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

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