VB.Net help. Code included.

Xenarchy

Limp Gawd
Joined
Jun 7, 2001
Messages
297
I decided to teach myself vb.net. I decided to make a stupid program just to get used to the language. I'm taking a string of character codes that I want to turn back into their respectable aplha/numeric state. Now, I can go from string to code easy, but going back again I'm running into errors. I'm sure it's my logic. Anyway here is my code please help if you can.
Code:
  ' Declare Variables Used In Function
        Dim textoutput As String = txt_output.Text
        Dim jletter As String
        Dim j As Integer = 0
        Dim jlength As Integer = Len(textoutput)
        ' Clear Input Box
        If txt_input.Text <> "" Then
            txt_input.Text = ""
        End If
        ' Loop Decode Code to Text
        For j = 0 To jlength
            If ((textoutput.Substring(j) <> " ") And (textoutput.Substring(j) <> ",")) Then
                If j = jlength Then
                    jletter = textoutput.Substring(j)
                    txt_input.Text = txt_input.Text & Chr(Val(jletter))
                ElseIf textoutput.Substring(j + 1) = "" Then
                    jletter = textoutput.Substring(j)
                    txt_input.Text = txt_input.Text & Chr(Val(jletter))
                ElseIf textoutput.Substring(j + 1) = "," Then
                    jletter = textoutput.Substring(j)
                    txt_input.Text = txt_input.Text & Chr(Val(jletter))
                ElseIf textoutput.Substring(j + 2) = "," Then
                    jletter = textoutput.Substring(j)
                    j = 1 + j
                    jletter = jletter & textoutput.Substring(j)
                    txt_input.Text = txt_input.Text & Chr(Val(jletter))
                ElseIf textoutput.Substring(j + 3) = "," Then
                    jletter = jletter & textoutput.Substring(j)
                    j = 1 + j
                    jletter = jletter & textoutput.Substring(j)
                    j = 1 + j
                    jletter = jletter & textoutput.Substring(j)
                    txt_input.Text = txt_input.Text & Chr(Val(jletter))
                End If
            End If
        Next j

Also any weblinks with tutorials on string manipulation and arrays would be nice. Or any other links would be cool. My next project involves useing a timer. I'll probly post again. :D

Thanks for the help.
 
I didn't spend too much time taking a look at your code, but the for j= 0 to jLength looks pretty suspicious to me.

First of all, if you have the string "hello" the length will be 5. You can only do substring for positions 0 to 4 (remember zero based everything). The second problem is the j + 1, 2 or 3 code too. Once again, reading past the end of the string.

Text manipulation is pretty easy and straight forward. Just look up System.String and System.Text.StringBuilder in the MSDN help.
 
Back
Top