By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,259 Members | 1,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,259 IT Pros & Developers. It's quick & easy.

Decode ASCII

P: 6
i used a code to decode a ASCII code:
Expand|Select|Wrap|Line Numbers
  1. 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?
Apr 18 '10 #1
Share this Question
Share on Google+
4 Replies


yarbrough40
100+
P: 320
hmm well If that is all you want to do then a crude way of doing it is like this
Expand|Select|Wrap|Line Numbers
  1.  
  2.         Dim t1, t2 As String
  3.         If TextBox2.Text.Length = 4 Then
  4.             t1 = Chr(TextBox2.Text.Substring(0, 2))
  5.             t2 = Chr(TextBox2.Text.Substring(2, 2))
  6.         Else
  7.             t1 = Chr(TextBox2.Text)
  8.             t2 = ""
  9.         End If
  10.         TextBox1.Text = t1 & t2
  11.  
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.
Apr 18 '10 #2

tlhintoq
Expert 2.5K+
P: 3,525
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
Apr 18 '10 #3

P: 6
@yarbrough40
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.
Apr 18 '10 #4

P: 6
@lauclaw
thank you all and i found my way
Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer = 0
  2.         Dim l As Integer = Me.TextBox2.Text.Length
  3.         Dim a As String = Nothing
  4.         While i < l
  5.             If Me.TextBox2.Text.Substring(i, 2) > 31 And Me.TextBox2.Text.Substring(i, 2) < 130 Then
  6.                 a += Chr(TextBox2.Text.Substring(i, 2))
  7.                 i += 2
  8.             Else
  9.                 a += Chr(TextBox2.Text.Substring(i, 3))
  10.                 i += 3
  11.             End If
  12.         End While
  13.         Me.TextBox3.Text = a
Apr 18 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.