Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TEXTBOX Input Mask 1

Status
Not open for further replies.

David Higgs

Programmer
May 6, 2012
390
GB
I have a TEXTBOX where the 1st four characters need to be in the following format:-
'Uppercase Letter' + 'Number' + 'Number' + '-' followed by any number of characters

i.e S93-Wexford

I have tried setting INPUTMASK to !99X which works for the 1st four characters but how do I allow for any number of random length characters?



Regards,

David

Recreational Developer and End User of VFP for my personal use in 'Amateur Radio' and 'British Railways' related Applications.
 
Also, if the fourth character is always a dash (minus sign), you don't need to store it in the table. Instead, set the Format property to R, and include the dash in the mask: !99[highlight #FCE94F]-[/highlight]XXXXXXXXXX.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike's advice is right, of course. There is no "any number of characters" character as % is in SQL LIKE clauses or * is in filenames.
You could check that in the VALID event with a regular expression, but as "any characters" isn't needing much checking. '!99-'+REPLICATE('X',LEN(field)-3) would automatically adapt the number of Xs when the field gets longer, taking into account that '-' is displayed but stripped off of the value stored.

Len(field) would not work on a Memo field, though, where it would be 0 for an empty memo. I would suggest some sensible number of Xs, then, maybe that also works out instead of computing the exact number of Xs, anyway.

Chriss
 
By the way, look at the documentation of TRANSFORM, too. It tells that the inputmask also can be used as formatting of output, so you can get the minus back into the output in reports, for example, when using @R followed by one space and then the input mask used in the textbox.

As demonstration:
Code:
? Transform('S93Wexford','@R !99-XXXXXXXXXXXXXXXXX') && prints S93-Wexford
So in a report you would set the report field expression to Transform(fieldname,'@R !99-XXXXXXXXXXXXXXXXX') to get the same output as was the display value of the input textbox (literally the textbox.displayvalue property). Therefore, you can make use of the saving Mike talks about, not storing the constant "-" part of the mask.

One downside with this is, that it takes a bit more effort to get this output in a BROWSE of the data, but that might not matter much. And another one is, that all characters that have a meaning as format/inputmask cannot be part of that constant part of the value that's stripped off. So you never can have a 9 as a constant part as 9 is the format character for digits, but minus is indeed one of the characters with no format meaning.

Chriss
 
Mike,

I realised I should have used ‘U’ to convert the first Character to uppercase and allow only A to Z Characters. I also want to save the dash (minus sign) to the database to match 3rd party format, so I ended up with: -
U99-!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The MySQL Field Length is 64, so I inserted the appropriate number of X’s to allow Input up to maximum field length.

Chris,

I wasn’t sure if there was a ‘%’ or ‘*’ syntax option available, so, thank you for confirming that’s not the case.


Regards,

David

Recreational Developer and End User of VFP for my personal use in 'Amateur Radio' and 'British Railways' related Applications.
 
David said:
I also want to save the dash (minus sign) to the database to match 3rd party format
I suggest you look into the database with the MySQL workbench, for example. You'll find, that you don't save the minus sign.

If you want that, you should override the VALUE at the VALID event with THIS.DISPLAYVALUE. Before you do that you must empty THIS.INPUTMASK, then return .T. and you save what is displayed, but still control user input during the input/modify phase.

Chriss
 
Well, but watch out, when showing the value with inputmask again, you'll have a double minus, one as you store it and one from the inputmask. So it becomes complicated to use inputmask not wanting its effect on the data stored. Note this doesn't depend on which backend you store into, as it's part of the behavior of the textbox control, not behavior of DBFs vs other backends.

Chriss
 
Chris Miller said:
One downside with this is, that it takes a bit more effort to get this output in a BROWSE of the data, but that might not matter much. And another one is, that all characters that have a meaning as format/inputmask cannot be part of that constant part of the value that's stripped off.

Also the data is stored in a shared 3rd party database (MySQL) so I don't have much choice in formatting. My application adds additional facilities not covered in the 3rd party software.

Regards,

David

Recreational Developer and End User of VFP for my personal use in 'Amateur Radio' and 'British Railways' related Applications.
 
I think you still miss one point: Once you use a character like minus (-) in the inputmask, that has no masking/formatting purpose, it is definitely stripped off the value before valid stores it back into the controlsource. You have no say in this other than what I suggested, with the problems described.

Please, just look at the data in both MySQL Workbench and in the form using the inputmask textbox. Either you do without the minus or you add it but then get it stripped off and when you apply it to saving with the method I proposed, you get problems in the next turn of retrieving it into a form with that inputmask, as the stored minus character will be added to the mask character because VFP adds what it strips off, but if you don't strip it off it gets displayed from the inputmask AND the value of the field.

Just look into this:

? Transform('s93-wexford','@R !99-!XXXXXXXXXXXXXXXXX') && prints S93--wexford.

Chriss
 
I checked the MySQL Database with phpMyAdmin and the relevant field shows the minus sign is being saved

C82-Londonderry

Empty TEXTBOX (apart from '-')

Capture_1_nckty9.jpg


TEXTBOX Entry

Capture_2_tzli4p.jpg


MySQL Database

Capture_3_xph133.jpg


I have INPUTMASK set to: U99-!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
FORMAT set to: (NONE)
Valid set to default

Regards,

David

Recreational Developer and End User of VFP for my personal use in 'Amateur Radio' and 'British Railways' related Applications.
 
I see my mistake, the stripping off only happens when you set Format to "R".

And even with Format="R" the capitalization of input is saved into the table field, only the minus is stripped off, then. Mike also said it, explicitly.

So okay, you can work this way, I don't see another immediate problem.

Chriss
 
Where possible, with Data Entry, I like to see the Data in a TEXTBOX in the required format (capitalisation of Callsigns etc) before TEXTBOX loses focus and with the help of Mike and yourself, I think that's been achieved.

Regards,

David

Recreational Developer and End User of VFP for my personal use in 'Amateur Radio' and 'British Railways' related Applications.
 
Hi David,

yes, once more, my mistake. I am so used to using Format="R" when using an inputmask, that I remember it as non-optional, but Format can be empty.

I do see one instance where you can be victim of the application you're extending with your separate Foxpro frontend to the data: If that application does have exceptions like a S404-Whatever in the data, if only by mistake, you display that as S40--Whatever with the inputmask. So there can be problematic data non-conformant with the inputmask you define that breaks your display of the data. Such a wrong value can't come from your form, but from elsewhere, also not the UI of that application, but data imports. I'm talking about the case without Format.

PS: It's not a reason to go for Format="R", as the opposite then can happen, of course, so there is nothing that will work with any case.
Also, I made another mistake in assuming a textbox has a displayvalue property, that only exists for combobox and listbox. A textbox has a text property, without using Format="R", textbox.text is the same as value, though. You can detect a difference, if you compare the table or cursor field with textbox.value, i.e. you can find out whether the data fulfills the inputmask or not.

Chriss
 
Hi Chris,

I take your point about exceptions / mistakes are possible, so I manually entered your example into the MySQL Database and found that S404-Whatever became S40—Whatever and 1AADD- became 1AA-D-

Fortunately, the Data is predetermined as a ‘County Code’ and ‘County Name’ separated by the minus sign, so, although there is the possibility of making a mistake by mis-typing etc the INPUTMASK should at least eliminate errors in Formatting of Data Input. As the application is for my own personal use, I have only myself to blame for any errors!

The 3rd Party Data input for the field in question does not provide any Formatting structure, it is a field available for users to store information of their choice of up to 64 characters in length. The software allows the data in this field to be used to collate information for various awards. In this case the number of counties contacted in Ireland.


Regards,

David

Recreational Developer and End User of VFP for my personal use in 'Amateur Radio' and 'British Railways' related Applications.
 
If it's for you, you'll of course be fine, you will always also have the MySQL Workbench and can also look at the raw data in BROWSE.

I just think of this more generally, no matter what you do, if you're just attaching to data from a third-party application not fully in your control, you can expect data CSV imports, for example, or any change of data structure to hit you possibly after a long time of things working nicely.

As a developer, you always have an easier way to cope with any problems, true.

You could make use of checking EVAL(This.Controlsource) and This.Text and This.Value to see if there is a difference, and then perhaps change Forecolor to red, if that differs, that's a thing you could do in a baseclass inputmasktextbox, for example.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top