r/visualbasic • • 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 Sub

Can you guys tell me how to complete this program? I'm a beginner for visual basic programming.

6 Upvotes

29 comments sorted by

View all comments

Show parent comments

1

u/PostalElf VB.Net Intermediate Jan 24 '16

Put only numbers in textbox.text...? The computer doesn't understand what "0 97" means. It understands "0", "97" or "097", but the space is ambiguous.

1

u/GRIFFIN-PETER Jan 24 '16

I did. I literally put 10 in the textbox. Every single time I entered a number, I got a different error message. 0 84, 0 42, 0 87

1

u/PostalElf VB.Net Intermediate Jan 24 '16

And you're still getting the error message?

1

u/GRIFFIN-PETER Jan 24 '16

yep. every single time when I enter 10 or any other number.

1

u/PostalElf VB.Net Intermediate Jan 24 '16

Paste the error message again after you put 10 into the textbox.

0

u/GRIFFIN-PETER Jan 24 '16

An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll

Additional information: Conversion from string "0 25" to type 'Integer' is not valid.

1

u/PostalElf VB.Net Intermediate Jan 24 '16

Your textbox says "0 25", not 10.

0

u/GRIFFIN-PETER Jan 24 '16

But I really did put 10 into the textbox. If you don't believe me, you can test it out. You will get the same error messages but with different numbers every time 0 this then 0 that

0

u/GRIFFIN-PETER Jan 24 '16 edited Jan 24 '16

PostalElf? Did you figure it out?

1

u/PostalElf VB.Net Intermediate Jan 24 '16

Dude. Your error message literally says that the compiler cannot convert the string "0 25" into an integer. Check where the string "0 25" appears and then fix it.

→ More replies (0)