An Improved Utility for Updating a Form's Object Events

by Ron Anusiewicz and Dr. Peter Wayne

Ron has improved on a utility that I originally wrote for Application Programming in Alpha Five.

Ron writes,

“I recently had to make numerous changes on multiple forms to all the OnArrive and OnDepart events of the type-in fields. I found your code in the book and started from there. As I like playing with Xdialog, I just kept tweaking the code until I had something I felt was easy to use and failry flexible.

I think the Xdialog form is self-explanatory, but then I designed it. It's a powerful tool and can be dangerous and should be used with care. Disclaimer: I did testing and it appears to work as I intended, but I'm not 100% sure.”

Here's the way Ron's utility works. Let's say you want to make it obvious to the user which text field has focus on a form. You may decide to put this code in the OnArrive event:

this.font.color=”Red”

and add this code to the OnDepart event:

this.font.color=”Wintext”

Here is what Ron's utility looks like, and here is what you would do in this utility:




Ron's code lets you select one form at a time to work on. You can use it to see what code already exists in type-in field events, as well as to clear that code or modify the code.

'Date Created: 11-May-2004 10:34:42 AM
'Last Updated: 12-Jun-2004 02:58:27 PM
'Created By  : Dr. Peter Wayne
'Updated By  : Ron Anusiewicz

dim dlg_code as C
dim event_code as C
DIM global readonly1 as l
DIM global readonly2 as l
dim titlelength as N
DIM global whichform as C
'dim forms_all as C
dim whatisthere as C
'dim count as N
dim kount as N
dim kountblank as N
dim frm as C
dim frmchg as C
dim vfield as C
dim msg as C
dim helptext as C
dim runtime as n 
dim sleeptime as n 

runtime = .5
sleeptime = runtime/20

clearbuttonpushed = ""
kount = 0
kountblank = 0
msg = " Progress"
helptitle ="Change XBasic Code Help"
helptext = <<%help%
EDIT FORM:  Select the form you wish to work with.

CLEAR SELECTED EVENTS:  Click on the check box, then select the Event to be 
cleared.

WARNING!  ALL of the Code in every Type-In field of the Selected Event will be 
removed!
You can clear only one Event at a time.

READING AND WRITING CODE TO EVENTS:  You can work with either one event
(1st or 2nd) or two events at the same time, (1st & 2nd).  The Read Only check 
box
will read the Selected Event and display the content on the Type-In fields with 
code.
If either one of the Read Only check boxes is checked, code should NOT be 
written to any Event(s).

Select the event(s) you wish to add code to.  Enter the code in the 
corresponding Xbasic code field.  Click "OK" and that code will be written to the 
selected Event for all the type-in fields on that form.
        
Existing code should not be overwritten.  

NOTE:  If the EXACT text already exists, then the new code will NOT be added.  I 
do believe it is case sensitive.

WARRENTY and LIABILITY:  There isn't one and I assume no liability.  You are on 
your own.
I did NOT test everything nor did I try everything that users can attempt.  It 
does do what I want it to do.  I recommend working with a duplicated form first.

Ron Anusiewicz
%help%
'forms_all = a5.Form_Enum()
'count = a5_array_from_string("a_forms",forms_all,local_variables())
auto_list_whichform = a5.form_enum(2)
temp_count = w_count(auto_list_whichform,crlf())

DELETE a_whichform
DIM a_whichform[temp_count] as c
a_whichform.initialize(auto_list_whichform)
a_whichform.sort("A")

dim pct as N
dim nchildren as N
dim i as N
dim j as N
dim o as P
dim f as P

DIM SHARED clearevent as L
DIM SHARED clearwhat as C
DELETE a_clearwhat              
DIM a_clearwhat[7] as c
dim temp_list as c 
temp_list = <<%list%
OnArrive
OnDepart
OnChange
CanArrive
CanDepart
OnFlyover
OnFlyoverLeave
%list%
a_clearwhat.initialize(temp_list)

text1 = "Select 1st Event:"
text2 = "1st Event XBasic Code:"
text3 = "Select 2nd Event:"
text4 = "2nd Event XBasic Code:"
text5 = "Read Only:"

DIM global action1c as C
DIM global action2c as C
DIM global action1results as C
DIM global action2results as C
DIM SHARED varC_result as C
DELETE a_action1
DIM a_action1[4] as c
dim temp_list as c 
temp_list = <<%list%
OnArrive
OnChange
CanArrive
OnFlyover
%list%
a_action1.initialize(temp_list)

DELETE a_action2                
DIM a_action2[3] as c
dim temp_list as c 
temp_list = <<%list%
OnDepart
CanDepart
OnFlyoverLeave
%list%
a_action2.initialize(temp_list)

Tryagain:
ok_button_label = "&OK"
cancel_button_label = "&Cancel"
help_button_label = "&Help"

dlg_code = <<%dlg%
{xmargin=6,6}
{lf};
{region}
Edit Form:|{sp=26}Clear Selected Events:{sp=2}(20clearevent);;
[.30,8whichform^#a_whichform]|{sp=28}[.20,8clearwhat^#a_clearwhat?clearevent];
{endregion};
{line=1,0};
{lf};
{region}
<%T= Deselect 1st Events;%Deselect 1st Event!clearevents_button_click1?clearevent=.F.>
{sp=26.7}
<%T= Clear 1st Event Codes;%Empty 1st Event Code!clearcode_button_click1?clearevent=.F.>
{endregion};
{region}
{text=20:text1?clearevent=.F.}|{sp=3}{text=23:text2?clearevent=.F.}{sp=5}
{text=11:text5?clearevent=.F.}{sp=2}(10readonly1?clearevent=.F.);;
[.45,5action1c^#a_action1?clearevent=.F.]|[%mw%.45,5action1results?clearevent=.F.];
{endregion}
{lf};
{lf};
{region}
<%T= Deselect 2nd Events;%Deselect 2nd Event!clearevents_button_click2?clearevent=.F.>
{sp=26}
<%T= Clear 2nd Event Codes;%Empty 2nd Event Code!clearcode_button_click2?clearevent=.F.>
{endregion};
{region}
{text=20:text3?clearevent=.F.}|{sp=3}{text=24:text4?clearevent=.F.}{sp=5}
{text=11:text5?clearevent=.F.}{sp=1}(10readonly2?clearevent=.F.);;
[.45,4action2c^#a_action2?clearevent=.F.]|[%mw%.45,5action2results?clearevent=.F.];
{endregion};
{line=1,0};
{lf};
{region}
<*15,1.5=ok_button_label!OK> 
<15,1.5=cancel_button_label!CANCEL>{sp=30}
<15,1.5=help_button_label!HELP>
{endregion};
%dlg%

event_code = <<%code%
if a_dlg_button = "clearevents_button_click1" then
  a_dlg_button = "" 
  button_xbasic = <<%code_string%
  action1c=""
  %code_string%
  evaluate_template(button_xbasic)
end if
if a_dlg_button = "clearcode_button_click1" then
  a_dlg_button = "" 
  button_xbasic = <<%code_string%
  action1results=""
  %code_string%
  evaluate_template(button_xbasic)
end if
if a_dlg_button = "clearevents_button_click2" then
  a_dlg_button = "" 
  button_xbasic = <<%code_string%
  action2c=""
  %code_string%
  evaluate_template(button_xbasic)
end if
if a_dlg_button = "clearcode_button_click2" then
  a_dlg_button = "" 
  button_xbasic = <<%code_string%
  action2results=""
  %code_string%
  evaluate_template(button_xbasic)
end if
%code%

varC_result = ui_dlg_box(\
"Change XBasic Code for Selected Events to all the Type-in Fields on the Selected Form",\
dlg_code,event_code)

if varC_result = "HELP" then
  ui_msg_box(" HELP",helptext)
  goto tryagain
end if

if varC_result <> "OK" then
  end
end if

if whichform = "" then
  ui_msg_box(" Warning","No Form Has Been Selected",ui_attention_symbol)
  goto tryagain
end if

if clearevent = .F. then
  if action1c = "" .and. action2c = "" then
    if readonly1 = .T. .or. readonly2 = .T. then
      ui_msg_box(" Warning",\
      "No Events Have Been Selected For 'Read Only'",ui_attention_symbol)
      goto tryagain
    else
      ui_msg_box(" Warning",\
      "No Events Have Been Selected For 'Change'",ui_attention_symbol)
       goto tryagain
    end if
  end if
  if action1results="" .and. action2results="" .and. readonly1=.F. .and. readonly2=.F. then
    ui_msg_box(" Warning",\
    "No Event Code Has Been Entered, Read Only Has Not Been Selected",ui_attention_symbol)
    goto tryagain
  end if
  if action1c <> "" .and. action1results="" .and. readonly1=.F. then
    ui_msg_box(" Warning",\
    "What Do You Want to do with the '"+action1c+"' event?",ui_attention_symbol)
    goto tryagain
  end if
  if action2c <> "" .and. action2results="" .and. readonly2=.F. then
    ui_msg_box(" Warning",\
    "What Do You Want to do with the '"+action2c+"' event?",ui_attention_symbol)
    goto tryagain
  end if
end if

if clearevent = .T. then
  if clearwhat = "" then
     ui_msg_box(" Warning",\
     "No Event Has Been Selected to Be Cleared",ui_attention_symbol)
     goto tryagain
  end if
 'Displays a message box(style:'OK, Cancel Buttons', image: 'Stop symbol', id: 'clearall').
  DIM SHARED  clearall_result as N
  DIM SHARED  clearall_OK_Button as L 
  DIM SHARED  clearall_CANCEL_Button as L 
  clearall_OK_Button = .F.
  clearall_CANCEL_Button = .F.
        
  title_var = " WARNING"
  clearall_result=ui_msg_box(title_var,\
  "You Have Selected To Clear ALL the '"+clearwhat+"' Events in The Form '"+whichform+"' ",\
  UI_OK_CANCEL+ UI_SECOND_BUTTON_DEFAULT+ UI_STOP_SYMBOL)
  'Test to see which button on the message box was pressed....
  SELECT
    CASE clearall_result = UI_OK_SELECTED
       clearall_OK_Button= .t.
    CASE clearall_result = UI_CANCEL_SELECTED
       clearall_CANCEL_Button= .t.
       END
  END SELECT
end if

'a_forms.sort("a")
ui_modeless_dlg_box(msg,<<%dlg%
{sp=40}{text=3pct}%;
{progress=80pct};
{text=50,2:frmchg};
<Close>;
%dlg%,<<%code%
if a_dlg_button="Close" then
   ui_modeless_dlg_close(msg)
   end
end if
%code%)
'for i=1 to count
   'frm = a_forms[i]
  frm = whichform
  'pct = int((i/count)*99)
  'ui_modeless_dlg_refresh(msg)
  on error goto errortrap
  f=Form.load(frm)
  f.Command("SYSTEM_DESIGN")
  nchildren=f.Children()
  for j=1 to nchildren
    sleep(sleeptime)
    pct = int((j/nchildren)*99)
    ui_modeless_dlg_refresh(msg)
    o=f.Child(j)
    if o.class()="type-in field" then
       vfield = ": " + f.Child(j).name()
       frmchg = frm + vfield
       kount = kount + 1
       select
         case readonly1 = .T. .and. clearevent = .F.
           dim x as N
           select
             case action1c = "OnArrive"
               whatisthere = o.code.OnArrive
               titlelength = len(alltrim(frmchg)) + len(alltrim(action1c))
               x = 90 - titlelength
               if whatisthere = "" then
                 kountblank = kountblank + 1
               else
                 ui_msg_box(frmchg+"  field"+space(x)+action1c+"  xBasic"+space(1),\
                 ""+whatisthere+"")
               end if
             case action1c = "OnChange"
               whatisthere = o.code.OnChange
               titlelength = len(alltrim(frmchg)) + len(alltrim(action1c))
               x = 90 - titlelength
               if whatisthere = "" then
                 kountblank = kountblank + 1
               else
                 ui_msg_box(frmchg+"  field"+space(x)+action1c+"  xBasic"+space(1),\
                 ""+whatisthere+"")
               end if                          
             case action1c = "CanArrive"
               whatisthere = o.code.CanArrive
               titlelength = len(alltrim(frmchg)) + len(alltrim(action1c))
               x = 90 - titlelength
               if whatisthere = "" then
                 kountblank = kountblank + 1
               else
                 ui_msg_box(frmchg+"  field"+space(x)+action1c+"  xBasic"+space(1),\
                 ""+whatisthere+"")
               end if                          
             case action1c = "OnFlyover"
               whatisthere = o.code.OnFlyover
               titlelength = len(alltrim(frmchg)) + len(alltrim(action1c))
               x = 90 - titlelength
               if whatisthere = "" then
                 kountblank = kountblank + 1
               else
                 ui_msg_box(frmchg+"  field"+space(x)+action1c+"  xBasic"+space(1),\
                 ""+whatisthere+"")
               end if
              end select
           END select
           SELECT
             case readonly2 = .T. .and. clearevent = .F.
               select
                 case action2c = "OnDepart"
                   whatisthere = o.code.OnDepart
                   titlelength = len(alltrim(frmchg)) + len(alltrim(action2c))
                   x = 90 - titlelength
                   if whatisthere = "" then
                     kountblank = kountblank + 1
                   else
                     ui_msg_box(frmchg+"  field"+space(x)+action2c+"  xBasic"+space(1),\
                     ""+whatisthere+"")
                   end if
                 case action2c = "CanDepart"
                   whatisthere = o.code.CanDepart
                   titlelength = len(alltrim(frmchg)) + len(alltrim(action2c))
                   x = 90 - titlelength
                   if whatisthere = "" then
                     kountblank = kountblank + 1
                   else
                     ui_msg_box(frmchg+"  field"+space(x)+action2c+"  xBasic"+space(1),\
                     ""+whatisthere+"")
                   end if                                  
                 case action2c = "OnFlyoverLeave"
                   whatisthere = o.code.OnFlyoverLeave
                   titlelength = len(alltrim(frmchg)) + len(alltrim(action2c))
                   x = 90 - titlelength
                   if whatisthere = "" then
                     kountblank = kountblank + 1
                   else
                     ui_msg_box(frmchg+"  field"+space(x)+action2c+"  xBasic"+space(1),\
                     ""+whatisthere+"")
                   end if
                 end select
           end select
           SELECT
             case clearevent = .T.
               select
                 case clearwhat = "OnArrive"
                   o.code.OnArrive=""
                 case clearwhat = "OnChange"
                   o.code.OnChange=""
                 case clearwhat = "CanArrive"
                   o.code.CanArrive=""
                 case clearwhat = "OnFlyover"
                   o.code.OnFlyover=""             
               end select      
             case action1c = "OnArrive" .and. readonly1 = .F. .and. readonly2 = .F.
               whatisthere = o.code.OnArrive
               select
                 case action1results$whatisthere=.T.
                 '
                 case action1results$whatisthere=.F.
                   o.code.OnArrive=whatisthere+crlf()+action1results
               end select
             case action1c = "OnChange" .and. readonly1 = .F. .and. readonly2 = .F.
               whatisthere = o.code.OnChange
               select
                 case action1results$whatisthere=.T.
                 '
                 case action1results$whatisthere=.F.
                   o.code.OnChange=whatisthere+crlf()+action1results
               end select
             case action1c = "CanArrive" .and. readonly1 = .F. .and. readonly2 = .F.
               whatisthere = o.code.CanArrive
               select
                 case action1results$whatisthere=.T.
                 '
                 case action1results$whatisthere=.F.
                   o.code.CanArrive=whatisthere+crlf()+action1results
               end select
             case action1c = "OnFlyover" .and. readonly1 = .F. .and. readonly2 = .F.
               whatisthere = o.code.OnFlyover
               select
                 case action1results$whatisthere=.T.
                 '
                 case action1results$whatisthere=.F.
                   o.code.OnFlyover=whatisthere+crlf()+action1results
               end select
           end select
           select
             case clearevent = .T.
               select
                 case clearwhat = "OnDepart"
                   o.code.OnDepart=""
                 case clearwhat = "CanDepart"
                   o.code.CanDepart=""
                 case clearwhat = "OnFlyoverLeave"
                   o.code.OnFlyoverLeave=""
               end select      
             case action2c = "OnDepart" .and. readonly1 = .F. .and. readonly2 = .F.
               whatisthere = o.code.OnDepart
               select
                 case action2results$whatisthere=.T.
                 '
                 case action2results$whatisthere=.F.
                   o.code.OnDepart=whatisthere+crlf()+action2results
               end select
             case action2c = "CanDepart" .and. readonly1 = .F. .and. readonly2 = .F.
               whatisthere = o.code.CanDepart
               select
                 case action2results$whatisthere=.T.
                 '
                 case action2results$whatisthere=.F.
                   o.code.CanDepart=whatisthere+crlf()+action2results
               end select
             case action2c = "OnFlyoverLeave" .and. readonly1 = .F. .and. readonly2 = .F.
               whatisthere = o.code.OnFlyoverLeave
               select
                 case action2results$whatisthere=.T.
                 '
                 case action2results$whatisthere=.F.
                   o.code.OnFlyoverLeave=whatisthere+crlf()+action2results
               end select
             end select
          end if
  next j  
  f.Command("FILE_SAVE")
  f.Close()
'next i 

ui_modeless_dlg_close(msg)
if readonly1 = .T. .or. readonly2 = .T. then
  if kountblank > 0 then
    ui_msg_box(" Success",\
    ""+kount+"  type-in fields were Examined and "+kountblank+" are Blank",\
    ui_information_symbol)
  else
    ui_msg_box(" Success",""+kount+"  type-in fields were Examined",ui_information_symbol)
  end if
else
  if clearevent = .T. then
    ui_msg_box(" Success",""+kount+"  type-in fields were Cleared",ui_information_symbol)
  else
    ui_msg_box(" Success",""+kount+"  type-in fields were Changed",ui_information_symbol)
  end if
end if

END

errortrap:
on error goto 0
resume next

You can download Ron's utility here.

6/12/2004 - pkw

Don't forget, we need your feedback to make this site better!

Return to home