1.

Solve : VB6 - Mix Up Array?

Answer»

Hello,

I need VB6 (not .NET) code to randomly mix up an array. Thanks in advance!

*Fleexy*module:

Code: [Select]Option Explicit

Public Sub Swap(ByRef valueA As Variant, ByRef ValueB As Variant)
Dim Temp As Variant
Temp = valueA
valueA = ValueB
ValueB = Temp



End Sub

Public Sub Shuffle(ArrayShuffle() As Variant)
Dim I As Long, RandomIndex As Long
Randomize Timer
'loop through the array. swap each item with a randomly chosen index
For I = LBound(ArrayShuffle) To UBound(ArrayShuffle)
RandomIndex = INT(LBound(ArrayShuffle) + (Rnd * (UBound(ArrayShuffle) - LBound(ArrayShuffle))))
Swap ArrayShuffle(I), ArrayShuffle(RandomIndex)
Next I

End Sub


I SUPPOSE you could make equivalent functions if you need a sort routine for a specific type.Thanks for your REPLY, but NEVER mind, I got it. Silly RND returning a number less than 1.HI! I'm beginner.. I have visual Basic 6.0 I want study visual basic. when I vb first coming some form. what is the us of this form? then how can I start to create my own programme?I would read the help first.



Discussion

No Comment Found