Game using Control arrays

I have a program that works on the principle of a childs game, the object of the game is to move the cells until all the numbers appear on the screen like this
1 2 3
4 5 6
7 8 Empty(mtcell)
I have enclosed the code i have already done, what I need is a way of starting the game so that every new game has a random starting position for the numbers could this be done by using a control array and how please.
I'm using VB5
Option Explicit
Dim x as Integer
Dim Temp
private Sub cmd1_click( )
If ((cmd1.Top = mtcell.Top) And (ABS(mtcell.Left - cmd1.Left) = 1680)) Then
      Temp = mtcell.Left
      mtcell.left = cmd1.Left
      cmd1.Left = Temp
End If
If ((cmd1.Left = mtcell.Left) And (ABS(cmd1.Top - mtcell.Top) = 1440)) Then
      Temp = cmd1.Top
      cmd1.Top = mtcell.Top
      mtcell.Top = Temp
End If
End Sub

private Sub cmd2_click( )
If ((cmd2.Top = mtcell.Top) And (ABS(mtcell.Left - cmd2.Left) = 1680)) Then
      Temp = mtcell.Left
      mtcell.left = cmd2.Left
      cmd2.Left = Temp
End If
If ((cmd2.Left = mtcell.Left) And (ABS(cmd2.Top - mtcell.Top) = 1440)) Then
      Temp = cmd2.Top
      cmd2.Top = mtcell.Top
      mtcell.Top = Temp
End If
End Sub

private Sub cmd3_click( )
If ((cmd3.Top = mtcell.Top) And (ABS(mtcell.Left - cmd3.Left) = 1680)) Then
      Temp = mtcell.Left
      mtcell.left = cmd3.Left
      cmd3.Left = Temp
End If
If ((cmd3.Left = mtcell.Left) And (ABS(cmd3.Top - mtcell.Top) = 1440)) Then
      Temp = cmd3.Top
      cmd3.Top = mtcell.Top
      mtcell.Top = Temp
End If
End Sub

private Sub cmd4_click( )
If ((cmd4.Top = mtcell.Top) And (ABS(mtcell.Left - cmd4.Left) = 1680)) Then
      Temp = mtcell.Left
      mtcell.left = cmd4.Left
      cmd4.Left = Temp
End If
If ((cmd4.Left = mtcell.Left) And (ABS(cmd4.Top - mtcell.Top) = 1440)) Then
      Temp = cmd4.Top
      cmd4.Top = mtcell.Top
      mtcell.Top = Temp
End If
End Sub

private Sub cmd5_click( )
If ((cmd5.Top = mtcell.Top) And (ABS(mtcell.Left - cmd5.Left) = 1680)) Then
      Temp = mtcell.Left
      mtcell.left = cmd5.Left
      cmd5.Left = Temp
End If
If ((cmd5.Left = mtcell.Left) And (ABS(cmd5.Top - mtcell.Top) = 1440)) Then
      Temp = cmd5.Top
      cmd5.Top = mtcell.Top
      mtcell.Top = Temp
End If
End Sub

private Sub cmd6_click( )
If ((cmd6.Top = mtcell.Top) And (ABS(mtcell.Left - cmd6.Left) = 1680)) Then
      Temp = mtcell.Left
      mtcell.left = cmd6.Left
      cmd6.Left = Temp
End If
If ((cmd6.Left = mtcell.Left) And (ABS(cmd6.Top - mtcell.Top) = 1440)) Then
      Temp = cmd6.Top
      cmd6.Top = mtcell.Top
      mtcell.Top = Temp
End If
End Sub

private Sub cmd7_click( )
If ((cmd7.Top = mtcell.Top) And (ABS(mtcell.Left - cmd7.Left) = 1680)) Then
      Temp = mtcell.Left
      mtcell.left = cmd7.Left
      cmd7.Left = Temp
End If
If ((cmd7.Left = mtcell.Left) And (ABS(cmd7.Top - mtcell.Top) = 1440)) Then
      Temp = cmd7.Top
      cmd7.Top = mtcell.Top
      mtcell.Top = Temp
End If
End Sub

private Sub cmd8_click( )
If ((cmd8.Top = mtcell.Top) And (ABS(mtcell.Left - cmd8.Left) = 1680)) Then
      Temp = mtcell.Left
      mtcell.left = cmd8.Left
      cmd8.Left = Temp
End If
If ((cmd8.Left = mtcell.Left) And (ABS(cmd8.Top - mtcell.Top) = 1440)) Then
      Temp = cmd8.Top
      cmd8.Top = mtcell.Top
      mtcell.Top = Temp
End If
End Sub








dypseyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mcriderCommented:
You can use Randomize and RND to generate random numbers and incorporate them into your program.  For example:

Dim MyValue
Randomize      ' Initialize random-number generator.

MyValue = Int((6 * Rnd) + 1)      ' Generate random value between 1 and 6.


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Erick37Commented:
0
dypseyAuthor Commented:
Do I put this code in General Declarations
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

KDivadCommented:
Richard?

If so, "John" has posted code for this game on the other board. Apparently it works because at the end of the message he says something like:

Well, I gotta go. This game is really addictive! Thanks!

If not, then everybody just ignore me...
0
Erick37Commented:
I have some example source code, if you need more help.
0
dypseyAuthor Commented:
Eric37 can you let me have some examples please
E-Mail RRichie@aol.com
0
Erick37Commented:
I could post the code here.
Sample program based on your code which uses a control array, and starts up in random order.

But first please reject the currently proposed answer, unless you think it is a good answer. :-)
0
mcriderCommented:
Here is a subroutine that you can call when you're ready to populate the buttons with random numbers.  It uses the randomize function I gave you...


Cheers!

THE CODE:

Sub LoadButtons()
    Dim RndIndex(1 To 8) As Integer
    Dim MyValue As Integer
    Dim iVal As Integer
    Dim jVal As Integer
    Dim Vswitch As Boolean
    Randomize ' Initialize random-number generator.
    For iVal = 1 To 8
        MyValue = Int((8 * Rnd) + 1) ' Generate random value between 1 and 8.
        Do
            Vswitch = False
            For jVal = 1 To iVal
                If RndIndex(jVal) = MyValue Then Vswitch = True
            Next jVal
            If Vswitch = False Then Exit Do
            MyValue = MyValue + 1
            If MyValue = 9 Then MyValue = 1
        Loop
        RndIndex(iVal) = MyValue
    Next iVal
    Cmd1.Caption = CStr(RndIndex(1))
    Cmd2.Caption = CStr(RndIndex(2))
    Cmd3.Caption = CStr(RndIndex(3))
    Cmd4.Caption = CStr(RndIndex(4))
    Cmd5.Caption = CStr(RndIndex(5))
    Cmd6.Caption = CStr(RndIndex(6))
    Cmd7.Caption = CStr(RndIndex(7))
    Cmd8.Caption = CStr(RndIndex(8))
End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.