by Jack Wheeler
| My Client insisted on customizing his A5-based CALENDAR according to his own color preferences. How was I going to do this? After a little thought I discovered GLOBAL VARIABLES and their place in Alpha Five. |
Many users are now habituated to customizing their own applications and desktops. Now this is not what we are used to doing in Alpha Five! I have written a contact manager/scheduling application in A5. My client wanted to customize the colors for different types of appointments, so he could distinguish at a glance what each appointment represents.
The first step in giving my users custom colors was to design a form allowing them to make choices. This form shows the different possible colors and gives a choice of fonts as well:
Figure 1. The color chart form.
Figure 2. The color chart with explanations!
Each color rectangle has a Hotspot object with a code placed in the OnPush event. Here is the code for the "light red" rectangle. The code is analogous for the other hotspots:
''XBasic
COLOR="LT RED"
dim f as p
dim t as p
DIM BACK AS C
f=parentform.this
IF F:RADIO1.VALUE="WHITE".OR.F:RADIO1.VALUE="CHANGE" THEN
If f:MULSTBTN1.value="Calls" then
t=table.open("Colors")
t.change_begin()
iF F:RADIO1.VALUE="WHITE" THEN
f:TEXT1.FILL.FORECOLOR="WHITE"
callsbk = "white"
t.CALLS_BK="WHITE"
ELSEIF F:RADIO1.VALUE="CHANGE" THEN
f:TEXT1.FILL.FORECOLOR=COLOR
t.CALLS_BK=COLOR
callsbk = color
end if
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="Meetings" then
t=table.open("Colors")
t.change_begin()
iF F:RADIO1.VALUE="WHITE" THEN
f:TEXT2.FILL.FORECOLOR="WHITE"
t.MEETING_BK="WHITE"
meetingsbak = "White"
ELSEIF F:RADIO1.VALUE="CHANGE" THEN
f:TEXT2.FILL.FORECOLOR=COLOR
t.MEETING_BK=COLOR
meetingsbk = color
END IF
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="things" then
t=table.open("Colors")
t.change_begin()
iF F:RADIO1.VALUE="WHITE" THEN
f:TEXT3.FILL.FORECOLOR="WHITE"
t.THINGS_BK="WHITE"
thingsbk = "white"
ELSEIF F:RADIO1.VALUE="CHANGE" THEN
f:TEXT3.FILL.FORECOLOR=COLOR
t.THINGS_BK=COLOR
thingsbk = color
END IF
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="Sales" then
t=table.open("Colors")
t.change_begin()
iF F:RADIO1.VALUE="WHITE" THEN
f:TEXT4.FILL.FORECOLOR="WHITE"
t.SALES_BK="WHITE"
salesbk = white
ELSEIF F:RADIO1.VALUE="CHANGE" THEN
f:TEXT4.FILL.FORECOLOR=COLOR
t.SALES_BK=COLOR
salesbk = color
END IF
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="Office" then
t=table.open("Colors")
t.change_begin()
t.office_color= office
iF F:RADIO1.VALUE="WHITE" THEN
f:TEXT5.FILL.FORECOLOR="WHITE"
t.OFFICE_BK="WHITE"
officebk = "white"
ELSEIF F:RADIO1.VALUE="CHANGE" THEN
f:TEXT5.FILL.FORECOLOR=COLOR
t.OFFICE_BK=COLOR
officebk = color
END IF
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="Low" then
t=table.open("Colors")
t.change_begin()
t.low_color= Low
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="Medium" then
t=table.open("Colors")
t.change_begin()
t.Medium_color= medium
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="High" then
t=table.open("Colors")
t.change_begin()
t.High_color= High
t.change_end(.t.)
t.close()
End If
ELSE
If f:MULSTBTN1.value="Calls" then
var->calls = color
f:Calls.fill.forecolor=calls
f:Text1.font.color = calls
t=table.open("Colors")
t.change_begin()
t.Calls_color= calls
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="Meetings" then
var->meetings = color
meeting = color
f:Meetings.fill.forecolor=Meetings
f:text2.font.color = meetings
t=table.open("Colors")
t.change_begin()
t.Meeting_color= Meetings
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="things" then
Var->things=color
f:Things.fill.forecolor=things
f:text3.font.color = things
t=table.open("Colors")
t.change_begin()
t.things_color= things
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="Sales" then
Var->sales= color
f:sales.fill.forecolor=sales
f:text4.font.color = sales
t=table.open("Colors")
t.change_begin()
t.sales_color= sales
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="Office" then
var->office=color
f:office.fill.forecolor=Office
f:text5.font.color = office
t=table.open("Colors")
t.change_begin()
t.office_color= office
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="Low" then
var->low =color
f:low.fill.forecolor=Low
t=table.open("Colors")
t.change_begin()
t.low_color= Low
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="Medium" then
var->Medium = color
f:Medium.fill.forecolor=medium
t=table.open("Colors")
t.change_begin()
t.Medium_color= medium
t.change_end(.t.)
t.close()
elseif f:MULSTBTN1.value="High" then
Var->High = color
f:High.fill.forecolor=High
t=table.open("Colors")
t.change_begin()
t.High_color= High
t.change_end(.t.)
t.close()
End If
END IF
f.resynch()
Script 1. Xbasic script for the Light Red hotspot.
I save the user's choices in a table of color preferences:
Figure 3. Table of color preferences, called - can you guess? - color.dbf.
When my application begins I load all the user-selected color and font preferences with this script:
'AutoExec script
Dim global calls as c
dim global Callstxt as c
dim global high as c
dim global low as c
dim global medium as c
dim global meetings as c
dim global meeting as c
dim global meetingtxt as c
dim global office as c
dim global officetxt as c
dim global things as c
dim global thingstxt as c
dim global sales as c
dim global salestxt as c
dim global Salesbk as c
dim global callsbk as c
dim global meetingsbk as c
dim global officebk as c
dim global thingsbk as c
Calls = alltrim(Lookup("Appointments\colors",".t.","calls_color"))
Callsbk = alltrim(Lookup("Appointments\colors",".t.","calls_bk"))
Thingsbk= alltrim(Lookup("Appointments\colors",".t.","things_bk"))
Officebk = alltrim(Lookup("Appointments\colors",".t.","office_bk"))
Salesbk = alltrim(Lookup("Appointments\colors",".t.","Sales_bk"))
Meetingsbk= alltrim(Lookup("Appointments\colors",".t.","meeting_bk"))
CallsTxt =alltrim(Lookup("Appointments\colors",".t.","calls_font"))
High=alltrim(Lookup("Appointments\colors",".t.","High_color"))
Low=alltrim(lookup("Appointments\colors",".t.","Low_color"))
Medium=alltrim(Lookup("Appointments\colors",".t.","Medium_color"))
Meeting=alltrim(Lookup("Appointments\colors",".t.","Meeting_color"))
Meetings=alltrim(Lookup("Appointments\colors",".t.","Meeting_color"))
MeetingTxt=alltrim(Lookup("Appointments\colors",".t.","Meeting_Font"))
MeetingsTxt=alltrim(Lookup("Appointments\colors",".t.","Meeting_Font"))
Office=alltrim(Lookup("Appointments\colors",".t.","office_color"))
OfficeTxt=alltrim(Lookup("Appointments\colors",".t.","Office_Font"))
Sales=alltrim(Lookup("Appointments\colors",".t.","Sales_color"))
SalesTxt=alltrim(Lookup("Appointments\colors",".t.","sales_Font"))
Things=alltrim(Lookup("Appointments\colors",".t.","things_color"))
ThingsTxt=alltrim(Lookup("Appointments\colors",".t.","Things_Font"))
Script 2. The Autoexec script loads the preferences into global variables.
Figure 4. See how the user selects a color for a Sales Call entry in this calendar utility.
See how the different categories of appointments show up in different colors on the calendar:
Figure 5. The calendar in use.
My major problem in Alpha Five programming has been my inability to plan logically enough to program something properly once, instead of repeatedly coming up with partial solutions. This color chart enabled me to come up with one solution that works for many users and many forms! Here are some lessons I learned:
If(CONTAINSi(scheduler->N21,"Calls"),var->calls+" on "+var->callsbk,If(CONTAINSi(scheduler->N21,"Sales Call" ), var->sales+" on "+var->salesbk,If(CONTAINSi(scheduler->N21,"Meeting" ),var->meeting+" on "+var->meetingsbk,If(CONTAINSi(scheduler->N21,"Office" ),var->office+" on "+var->officebk,If(CONTAINSi(scheduler->N21,"Things" ),var->things+" on "+var->thingsbk,"Black on White")))))
I hope this will help you in your development. If you apply this before you start developing you can develop 10 to 20 global variables that can be used to customize each and every field on every form.
| Editor's note: This is the first of what Jack has promised will be 3 articles on his scheduling application. Jack says he will make a download available at some point. In the meantime, you can reach Jack at jwl1@jps.net |
2/1/00
Don't forget, we need your feedback to make this site better!