Using Text as a variable
Joe Fishback
Posts: 99
I would like to be able to have someone type in their first name and then store the name typed as a variable. Then the program would compare this name as Text to a variable Text name. If the INPUT matches one listed in the program, the program would go to a sub and do something. Attached is a program I tried, but it does not work. Can anyone help me.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······ Joe Fishback
-Robots are my friends-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······ Joe Fishback
-Robots are my friends-
Comments
·
·· I have posted code a few times for comparing passwords entered from keypads.· That same code could be used as you describe.· The limitations on a BS2 are the amount of available array storage.· On any other BASIC Stamp you can use the SPRAM in the same manner.· This can be compared to the internal values stored in DATA statements terminated with a 0.· For example:
You could do something like:
Then you would have a lookup routine compare character by character until you hit the 0.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
You could try a hash function. What this does is convert a string of characters to a number. Then you can compare the number to other, stored numbers that were obtained in the same way. A word variable can take on 65536 different values. Under ideal circumstances, each of these would be the hash for a different name. So, ideally, two different names will virtually never generate the same number. When this happens, it's know as a "collision", and collisions can and do happen. The idea is to come up with a hash function that minimizes this possibility.
The program below is an example of a hash function. It accepts characters from DEBUGIN until it receives a carriage return. As it's doing so, it converts all lower-case letters to upper-case and filters out any non-letters. Then, it keeps a running computation of the hash in the variable name. Once it receives a carriage return, it spits out the number and starts over.
No attempt has been made to test the collision behavior of this function. The way to do this would be to write a similar program for the PC and feed it a list of first names from the internet and see if any collisions occur. But you can at least try it out with the names you might encounter to see if it works well enough.
-Phil
Attached is the list of collisions produced by this formula.
-Phil