Computer Science Canada

ASCII Converter

Author:  peterggmss [ Thu Dec 14, 2006 1:52 pm ]
Post subject:  ASCII Converter

When I enter something like "you suck" i get 121 for y but also 121 for s. I have attached an EXE so that you can try it.

code:
    Dim UserInput, Action
    Dim Length, LengthDone
    Dim Output
    Dim NewInput As String
   
Private Sub cmdConvert_Click()
   
    'What should we do with the input?
    If optEncode.Enabled = False And optDecode.Enabled = False Then
        MsgBox ("Select an action to perform")
        Exit Sub
    End If
    If optEncode.Enabled = True Then
        Action = Encode
    End If
    If optDecode.Enabled = True Then
        Action = Decode
    End If
   
    'What is the input?
    UserInput = txtInput.Text

    'How long is the input?
    Length = Len(UserInput)
   
    'We should tell the user what they gave us
    lblInput.Caption = UserInput
   
    txtInput.Text = ""
    LengthDone = 1
    'Calculate the ASCII Values
    If Action = Encode Then
        'For Length = 1 To Length COMMENTED OUT - WILL NOT EXECUTE
        Do Until LengthDone = Length
            Output = Asc(Left(UserInput, LengthDone)) '+ " "
            NewInput = NewInput + Str(Output) '+ " "
            LengthDone = LengthDone + 1
        'Next COMMENTED OUT - WILL NOT EXECUTE
        Loop
    End If
               
    'Calculate the text values
    If Action = Decode Then
        Do Until LengthDone = Length
            Output = Chr(Left(UserInput, LengthDone))
            NewInput = NewInput + Output
            LengthDone = LengthDone + 1
        Loop
    End If
       
    'Lets show them the output
    txtInput.Text = NewInput
                   
   'lblInput.Caption = txtInput.Text
   'txtInput.Text = Asc(txtInput.Text)

End Sub

Author:  Silent Avenger [ Thu Dec 14, 2006 7:18 pm ]
Post subject: 

Are you trying to get each ASCII code for each letter of what the user typed in?

Author:  cool dude [ Thu Dec 14, 2006 7:35 pm ]
Post subject: 

i'm not exactly sure of what your trying to do and i am not going to download the exe unless you provide the actual form. (i don't like exe)
however this might help you. basically you press any key and on your form it will show you the ascii value of that key.

code:

Private Sub Form_KeyPress(KeyAscii As Integer)
    Print KeyAscii
End Sub


: