Decode ASCII

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lauclaw
    New Member
    • Apr 2010
    • 6

    Decode ASCII

    i used a code to decode a ASCII code:
    Code:
    textbox1.text=chr(textbox2.text)
    when i type 97 in textbox2, textbox1 show correct answer that is 'a'.
    But when i type 9797, is there any possible ways to get 'aa' in textbox1?
  • yarbrough40
    Contributor
    • Jun 2009
    • 320

    #2
    hmm well If that is all you want to do then a crude way of doing it is like this
    Code:
     
            Dim t1, t2 As String
            If TextBox2.Text.Length = 4 Then
                t1 = Chr(TextBox2.Text.Substring(0, 2))
                t2 = Chr(TextBox2.Text.Substring(2, 2))
            Else
                t1 = Chr(TextBox2.Text)
                t2 = ""
            End If
            TextBox1.Text = t1 & t2
    however it's not very practical because it assumes that the only two scenarios will be either a case of 1) two chars - both a two character ASCII, or 2) a single char with one or two ASCII characters.
    if you could explain more comprehensively what you are trying to do, we may be able to help with a better solution.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      just do a loop... for the length of the textbox.text... get the next character... make the ascii... add it to the output... continue loop

      Comment

      • lauclaw
        New Member
        • Apr 2010
        • 6

        #4
        Originally posted by yarbrough40
        hmm well If that is all you want to do then a crude way of doing it is like this
        Code:
         
                Dim t1, t2 As String
                If TextBox2.Text.Length = 4 Then
                    t1 = Chr(TextBox2.Text.Substring(0, 2))
                    t2 = Chr(TextBox2.Text.Substring(2, 2))
                Else
                    t1 = Chr(TextBox2.Text)
                    t2 = ""
                End If
                TextBox1.Text = t1 & t2
        however it's not very practical because it assumes that the only two scenarios will be either a case of 1) two chars - both a two character ASCII, or 2) a single char with one or two ASCII characters.
        if you could explain more comprehensively what you are trying to do, we may be able to help with a better solution.
        actually what i want to do is I try to parse a few information in my system into ASCII and put it into database to secure it. After that, i can redeem it into my system again and use it.

        Comment

        • lauclaw
          New Member
          • Apr 2010
          • 6

          #5
          Originally posted by lauclaw
          i used a code to decode a ASCII code:
          Code:
          textbox1.text=chr(textbox2.text)
          when i type 97 in textbox2, textbox1 show correct answer that is 'a'.
          But when i type 9797, is there any possible ways to get 'aa' in textbox1?
          thank you all and i found my way
          Code:
          Dim i As Integer = 0
                  Dim l As Integer = Me.TextBox2.Text.Length
                  Dim a As String = Nothing
                  While i < l
                      If Me.TextBox2.Text.Substring(i, 2) > 31 And Me.TextBox2.Text.Substring(i, 2) < 130 Then
                          a += Chr(TextBox2.Text.Substring(i, 2))
                          i += 2
                      Else
                          a += Chr(TextBox2.Text.Substring(i, 3))
                          i += 3
                      End If
                  End While
                  Me.TextBox3.Text = a

          Comment

          Working...