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

reset text boxes to either character or numeric using Setall

Status
Not open for further replies.

cverrall

Programmer
May 23, 2003
5
0
0
GB
Hi Everyone,

Firstly merry xmas and happy new year. I have a form (which contains a pageframe) which needs to have all the values reset to either character or numeric. currently i set each field individually. but sure there must be a better way.

many thanks Colin
 
Do you mean set the value to a string or a numeric?
Do you means something like this:
Code:
FOR i=1 TO thisform.Objects.count 
    IF UPPER(thisform.Objects[i].BaseClass) == "TEXTBOX"
    	m.MyValue = thisform.Objects(i).value
    	
    	IF TYPE("m.MyValue") = "U" .or. TYPE("m.MyValue") = "C"
	        thisform.Objects(i).value = 0
	    ELSE
	        thisform.Objects(i).value = "a"
	    ENDIF
    ENDIF 
ENDFOR

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
What do you mean by "all the values"? If you are referring to values of individual controls within the pages, what sort of controls are they (text boxes? combo boxes? spinnners?)? Are they bound to fields in a table? And what do you mean when you say you want to reset the values to "either character or numeric"? Character and numeric are data types, not values.

If you could phrase your questions more clearly, you have a better chance of getting a good answer.

In general, you can use SetAll() to change the properties of any object within a container. A pageframe is a container, as is a page within a pageframe. If the page contains, say, a number of tetxboxes, you could use SetAll() to change the Value property of every textbox within the page, like so:

[tt]THISFORM.MyPageFrame.Page1.SetAll("Value", "", "textbox")[/tt]

Here you setting the value of every textbox to an empty string. But, using this technique, you have to set every value the same. You can't use it, for example, to convert every numeric data type to a character string (there are other ways of doing that). And it is not appropriate if the texboxes are bound to controls whose data type is other than character.

Does that help at all?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
If controls are bound to a record, Well, Append Blank will give you a new record with "Blank" fields, which means default values.
If you want to blank an existing record you can simply use the Blank command on an existing record.

But, you see, it's rather a question of the data and not the controls, even though there is setall, BLANK is the real deal as it acts according to data type and more important the default values you might define 8only a feature of DBC tables, though).

There even is BLANK DEFAULT AUTOINC, which means the old record gets a new autoincrementing value.

Even if you just have unbound controls for some reason. Create a class for the form that has the properties you want to bind to or better yet create a cursor with the needed structure. Easy, when it's the structure of a table of your database, then you have COPY STRUCTURE to get an empty cursor including same default values and APPEND BLANK gives you one record to bind to, if it already exists and you want to go back to defaults, again just use BLANK DEFAULT. Last not least, it's the usual way to go with an updatable view in buffered mode, you add a row to the view, the user can edit it, revert/cancel it or save it, it's not part of the DBC until then, which has pros and cons, but in the scenario of unbound controls you usually only want a new record in the real DBF once all is set and any business rules about the new record(s) are checked.

Chriss
 
In regard of using SetAll - as you mention it in your question:

SetAll for textboxes, for example, only affects native base class textbox, not derived classes. Therefore Griff method of recursing all objects. Just a thought about numeric values. They can be integer ids, which should be generated by the table or databasse, they can be a simple number, like a count or they could be a foreign key. So it's not necessarily good to reset all numeric fields to 0 just because that's a default. A default foreign key - for example of categoryid of a priduct, might be NULL or 1 instead. So having control classes for each such case will help to make use of SetAll. I'd still recommend the BLANK solution, VFP is meant to be data centric, not control centric.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top