Introduction
Create an application that uses the ASCII character set to encode text into
a series of numbers or decode the numbers back into text.
Algorithm
The following algorithms may help you create the two main subroutines, which
should be called from the Go button based on the selected option.
Algorithm: EncodeText subroutine |
Dimension and initialize variables ' loop through each letter of input string For intPosition = 1 To length of input string ' take 1 character at a time, using Mid() function strChar = next character from middle of input string ' determine ASCII code and add it to the results strResult = strResult & ASCII code of strChar & ", " Next intPosition Display results |
Algorithm: DecodeText subroutine |
Dimension and initialize variables ' Hint: add an extra comma to the end of strInput so that it doesn't crash ' loop through input string, breaking off one number at a time until gone Do While Len(strInput) > 0 ' get one number from list (up to next comma), using InStr() function strNumber = Left(strInput, position of next comma - 1) ' remove the first number from the input string strInput = Mid(strInput, position of next comma + 1) ' convert string to number (the ASCII code) intCode = Val(strNumber) ' add character to output Append ASCII character (intCode) to strResult Loop Display results |
Important features
- Separate subroutines for encode and decode
- Command button uses option buttons to decide which subroutine to call
- Subroutine heading comment block
- Do…Loop and For…Next loops in proper format
- Mid() function to get one character at a time
- InStr() function for finding commas in list
- Error control – handle codes outside of ASCII range
- Go and Done buttons, with Default and Cancel properties set
- Proper indents, spacing, comments
- Explanation paragraph (see below)
Example
Explanation
In addition to your program, write a paragraph explaining in common
terms how each of the two main algorithms works. Make it clear that you understand
the purpose of the loops, what happens each time the loop runs, and how each of
your variables plays a part in the encoding or decoding process.