Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Help needed with auto spacing when entering registration key in code

Author
Message
DemonHill
18
Years of Service
User Offline
Joined: 20th Mar 2008
Location:
Posted: 15th Sep 2010 22:23
I am adding somew code to allow entry of a registration key in the format: 1234 1234 1234 1224 or 1234-4567-7890-8765. I can't figure how to automatically add an "-" symbol.

Bascially after adding four characters I need to automatcially either add a space(preffered) or a -

Please look at code here thx

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 16th Sep 2010 05:46 Edited at: 16th Sep 2010 05:51
You could add a space to the actual input but if the user hits backspace he/she would have to back up the automatically added spaces. It's better to keep the user input without spaces but show the user the same input with spaces every 4 characters. That way when they do backspace it'll erase only the characters entered and not the spaces.



What the above does is shows both what you want the user to see Temp$ and the actual input InpStr$. The Temp$ is the one the spaces are added to using a counter so the actual input remains intact. I also added char$<>"" to the check for the max length because when I ran your code as it was it automatically put the length at 19 and thus I couldn't input anything.

I also saw a GOTO in there to check if the code was valid... it's best to avoid GOTO altogether (now that you know how it works). Instead of using GOTO to leave the DO/LOOP you can use EXIT to go to the line right after LOOP.

At the bottom of the code snip I added a function for you to use for the code check so you can see how a function would work. All you have to do is make Valid=0 if the code isn't valid or Valid=1 if it is valid.

DemonHill
18
Years of Service
User Offline
Joined: 20th Mar 2008
Location:
Posted: 17th Sep 2010 00:23
Your a star, thank you very much

Login to post a reply

Server time is: 2026-07-22 12:41:09
Your offset time is: 2026-07-22 12:41:09