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!

.Setall max length of textboxes to 100 in form w/PageFrame - possible? 2

Status
Not open for further replies.

CMcC

Programmer
Feb 5, 2002
196
US
I have a form with 6 tabs on a pageframe, and would like to set all the maxlengths to 100 for all textboxes on the form without having to go into each and every tab and each and every textbox property to set.

Is there someway to do it, sorta like closing forms all at once:
Code:
lnFormCount = _Screen.FormCount
    For i = 1 To lnFormCount-1
       _Screen.Forms(i).Release
    ENDFOR
But I want to do this with all textboxes on the entire form, pageframe and all.

Any suggestions? ALL help is very appreciated!
CMCC
 
You can write a little program to open each form individually as a table and then execute the following:

Code:
REPLACE ALL properties WITH "MaxLength = 100" + CHR(13)+CHR(10) + ALLTRIM(properties) FOR ALLTRIM(class) = 'textbox' AND !("MaxLength = 100" $ properties)

That will make the MaxLength property = 100 for each textbox object on the form where it is not entered (set to default = 0)

The other way would be to put code into the Init method of each form to modify the MaxLength property as the form is initialized.

Good Luck,
JRB-Bldr
 
The best way to do it is to base all the textboxes on a textbox class that's set up the way you want. I recommend you create such a class and then you can use a little code to replace all the textboxes on the form with textboxes from your new class. The code would look something like:

Code:
USE <Your Form.SCX>
REPLACE Class with "Your New Class Name", ;
        ClassLoc WITH "Your New Classlib including relative path" ;
  FOR Class = "textbox"
USE


If, for some reason, you don't want to use a class for this, you can use the SetAll method. However, you'll still have to touch each page of the pageframe to make the change, since SetAll doesn't drill down.

Tamar
 
Actually I should modify my example above slightly

Code:
cThisForm = <whatever>
USE (cThisForm) ALIAS MyForm
SELECT MyForm
REPLACE ALL properties WITH "MaxLength = 100" + CHR(13) + CHR(10) + ALLTRIM(properties) ;
   FOR ALLTRIM(class) = 'textbox' ;
   AND !("MaxLength" $ properties)
USE

Good Luck,
JRB-Bldr
 
Thanks to both Tamar and jrbbldr. Both have been extremely helpful!
Cmcc
 
CmCC,

Although JrbBldr has given you a good answer, you should keep in mind that it is a one-off solution. Every time you add a textbox to your form, you will have to run the code again.

Personally, I think it's better to do this sort of thing at run time, within the application. You can do that as follows:

Code:
FOR EACH loPage IN THISFORM.MyPageFrame.Pages
  loPage.SetAll("MaxLength", 100, "textbox")
ENDFOR

If you add that code to the Init of your form, you will always get the desired result, even if you add or remove pages or make any other similar changes.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thank you Mike. I realized that I would have to run that again, but your suggestion would work for all instances- with no need to run again - in case I forget.

I love this site!!!

Cmcc
 
Mike's solution is absolutely correct and indeed the best approach for each individual form.

My saying "write a little program to open each form individually as a table" was an indication that, for some reason, I thought that you had a LOT of forms to change in the same manner and that adding that code to ALL of the forms might be a onerous task.

Regardless, I am glad you got your answer.

Good Luck,
JRB-Bldr
 
Thanks JRB-Bldr! I guess I didnt phrase my question quite correctly, but I will keep your suggestion in mind for when I have multiple forms that need altering. I must start using the class effect when starting a project (as Tamar suggested) - sometimes I forget to do that.

Cmcc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top