• Welcome to PlanetSquires Forums.
 

WM_CHAR

Started by Petrus Vorster, December 02, 2017, 04:39:37 PM

Previous topic - Next topic

Petrus Vorster

I have used this simple formula under WM_Char to prevent the user from pressing certain keys:
elect Case Chr$(chCharCode)
        Case "A" To "Z" ,"a" To "z", Chr$(9), Chr$(8), Chr$(32)
           
            Function = 0 '
           
        Case Else
            Function = 1
               
            Exit Function
    End Select   
   Function = 0 


I want to limit it to certain places in the string to prevent TYPO's on capturing tracking numbers manually.
It has to be TWO LETTERS, 9 Numbers, 2 Letters: e.g.
RA952800068ZA

Thereafter i will pass the string for validation using a check digit, but how to get it to only allow characters only in that sequence i am still struggling to make happen although i am pretty sure it would happen inside the same function.

Anny ideas would be appreciated!
-Regards
Peter

David Kenny

Are you talking about forcing that sequence as the user types?  That could get frustrating for the user.  How would you want to deal with them cursoring back with the arrow keys and then deleting the first A, shifting the 9 into a letter position?  It's probably best to check when they leave the field.  Too many possible ways of dealing with this that without knowing how you want to notify the user and when (in great detail) there is really no way to offer advice.

Petrus Vorster

Hi David

Yes, i was thinking of enforcing the sequence although i still do a check when the textbox loses focus.
That tracking numbers has to be in that exact sequence.
I was using the tool myself and i had a barcode scanner, but now that some other guys are going to use it, and they will not all have barcode scanners, i discovered how easy one makes typing errors, and how frustrating it is to get a pop-up, reminding you its wrong.

Paul uses something like that in his DATE function in the Fire-Textbox, but it's ok, It's not the en of the world.

thanks for the advice.
-Regards
Peter

Nathan Durland

I did a quick search on the PowerBASIC board for "masked input".  Most advanced database system have this for entering things like phone numbers and so forth.  I got several hits, but I admit I didn't study them too hard.  Most are for enforcing entering only numbers, but at least one was a sub class example that might be adapted to your needs. 

David Kenny

I thought about it again, and came up with something you might like. Three different edit fields almost touching each other.  The outer ones only allow alpha, and the inner only digits.  I would intercept arrow keys to allow the user to seamlessly move from one field to the other as if they were one, although I wouldn't make the borders invisible so that the user has a reminder what size each piece is.  It would look much nicer if the fonts are fixed width.

Mike Doty

#5
type site:powerbasic.com masked edit in a google search.
Verify is also used in some examples.
The use of site:  works better than using the search in PowerBASIC in my opinion.
I first saw Eric Pearson using this and have found it extremely useful.
Another thing that works well with google is putting VB6 in front of a search because VB6 code is very similar.