Well I just started learning VB, as I started a course at school. So far everything is going good and I'm loving it, and trying out different things.
I'm looking for any tips on how to convert entire sentences or even whole text files to ASCII, or from ASCII back to text.
Bits of code for my simple converter/generator:
Code:Private Sub Command1_Click() Rem generates an ASCII list of the codes ranging from 65 to 126 Dim n As Integer Dim a As Integer picError.Cls Picture1.Cls If a = 0 Then For n = 65 To 126 'start of the iteration / the loop starts Picture1.Print n, Chr(n) 'this is the action that repeats Next 'end of iteration (loop) picError.Print "You have generated ASCII " picError.Print "Codes, make sure to click" picError.Print "Clear before you generate " picError.Print "them again!" a = 1 End If If chkGenerateError = True Then ' checks whether the hidden OptionButton is set to true or false picError.Cls Picture1.Cls picError.Print "You have not cleared the" ' if the button is set to true then it prints an error in the picture box picError.Print "boxes, please clear the boxes" picError.Print "before generating ASCII" picError.Print "codes again!" End If chkGenerateError.Value = True ' sets the optionbutton to true allowing an error to print next time the ascii button is pressed without clearing chkExit = 0 End SubIt's not completely finished or tidied up and I've got a heap of comments stuck in there for reminders, but it shows what I've got done. As you can see from the second code box it lets me convert a singular text or ASCII code back and forth, but I can't figure out how to get whole sentences working. If anyone would be kind enough to show me some examples or give some tips it would be very much appreciated!Code:Private Sub txtConverter_KeyPress(KeyAscii As Integer) Rem this piece of code is the basis of the key to ascii converter. it can be changed by changing Asc() with Chr(), which will then print the key for the ascii number picConvert.Cls If KeyAscii = 13 Then picConvert.Print Asc(txtConverter) ' uses Asc(txtConverter) to convert a letter or symbol in the text box to it's corresponding ASCII code End If ' use Chr(txtConverter) to swap it around and convert ascii codes to a letter or symbol ' you will need to change Label3 and Label5's caption value around for it to make sense, but it is not strictly neccessary for it function End Sub
Thanks in advance.




Reply With Quote