6

The LA Fox Developer Newsletter
February 1997
VFP Forms for Any
Screen Resolution
By Nelson M. Johnson, CCP

While I was learning MS Access, I saw a really cool demonstra-
tion of a form that would proportionally resize all the controls on
the form each time the form size was changed so that no matter
how small or large the form was, the user could still use all the
controls. I was stunned. This was the answer to my Windows-
client prayers. Now I could develop a form for one resolution and
regardless of what screen resolution the user had, my form
would always look right. I initially tried copying the code into the
forms I wanted to have this ability, but reality struck. Access
has this nasty requirement that ALL procedure names through-
out the application must be unique. This meant that if I really
wanted this to work, I would have to do some serious re-writing.

Along comes Visual FoxPro. I wrote a simplified procedure to
do this very trick and have included it below. There are four
properties you will need to add to your form: PrevHeight,
PrevWidth, BaseWidth, and BaseFontSize. You should manu-
ally set the BaseFontSize to whatever font size is your default
for the form. Then add these two procedures to your form and
you are off. There are a couple things you need to be aware of:
This will not handle container objects such as option groups and
page frames. Also, some controls have an AutoSize property
which this will set to .T., but the ones that don’t (like text boxes)
will have problems in the handling of the height property be-
cause rounding error will cause the size to “creep” if you resize
the form several times. I started to address this problem in fonts
by tracking the original base font size and then use an absolute
scaling factor, but I haven’t perfected it - I will leave that to you
to share with us. Unlike its Access cousin, this code should
allow you to drop it into many forms or classes and impress
your clients and coworkers, especially if they have been using
an FPW application.

Procedure Form.lnit()
this.prevHeight = this.height
this.prevWldth = this.width
this.BaseWidth = this.width

Procedure Form.Resize()
local InI && a loop counter
local lcName && the name of the object
local InScaleFactor && a relative scale factor
local InBaseScaleFactor && an absolute scale factor
local IcError
IcError = on(’error’)

InScaleFactor = this.width I this.prevWidth
this.prevWidth = this.width
this.height = this.prevHeight * InScaleFactor
&& the height of the form isa
&& fixed function of the width
this.prevHeight = this.height
InBaseScaleFactor = this.width / this.BaseWidth
on error * && some objects don’t have
&& FontSize or AutoSize Property
(Con't, next column)
Forum Hot Tip
Corrupted Table
/ have a small corrupted datebase which I’d like to fix and I
understand that! should use a Foxpro compatible program to
make the changes.

The Software program is Navcis 1.76, a Compusetve "offline
reader” The specific database which is couurpted is the
address book. It is about 70 kb in size and consists of 314
records. Each record is assigned a number. The numbers
should run from 1-314. Howe ver somehow the db got corru pted
and actually reads from 1 to about 150 and then starts over,
again running from about I - 150. I understand that I simply
need to open the db and manually change the numbering to I -
314. Any suggestions?

Bob

Hi Bob,

Try this-
First create a table with an exact structure like your
‘corrupted_table’.
Then-
SELECT ‘corrupted_table’
COPY TO ARRAY anyname
SELECT new_table’
APPEND FROM ARRAY anyname


VFP Forms (Con? from prey, column)

=amembers(laMembers,this,2) && get a list of object names

&& (ignore nested objects)
this.lockscreen = .t. && this will make form updates
&& wait until we are done
for InI = I to alen(laMembers)
IcName = laMembers[lnl]
with this.&lcName
.AutoSize .t.
.width .wldth * InScaleFactor
.height = height * lnScaleFactor
.top = .top * InScaleFactor
.left = .left * InScaleFactor
.FontSize int(this.BaseFontSize * lnBaseScaleFactor)
endwith
next
thls.lockscreen = .f. && allow form to udpate

on error &lcError


[Ed. Note: Nelson M. Johnson, Certified Computer Profes-
sional, is a member of the Potomac Area FoxPro Group. To
contact him, send e-mail to consult@i-t-works-inc.com. Copy-
right © 1996 i.t. Works, Inc.)
Page 6

6