r/visualbasic • u/GRIFFIN-PETER • Jan 23 '16
DynamicNumbers
I only finished a third of the requirements. I need to make a findLowest function that returns the index of the lowest value of the arrayusing the code that I created. I also need to make a sort() procedure that repeateldy finds the lowest value in an array A, removes it and adds it to array T. When all the values of A have been moved, the elements of T are copied to A wth an assginment statement and a loop.. AddItem() and RemoveItem() is a hint. I only completed the part where it says to create an array of random numbers in a listbox. Here is what I finished so far:
Private Sub btnCreate_Click(sender As Object, e As EventArgs) Handles btnCreate.Click
Dim number(txtBox.Text)
Dim rand As New Random
For count As Integer = 0 To txtBox.Text - 1
RandomNumbers.Items.Add(count & vbTab & rand.Next(1, 99))
number(count) = RandomNumbers.Items(count)
Next count
End SubCan you guys tell me how to complete this program? I'm a beginner for visual basic programming.
6
Upvotes
1
u/PostalElf VB.Net Intermediate Jan 23 '16
Create a variable to hold the smallest value, and another to hold the index. Loop through your array, each time comparing the current item to the smallest value: is it smaller? Yes, store the value and index. No, move on.
At the end of the loop you will have both the value and the index.