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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Assign Mixed Data Types to a Textbox Interactively

Status
Not open for further replies.

stanlyn

Programmer
Sep 3, 2003
945
US
Hi,

How do I assign mixed data types textbox interactively as the text box is where the user enters a value to search for based on a combo boxes selection which could be a char, numeric, logical types.

The user is given a combo or list box to select the field that needs searched. I want the user input box to respect the field type, format and InputMask. I know I can assign a value to it and the input box will become that type, however I'm not able to reset it for a different type between entries.

Thanks,
Stanley
 
Stanlyn,

The empty unbound textbox allows entry of any type. You'll find the vartype(thisform.txtSearch.value) will be C. Then it's up to you to infer whether the entered string is of the correct type. Well, if evaluating user input wouldn't be evil. To give a harmless example, you don't want to evaluate the user input "_vfp.docmd('quit')".

Even not assuming evil users, since the textbox then always is type char and the problem to check the type is sometimes easy (i.e. an integer has to consist of digits only), but you end up with a lot of type determination code. I therefore think it's easier to set the controlsource. And what would work as controlsource is a property of an object you create from a record of the table with:

Code:
Thisform.AddProperty('oRecord') 
Select Yourtable
Scatter Name Thisform.oRecord

Then you can bind the textbox to properties of Thisform.oRecord, which have the name of the field. Since a textbox is not as sensitive as a Grid when changing the Controlsource, you can set it multiple times to the different fields.

To not have the value of a specific record in each property, you can scatter when you're at EOF of the table, for example. Or go through the fields and decide from their fieldtype what to set as startvalue of the oRecord object. The table designer gives you the option to set a format and inputmask as meta data, which you can use in a filter/search form by reading it with mask DBGetProp('table.field',"FIELD","InputMask"). More generally speaking it means you can also help yourself with the design of the correct interface when entering such information in the table designer once and using it in any place you display, report or input a value of a field. Obviously only, if you have your tables in a DBC, a standalone free or fox2x table won't store such meta data about itself. Which you could of courrse do in separate free tables yourself.

Chriss
 
Stanley,

You say you want to respect the data type of the specified value. I don't know if this will help, but keep in mind that a combo box's Value property is always a character string, regardless of whether the user enters or selects numbers, dates or whatever.

Welcome back to the forum, by the way.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The idea applies less good to an integer field that is a foreign key to another table. There you'd like to be able to search for a value of one or even multiple fields of the corresponding foreign table. For example when the field is a personid you'd like to enter a name, even first+last. If it's a productid you'd like to search for product name or perhaps also productcode. If the foreign key points to a table like quarters with only a short liste like Q1 to Q4, you'd perhaps want a simple combobox there.

It's not necessarily your goal to have such a search input, that can still be manually set up per special use case, but I think you're aiming for a general search form.
If that's the case, perhaps use the application wizard and in the generated pjx look into the _table.vcx for the _filterdialg form class. This works with an unbound value editbox (edtSought) and the type is determined by the field and how to modify the entered value to become part of a query is done in the cmdAdd button. It's not the best way to avoid malicious input. One defense is that the edtSought does not accept quotes in its value, but that's not the strongest defense.

You might get inspiration from the form and how the most general search is tackled in it by query design. You can also look into the query or view designer for UI ideas.

Chriss
 
Hello,

maybe you can use a container with a checkbox, spinner, textbox, datepicker,.. and show only the control matching the type of data you want to get.
You may transform return value to a matching datatype before if necessary (not sure on that with listbox, since several years we use a grid instead of listbox)
Textbox : I remember textbox classes for different inputs like "calculator style" , but maybe setting inputproperty is ok, too.

Regards
tom
 
Thanks for all the quick input, however everyone is making this more complex that it needs to be. I'll explain...

A combo box that has preset selections with controlsource type=1 (value). Let me show you instead of trying to describe it in text. Just look at the screenshots.

z1_t6czc5.jpg


z2_fimxim.jpg


Batch #, category, and status are character type. Length is numeric type. PubliclyList and all the tldn values are logical.


z3_nxcj5l.jpg


z4_pdeqcj.jpg


Hope these screenshots shows what I'm trying to do...

Thanks Stanley
 
Stanley,

Well, that's a lot of code that'll differ from table to table.

But what's your problem, really? The way this is seems to work. Or do you get errors? What and when?

Chriss
 
The only thing that's bad here is that SET FILTER is always working on already loaded data, especially when using a view you'd rather set query parameters and requery the view than set filter.
You're not adding to an already set filter, so can only apply one at a time. But all that is not your question.

You're saying "I'm not able to reset it for a different type between entries."
The combo interactivechange does and this works.

Chriss
 
Chris,

It has been a while since I was working on it. Thats why there are a lot of commented and missing pieces as I was having issues just getting the basics working. Once this is working, I will upgraded it to use a combo for user input while setting it to allow user to select YES, NO, True or False for logicals, only numbers for numeric with decimal places if needed, and character upper, lower and proper casing for char data.

What I remember is that whatever value I use in the interactive change method is shown into the textbox and if the last value was a numeric and a different selection to a different selection/type in the combo, it doesn't like changing it to something different. At the time I made a note to ask here, which is what I'm doing now...

So how do I change a textbox type from numeric to logical without a value being shown. I can allow the textbox to accept anything and do conversions behind the scenes, but I'd be losing Format, MaxLength, InputMask, and maybe some other settings.

I'll get back in this...

Thanks,
Stanley
 
Chris,

I know and understand about using set filters and its implications vs pulling down only needed data... I have a version as you suggest working. Thanks for mentioning it though...

Stanley
 
whatever value I use in the interactive change method is shown into the textbox
Yes you can't just set a type and have an empty textbox. See how blank logical fields are displayed in a browse, they show .F., not blank.
For that specific case you could use SET NULLDISPLAY TO '' and set the value to CAST(.NULL. as L).

if the last value was a numeric and a different selection to a different selection/type in the combo, it doesn't like changing it to something different.

No, a textbox value is as untyped as a variable and accepts being SET to different types. You can't CTRL+A and DEL a textbox set to a numeric value interactively and then type in text. Without checking CTRL+A and DEL will set it to 0. But code can set textbox.value='' and the textbox won't complain, error or reject this value, that's wrong. It'll work and change from type numeric to type char.

Chriss
 
Correction: I just tried setting a textbox to CAST(.NULL. as L) and that does not generate a typed textbox without value. You will then be able to type in anything, not just .T. or .F.

Anyway, the problem that you can't set values to other types programmatically as the interactive change does isn't true. If your major problem is that you don't want to see a specific start value in the txtFilterValue textbox, I don't think you can get there at all, have a strict type and an empty display isn't possible. You'll have to accept that an empty display will always have type "C" and is an empty string, and you then can only limit the user input with inputmasks to stay at only digits, for example, for a number.

As soon as you set the type by a typed value, that's your start value, and there is an empty string, there is an empty date, there is .NULL. for Logical, but it's not limiting the type to L, as .null. is the "no value" value for any data type. The empty number is 0 or 0.0 for float or $0.00 for currency, in short there are typed values that EMPTY() regards as empty, but most of them are not displayed as empty string. An empty date or datetme displays at least as the format of the date, with separators, so all you enter is digits. But there's no currency value like that displayed only empty, you get 0.00 as with floats

PS: You can get typed .NULL values, if you set the txtFilterValue.controlsource to a variable or property that is set to CAST(.NULL. as type). So you have to get into using controlsource and usage of "typed NULLs". But your concenrs about a teextbox staying at a tpye are wrong. That only applies to interactive changing it and is the feautre you want to have and use for setting it and not needing the check of the input value changed from the forced type to something else. Programmatically you can change the type by setting different type values as often as you wish, though.

Chriss
 
Hi Chriss,

Actually, having the textbox of type logical displaying a .F. is ok as in a way its a template. Likewise, if the textbox is for a date, then a date template would be good, and a char showing blank is also good. So using the cast, variable and controlsource may be the way to go. I've got to play around with it...

Thanks, your comments have been very helpful,
Stanley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top