0

I'm new to Visual Studio.I tried to write a simple program in Visual Basic that takes a 13-digit number from a text box and writes its digits to an array.Then it writes the second member of the array (second digit of the number) to another text box, but it doesn't work. Here's the code:

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim array(12) As Integer
        Dim index As Integer = 11
        Dim code As Long = TextBox1.Text
        Do While index >= 0
            array(index) = code Mod 10
            code /= 10
            index -= 1
        Loop
        TextBox2.Text = array(1)
    End Sub
End Class

Can you tell me what's wrong?

2
  • 1
    Forgotten VB, but isn't it: code = code / 10 and index = index - 1. Also I would not use "array" as name. Commented Mar 8, 2013 at 8:34
  • 1
    Option Strict Off, this is the biggest error. Commented Mar 8, 2013 at 11:25

1 Answer 1

1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim array(12) As Integer
    Dim index As Integer = 11
    Dim code As Char() = TextBox1.Text.ToCharArray()

    For i As Integer = 0 To code.Count - 1
        array(i) = Integer.Parse(code(i))
    Next

    TextBox2.Text = array(1)
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your help.I used to make programs with C++ and didn't know that in Visual Basic I can easily convert digits in char to integer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.