Converting a ASCII number to a character
Philldapill
Posts: 1,283
I'm using the Keyboard object and in particular, the getKey routine. It returns a number between 0 and 255, cooresponding to the key pressed. How would I go about converting this number to an actual character? I've thought about using a lookup table, and if that's the case, how do I concatenate the single character, with a string? I want to be able to allow the user to input a filename.
Comments
I've attached the routine VGA_1024. If you look at the code there, you'll see the use if getkey and the routine "out" that prints the characters to the screen.
Let me know if you have any questions.
Jim
VAR
byte FileName[noparse][[/noparse]32]
When a key is pressed, it will be checked to see if it is a letter, number, or other acceptable character for a filename. If it is, I will add it onto the end of this array. When the user hits the Enter key, this array will then somehow be translated into a string, and passed to the SD Card object, and a file will be saved with that name. The trouble is, how do you do something as simple as this...
Hope this helps.
Jim
The last line should be: array sub i := 0. For some reason, the forum is removing the character sequence[noparse]:([/noparse]
One thing I would add to the code, however, is a check to see if the character is a valid character or not. That can be done with a simple compare. Also, you probably want to add a check to make sure that input doesn't overflow your buffer. So I would change the repeat line to
Post Edited (soshimo) : 12/28/2008 12:41:42 AM GMT
Post Edited (Mike Green) : 12/28/2008 12:51:11 AM GMT
I was just trying to show the approach.
Regarding the [noparse][[/noparse] i ] being deleted by the forum, I think this may be OK for text input. But I think it is a definite BUG when it happens within the "code" directive.
Does anyone know who to talk to to get this fixed? It's kinda frustrating when you're trying to post some code. Using "i" as an index probably happens more often than any other [noparse]:)[/noparse]
Jim