ASCII Class Excercise

Class Exercise: ASCII

Create a program to find the ASCII codes of characters and vice versa.

 

  1. Begin by designing the form.
  2. Use the names txtChar, txtCode, cmdConvertToCode, cmdConvertToChar, cmdDone for the controls on the form.
  3. Add code to cmdDone.
  4. Add code to set the left button as default when txtChar receives the focus.
  5. Add code to set the right button as default when txtCode receives the focus.
  6. Determine what the error checking needs are on both sides.
  7. Add code for cmdConvertToCode and test your program.
  8. On your own, add code for cmdConvertToChar.
  9. Try your program out to make sure it works.
  10. Raise your hand and ask your teacher to grade your assignment on screen.

ASCII Code
Private Sub cmdDone_Click()
    ' close program
    Unload frmMain
End Sub

Private Sub txtChar_GotFocus()
‘ set left button as default
cmdConvertToCode.Default = True
End Sub

Private Sub txtCode_GotFocus()
‘ set right button as default
cmdConvertToChar.Default = True
End Sub

Private Sub cmdConvertToCode_Click()
‘ dimension
Dim strChar As String
‘ initialize
strChar = txtChar.Text
‘ error checking
If Len(strChar) <> 1 Then
MsgBox “You must enter exactly 1 character.”
Else
‘ display code
MsgBox “The character ‘” & strChar & “‘ is ASCII code ” & _
CStr(Asc(strChar)) & “.”
End If
‘ clear box
txtChar.Text = “”
End Sub

Assignment

The Code Cracker assignment is due in one week.