I need to create an array of decimals by getting input from the user. I know how to create one of random numbers but do not know how to get the input from a user through a text box to a list box.

6 Years
Discussion Span
Last Post by Reverend Jim

Do you mean a string like "......"? Or do you mean a series of decimal numbers? I presume you know how to create a textbox control. Let's say you have one namex txtDecimals. You can refer to the text in the box by txtDecimals.Text. For example, to copy it to a local variable you do

Dim mystring As String

mystring = txtDecimals.Text

If, however, the user has entered the number of decimals they want then you get that number by converting the text in the control to an integer value via CInt as follows:

Dim numdecimals as Integer

numdecimals = CInt(txtDecimals.Text)

Keep in mind that if the user has entered a string that cannot be converted to a number you will get an error. You can account for this by using IsNumeric to check the string before converting, or by doing the conversion in a Try/Catch block.

If the user has entered text like "12 5123 17 947 42" then you have to parse the text using Split and converting each item in the resulting array.

Edited by Reverend Jim: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.