Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am new to Vb and trying to create an array to hold 10000 numbers. I must use a random number generator to load the array with alues. Display the first 100 values unsorted, sort the array, and then display the first 100 values sorted. Ask the user for a number, search for the nuber in the array. If the number is not found, display an error message, and if the nuber is found display the location (index) in the array.
I would appreciate any help that can be offered.

"What do you got so far?"
Yes, before we can help you with your homework, we need to see that you've made some effort on your own.
Please let us know if you found someone's advice to be helpful.

This is what I have so far.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadRandomize()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnt As Long
Dim arrayGroup As Array
arrayGroup(0).groupNumberString = (1 - 1000)
arrayGroup(1).groupNumberString = (1001 - 2000)
arrayGroup(2).groupNumberString = (2001 - 3000)
arrayGroup(3).groupNumberString = (3001 - 4000)
arrayGroup(4).groupNumberString = (4001 - 5000)
arrayGroup(5).groupNumberString = (5001 - 6000)
arrayGroup(6).groupNumberString = (6001 - 7000)
arrayGroup(7).groupNumberString = (7001 - 8000)
arrayGroup(8).groupNumberString = (8001 - 9000)
arrayGroup(9).groupNumberString = (9001 - 10000)
List1.ClearSelected()
List2.ClearSelected()For cnt = 1 To UBound(arrayGroup)
arrayGroup(cnt) = cnt
NextEnd Sub
Private Sub RandomizeArray(ByVal ArrayIn As Object)Dim cnt As Long
Dim RandomIndex As Long
Dim tmp As Object'only if an array was passed
If VarType(ArrayIn) >= vbArray ThenFor cnt = UBound(ArrayIn) To LBound(ArrayIn) Step -1
RandomIndex = Int((cnt - LBound(ArrayIn) + 1) * _
Rnd() + LBound(ArrayIn))tmp = ArrayIn(RandomIndex)
ArrayIn(RandomIndex) = ArrayIn(cnt)
ArrayIn(cnt) = tmpNext
Else
End IfEnd Sub
Private Sub List1_Scroll()'if List2 is scrolled, keep List1 in sync
List2.TopIndex = List1.TopIndexEnd Sub
Private Sub List2_Scroll()'if List1 is scrolled, keep List2 in sync
List1.TopIndex = List2.TopIndexEnd Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
' Exit the program.Me.Close()
End Sub
End Class

Just a word of advice once you get closer to solving your problem...One of the requirements is to be able to search for a value contained in the array. Once your array is sorted, I think you should Google "binary search". A binary search is a fairly effifient algorithm for searching arrays and vectors. The binary search has one precondition; the contents of the array must be sorted.
The binary search basically works by taking your search criteria, and dividing the array/vector search in 1/2 each time a search iteration occurs. The results of the search iteration dictate which part of the array is no longer needed to search in. This is why the array must be sorted first.

![]() |
Batch - Time/Date calcula...
|
Renaming Files
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |