Computing.Net > Forums > Programming > VB Arrays

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VB Arrays

Reply to Message Icon

Name: ebrown64
Date: June 13, 2007 at 17:15:30 Pacific
OS: Windows Xp
CPU/Ram: Intel
Product: Dell Optiplex 745
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Shr0Om
Date: June 14, 2007 at 05:03:02 Pacific
Reply:

What do you got so far?


0

Response Number 2
Name: Sci-Guy
Date: June 14, 2007 at 15:29:32 Pacific
Reply:

"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.


0

Response Number 3
Name: ebrown64
Date: June 16, 2007 at 15:54:12 Pacific
Reply:

This is what I have so far.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Randomize()

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
Next

End 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 Then

For 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) = tmp

Next

Else


End If

End Sub
Private Sub List1_Scroll()

'if List2 is scrolled, keep List1 in sync
List2.TopIndex = List1.TopIndex

End Sub


Private Sub List2_Scroll()

'if List1 is scrolled, keep List2 in sync
List1.TopIndex = List2.TopIndex

End 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


0

Response Number 4
Name: SmittyZ3M
Date: June 17, 2007 at 12:13:47 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Batch - Time/Date calcula... Renaming Files



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VB Arrays

vb array using a text file www.computing.net/answers/programming/vb-array-using-a-text-file/5539.html

VB Array Problem www.computing.net/answers/programming/vb-array-problem/6020.html

VB Array Trouble www.computing.net/answers/programming/vb-array-trouble/11756.html