Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27189

substring, index of, and array beginners help

$
0
0
Please help. I need to take a string separated by commas, and divide up the numbers to store into an array. I cant seem to figure out why it isn't working. I'm pretty sure the part where I store the numbers is correct. It's just how I divide them up that is incorrect. Any help would be appreciated.

Code:

define variables
        Dim usrInput(4) As Integer
        Dim x As Integer = 0
        Dim i As Integer = 0
        Dim y As Integer = 0
        Dim usrinput_ As String

        'simplify input
        usrinput_ = txtUserinput.Text
        'find comma and split numbers
        Do While x <= usrInput.GetUpperBound(0)
            y = usrinput_.IndexOf(",", i)
            If y = -1 Then y = usrinput_.Length

            usrInput(x) = CInt(txtUserinput.Text.Substring(i, y - i))
            i = y + 1
            x += 1
            If i = usrInput.GetUpperBound(0) Then
                ReDim Preserve usrInput(usrInput.GetUpperBound(0) + 1)
            End If

        Loop


Viewing all articles
Browse latest Browse all 27189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>