K-Meleon

KMeleonWiki > Resources > MacroLibrary > KmmTraining

Submitted by: JamesD



Notes:

Training provides some description and demonstration of some Macro Language statements. It is interactive, providing on screen information while the actual code for Training.kmm provides a working sample library. Training has, and will have more, extra chapters. These will be files with names in the the form of Training1[2][3]...[X].kmm. Training1.kmm is available now.

These macros require K-Meleon version 1.1.x or later.

Training includes units on promptforfolder, gensub, and $ARG.
Training1 includes units on prompt, confirm, and alert.
Updates:

2009-01-11
Added Training2 with End/Exit, Catch, promptforfile, and basename

note: Training2 requires K-Meleon version 1.5 or later. For a 1.1 version of Training2 see here

Open your User Macro Folder (Edit > Configuration > User-Defined Macros) or your Macro Folder (Edit > Configuration > Macros) and create the following text file(s):

Training.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- Training.kmm
# ---------- K-Meleon Macro Language Training/Example ---------------
#
# Dependencies        : main.kmm,  K-Meleon ver 1.1 or later
# Resources           : -
# Preferences         : -
# Version             : - 0.7   2008-12-24
# --------------------------------------------------------------------------------
#
####  PUBLIC MACROS ----------

Training_ArgCode{
$_Training_ArgVal = $ARG ;
$_Training_ArgVal == "menu" ? &_Training_ArgCodeA : 0 ; 
$_Training_ArgVal == "F8" ? &_Training_ArgCodeB : 0 ;
}

####  PRIVATE MACROS ---------

_Training_OverView{
$_Training_Text01 = "This 'Training' macro is provided to help users understand some statements";
$_Training_Text02 = "in the Macro Language which is a part of K-Meleon.";
$_Training_Text03 = "This macro file controls additional macro files designated as 'Training1[2][3]'.";
$_Training_Text04 = "Not all files are available yet.  They will be added as they become available. ";
alert($_Training_Text01."\n".$_Training_Text02."\n\n".$_Training_Text03."\n".$_Training_Text04, "Overview of 'Training'", "INFO");
$_Training_Text01 = "Each macro statement or concept will be reachable from the Training popup menu. ";
$_Training_Text02 = "Individual units do not follow each other.  You must choose an item from the menu. ";
$_Training_Text03 = "The additional macro files may each be made inactive via the Macro Extension  ";
$_Training_Text04 = "in preferences.  You can do this for units on which you no longer need help. ";
alert($_Training_Text01."\n".$_Training_Text02."\n\n".$_Training_Text03."\n".$_Training_Text04, "Overview of 'Training' (2)", "INFO");
$_Training_Version_Pref="general.useragent.vendorSub";
$_Training_User_Ver=getpref(STRING, $_Training_Version_Pref);
##  $_Training_User_Ver=substr(getpref(STRING, $Training_Version_Pref), 0, 3);
##  double conditional  ==> _KMVersion=="1.5"?$kSessions==true?&_Sessions_BuildMenu_15:0:0;
$_Training_Text01 = "The Macro Language has evolved through each new version of K-Meleon.";
$_Training_Text02 = "Some current language statements may not be not available to the version" ;
$_Training_Text03 = "of the browser that you are using.  Training will tell you if the version" ;
$_Training_Text04 = "you are using does not support a particular statement.";
$_Training_Text05 = "You are current using K-Meleon ";
alert($_Training_Text01."\n".$_Training_Text02."n\n".$_Training_Text03."\n".$_Training_Text04."\n\n".$_Training_Text05.$_Training_User_Ver, "Overview of 'Training' (3)", "INFO");
}

_Training_FolderCode{
$_Training_Text01 = "The promptforfolder statement is used to open a dialog with the user. \n" ;
$_Training_Text02 = "The user can select a folder from the list in the dialog.  An initial \n" ;
$_Training_Text03 = "folder may be provided.  A new folder may be created by the user.\n\n " ;
$_Training_Text04 = "  $PATH = promptforfolder( CAPTION [, INITIAL_FOLDER] ); ";
alert($_Training_Text01.$_Training_Text02.$_Training_Text03.$_Training_Text04, "promptforfolder", "INFO");
alert("Allow user to select folder. \n\n No initial folder \n No programed requirement", "Using promptforfolder") ;
$_Training_SubFolder=promptforfolder("Select a folder for use") ;
$_Training_Text01 = "$SubFolder=promptforfolder('Select a folder for use');" ;
#alert($_Training_SubFolder, "Return from promptforfolder dialog", "EXCLAIM");
$_Training_Text02 = "Some items in the default list are not actual folders. \n";
$_Training_Text03 = "'My Computer' and 'My Network Places' do not provide a value to '$SubFolder'. \n\n";
$_Training_Text04 = "Selecting 'Cancel' does not provide a value to '$SubFolder'." ;
$_Training_SubFolder == "" ? alert($_Training_Text02.$_Training_Text03.$_Training_Text04,"No value returned", "EXCLAIM") :0;
$_Training_SubFolder != "" ? alert($_Training_SubFolder. "\n\n".$_Training_Text01, "Folder user selected", "INFO") :0 ;
alert("Allow user to select folder. \n\n Set initial folder to originating folder \n No programed requirement", "Using promptforfolder") ;
$_Training_SubFolder=promptforfolder("Select a folder for use", $_Training_Path);
$_Training_Text01 = "$SubFolder=promptforfolder('Select a folder for use', $_Training_Path);";
alert( $_Training_SubFolder. "\n\n".$_Training_Text01, "Folder user selected", "INFO") ;
macros(_Training_FolderCode2) ;
}

_Training_FolderCode2{
alert("Allow user to select folder. \n\n Set initial folder to Favorites \n Require Favorites or subfolder", "Using promptforfolder") ;
####   look three places for the favorites directory
$_Training_FavFolder=getpref(STRING,"kmeleon.plugins.favorites.directory");
$_Training_FavFolder==""?$_Training_FavFolder=readreg("HKCU","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
$_Training_FavFolder==""?$_Training_FavFolder=readreg("HKLM","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
####   $_Training_FavFolder should have the path for the favorites folder   c:\something\favorites
####   call _Training_RnameTrue_loop until $_Training_SubFolder is no longer a "?"
$_Training_SubFolder="?";   while($_Training_SubFolder=="?") &_Training_NameTrue_loop;
$_Training_Text01 = "Review the code in macros '_Training_FolderCode2' and '_Training_NameTrue_loop'. ";
$_Training_Text02 = "Your action was either 'cancel' or 'OK'. \n";
$_Training_Text03 = "The program is designed to default to 'Favorites' in this case. \n\n";
$_Training_SubFolder == "" ? alert($_Training_Text02.$_Training_Text03.$_Training_Text01."\n\n".$_Training_FavFolder, "The selected folder", "INFO") : alert($_Training_FavFolder."\\".$_Training_SubFolder."\n\n".$_Training_Text01, "The selected folder", "INFO") ;
}

_Training_NameTrue_loop{
$_Training_SubFolder=promptforfolder (_("Specify where to add the new shortcut. Select your Favorites folder or one of its subfolders:"),$_Training_FavFolder);
$_Training_SubFolder=$_Training_SubFolder=="" ? "" : index($_Training_SubFolder,$_Training_FavFolder) == 0 ? substr($_Training_SubFolder,length($_Training_FavFolder)+1) : "?";
}

_Training_GensubCode{
$_Training_Text01 = "$SUB = gensub( r, s, h, t );" ;
$_Training_Text02 = "Searches the target string t for matches of the string r." ;
$_Training_Text03 = "If h is a string beginning with 'g' or 'G', then all matches" ; 
$_Training_Text04 = "of r are replaced with s. Otherwise, h is a number indicating" ; 
$_Training_Text05 = "which match of r to replace. The modified string is returned." ;
alert($_Training_Text01."\n".$_Training_Text02."\n".$_Training_Text03."\n".$_Training_Text04."\n".$_Training_Text05, "gensub statement", "INFO");
$_Training_Target = "copper is a color for corporate" ;
alert($_Training_Target, "The target string (t)") ;
$_Training_Match = "co" ;
$_Training_Replace = "To" ;
alert("The match string (r) is  '".$_Training_Match."'\n\n The replacement string (s) is  '".$_Training_Replace."'", "The match and replace strings", "INFO");  
$_Training_GOut = gensub($_Training_Match, $_Training_Replace, "G" ,$_Training_Target) ;
$_Training_Text01 = "$_Training_GOut = gensub($_Training_Match, $_Training_Replace, 'G' ,$_Training_Target) ;" ;
alert($_Training_GOut."\n\n".$_Training_Text01, "Global replacement", "INFO") ;
$_Training_GOut = gensub($_Training_Match, $_Training_Replace, "1" ,$_Training_Target) ;
$_Training_Text02 = "$_Training_GOut = gensub($_Training_Match, $_Training_Replace, '1' ,$_Training_Target) ;" ;
alert($_Training_GOut."\n\n".$_Training_Text02, "First replacement only", "INFO") ;
}

_Training_ArgCodeA{
$_Training_Text01 = "setmenu($_Training_Popm,'macro','$Arg','Training_ArgCode(menu)');" ;
alert("A choice was made within the Training_ArgCode macro \n based on the argument passed from the setmenu statement. \n\n The argument was 'menu'.\n\n" . $_Training_Text01 , " $ARG - argument in setmenu statement", "INFO"); 
alert("After you click OK for this message, \n\n please press the CTRL + SHIFT + F8 together.", "To test another method", "INFO");
}

_Training_ArgCodeB{
$_Training_Text01 = "setaccel( 'CTRL SHIFT VK_F8' ,'macros(Training_ArgCode(F8))');"; 
alert("A choice was made within the Training_ArgCode macro \n based on the argument passed from the setaccel statement. \n\n The argument was 'F8'.\n\n" . $_Training_Text01, " $ARG - argument in setaccel statement", "INFO"); 
alert("Training actually finished running before you pressed CTRL + SHIFT + F8. \n Your keypresses restarted Training_ArgCode and and passed 'F8' \n as an argument.", "$ARG examples finished", "INFO"); 
}

_Training_BuildMenu{
$_Training_Num = 1 ;
# add another option to Help menu
$Training_Popm = "Training" ;
#setmenu("&Help",popup,$Training_Popm,2);
setmenu("KMDocs",popup,$Training_Popm,2);
setmenu($Training_Popm,"macro","Overview","_Training_OverView");
setmenu($Training_Popm,"macro","PromptForFolder","_Training_FolderCode");
setmenu($Training_Popm,"macro","Gensub","_Training_GensubCode");
setmenu($Training_Popm,"macro","$Arg","Training_ArgCode(menu)");
macros(Training_Chapters) ;
macros(_Training_accelerators) ;
}

_Training_accelerators{
setaccel( "CTRL SHIFT VK_F8" ,"macros(Training_ArgCode(F8))"); 
}

Training_Chapters{
while($_Training_Num < 20) &_Training_Chapters_Loop ;
}
_Training_Chapters_Loop{
$_Training_File = "Training". $_Training_Num . ".kmm" ;
$_Training_ChapExist = readfile($_Training_Path."\\".$_Training_File );
$_Training_File_Menu = "Training". $_Training_Num . "_BuildMenu" ;
$_Training_ChapExist != "" ? macros($_Training_File_Menu) : 0 ;
$_Training_Num = $_Training_Num + 1 ;
}

_Training_GetPath{
## Training.kmm will be located in one of two possible locations
## If readfile finds nothing at MacroFolder then the location is UserMacroFolder
$_Training_Data=readfile(getfolder(MacroFolder)."\\Training.kmm");
$_Training_Path=getfolder($_Training_Data==""?UserMacroFolder:MacroFolder);
}

$OnInit=$OnInit."_Training_GetPath;";
$OnInit=$OnInit."_Training_BuildMenu;";
$macroModules=$macroModules."Training;";

################  END OF TRAINING.KMM  ###############################


Training1.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- Training1.kmm
# ---------- K-Meleon Macro Language Training/Example ---------------
# ---------- CHAPTER 1
#
# Dependencies        : main.kmm, Training.kmm, K-Meleon ver 1.1 or later
# Resources           : -
# Preferences         : -
# Version             : - 0.3   2008-12-23
# --------------------------------------------------------------------------------

Training1_PromptCode{
#--    $VALUE = prompt( MESSAGE [, TITLE [, DEFAULT]] );
#$_Training1_Result_Bounds = 0 ;
$_Training1_Result = prompt("Select a whole number from zero to ten", "prompt example", 5);
$_Training1_Result != "" ? alert($_Training1_Result, "Your answer from prompt") : alert("Cancel", "Your answer from prompt");
macros(_Training1_PromptValid) ;
$_Training1_Text01 = "The prompt statement is used to send a message to the user. \n" ;
$_Training1_Text02 = "The user must interact with the message display box in order \n" ;
$_Training1_Text03 = "for the macro to continue.  \n The user's interaction is returned " ;
$_Training1_Text04 = "to the macro where the results \n can be acted upon. \n\n ";
$_Training1_Text05 = "$VALUE = prompt( MESSAGE [, TITLE [, DEFAULT]] ); \n\n ";
$_Training1_Text06 = "The prompt requesting a number looks like this: \n\n Result = prompt('Select a whole number between zero and ten', 'prompt example', 5);";
alert($_Training1_Text01.$_Training1_Text02.$_Training1_Text03.$_Training1_Text04.$_Training1_Text05.$_Training1_Text06,"prompt example", "INFO");
}

_Training1_PromptValid{
$_Training1_Version_Pref="general.useragent.vendorSub";
$_Training1_User_Ver=substr(getpref(STRING, $_Training1_Version_Pref), 0, 3);
# choice 1.5 series = later version while other = early version
$_Training1_User_Ver == "1.5" ? &_Training1_PromptValidL : &_Training1_PromptValidE ;
}

_Training1_PromptValidL{
$_Training1_RCnt = 0 ;
$_Training1_RBI = 10 < $_Training1_Result ? 1 : 0;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = 0 > $_Training1_Result ? 1 : 0;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
## / operator produces an integer result
$_Training1_DecChek = $_Training1_Result / 1 ;
$_Training1_CrChek = $_Training1_Result == $_Training1_DecChek ? 0 : 1;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_CrChek ;
$_Training1_Text01 = "\n\n The acceptable values are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10." ;
$_Training1_RCnt >= 1 ? alert($_Training1_Result.$_Training1_Text01, "Your answer was not an integer within the range.", "EXCLAIM"):0;
}

_Training1_PromptValidE{
$_Training1_RCnt = 0 ;
$_Training1_RBI = $_Training1_Result == 0 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 1 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 2 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 3 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 4 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 5 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 6 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 7 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 8 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 9 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 10 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_Text01 = "\n\n The acceptable values are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10." ;
$_Training1_RCnt > 10 ? alert($_Training1_Result.$_Training1_Text01, "Your answer was not an integer within the range.", "EXCLAIM"):0;
}

Training1_ConfirmCode{
#--    $RESULT = confirm( MESSAGE [, TITLE [, BUTTONS [, ICON]]] );
#--    BUTTONS = RETRYCANCEL | YESNO | YESNOCANCEL | ABORTRETRYIGNORE
#--    ICON = EXCLAIM | INFO | STOP | QUESTION
#--    RESULT = OK | YES | NO |ABORT | RETRY | IGNORE | 0
$_Training1_Text01 = "The confirm statement is used to send a message to the user. \n" ;
$_Training1_Text02 = "The user must interact with the message display box in order \n" ;
$_Training1_Text03 = "for the macro to continue.  \n The user's interaction is returned " ;
$_Training1_Text04 = "to the macro where the results \n can be acted upon. \n\n Can you see this message?";
$_Training1_Result = confirm($_Training1_Text01.$_Training1_Text02.$_Training1_Text03.$_Training1_Text04,"confirm statement","YESNO",QUESTION) ;
$_Training1_Result == "NO" ? $_Training1_Result=confirm("You could not see prior message?", "received 'NO' from previous", "YESNO",EXCLAIM) :0 ;
$_Training1_Result == "YES" ? $_Training1_Result=confirm("Good, you did see it.", "received 'YES' from previous", "YESNO","EXCLAIM") :0 ;
$_Training1_Text01 = "are shown below.  Some shortning of text was done so they would fit \n\n" ;
$_Training1_Text02 = "Result=confirm('Bunch of text','confirm statement','YESNO','QUESTION'); \n" ;
$_Training1_Text03 = "Result=confirm('You could not see prior message?', 'received 'NO' from previous', 'YESNO','EXCLAIM'); \n" ;
$_Training1_Text04 = "Result=confirm('Good, you did see it.', 'received 'YES' from previous', 'YESNO','EXCLAIM'); \n" ;
$_Training1_Text05 = "Bye the way, your last answer was  ".$_Training1_Result. "." ;
alert($_Training1_Text01.$_Training1_Text02.$_Training1_Text03.$_Training1_Text04.$_Training1_Text05, "The previous confirm statements");
$_Training1_Text01 = "$RESULT = confirm( MESSAGE [, TITLE [, BUTTONS [, ICON]]] ); \n" ;
$_Training1_Text02 = "BUTTONS = RETRYCANCEL | YESNO | YESNOCANCEL | ABORTRETRYIGNORE \n" ;
$_Training1_Text03 = "ICON = EXCLAIM | INFO | STOP | QUESTION \n " ;
$_Training1_Text04 = "RESULT = OK | YES | NO |ABORT | RETRY | IGNORE | 0 \n\n";
$_Training1_Text05 = "Do you need to view other combinations of buttons and icons? ";
$_Training1_Result = confirm($_Training1_Text01.$_Training1_Text02.$_Training1_Text03.$_Training1_Text04.$_Training1_Text05, "confirm message box", "YESNO");
$_Training1_Result == "YES" ? macros(_Training1_ConfirmCodeA) : 0 ;
}

_Training1_ConfirmCodeA{
#alert("the user wants more");
$_Training1_Result = confirm("Choose an action", "The process stopped", "ABORTRETRYIGNORE", "STOP");
$_Training1_Text01 = "Result = confirm('Choose an action', 'The process stopped', 'ABORTRETRYIGNORE', 'STOP');";
alert("Your reply generated this answer " . $_Training1_Result. "\n\n The code was as follows \n\n". $_Training1_Text01, "confirm with buttons 'ABORTRETRYIGNORE'");
$_Training1_Result = confirm("Do you want to try another answer?", "Replay previous", "YESNOCANCEL");
$_Training1_Text01 = "Result = confirm('Do you want to try another answer?', 'Replay previous', 'YESNOCANCEL');" ;
$_Training1_Result == "YES" ? $_Training1_Text02 = "Other possible answers were  NO or 0." :0; 
$_Training1_Result == "NO" ? $_Training1_Text02 = "Other possible answers were  YES or 0." :0;
$_Training1_Result == 0 ? $_Training1_Text02 = "Other possible answers were  NO or YES." :0;
alert("Your reply generated this answer " . $_Training1_Result. "\n\n". $_Training1_Text02."\n\n The code was as follows \n\n". $_Training1_Text01, "confirm - replay previous");
$_Training1_Result == "YES" ? &_Training1_ConfirmCodeA : 0;
}

Training1_AlertCode{
#--  alert( MESSAGE [, TITLE [, ICON]] );
#--  ICON = EXCLAIM | INFO | STOP | QUESTION  
$_Training1_Text01 = "The alert statement is used to send a message to the user. \n" ;
$_Training1_Text02 = "The user must interact with the message display box in order \n" ;
$_Training1_Text03 = "for the macro to continue.  \n\n This is an alert message." ;
alert($_Training1_Text01.$_Training1_Text02.$_Training1_Text03, "alert message box", "INFO");
$_Training1_Text01 = "alert( MESSAGE [, TITLE [, ICON]] ); \n\n TITLE and ICON are optional. \n" ;
$_Training1_Text02 = "ICON can have one of the following values \n" ;
$_Training1_Text03 = "EXCLAIM | INFO | STOP | QUESTION \n\n EXCLAIM was used in this alert." ;
alert($_Training1_Text01.$_Training1_Text02.$_Training1_Text03, "form of the alert statement", "EXCLAIM");
alert("Neither TITLE nor ICON  is used in this alert");
}

Training1_BuildMenu{
# add additional lines to the training menu
setmenu($Training_Popm,"macro","[1]   Prompt","Training1_PromptCode");
setmenu($Training_Popm,"macro","[1]   Confirm","Training1_ConfirmCode");
setmenu($Training_Popm,"macro","[1]   Alert","Training1_AlertCode");
}

$macroModules=$macroModules."Training1;";
################  END OF TRAINING1.KMM  ###############################


Training2.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- Training2.kmm
# ---------- K-Meleon Macro Language Training/Example ---------------
# ---------- CHAPTER 2
#
# Dependencies        : main.kmm, Training.kmm, K-Meleon ver 1.5 or later
# Resources           : -
# Preferences         : -
# Version             : - 0.4   2009-01-11
# --------------------------------------------------------------------------------

Training2_EECode{
#--   How to end / cancel the execution of the macro based on a condition
$_Training2_Catch = "false" ;
macros(_Training2_EECodeRun) ;
}

_Training2_EECodeRun {
macros(_Training2_Ver);
$_Training2_Text0 = "There is neither an 'end' nor an 'exit' statement in the MacroLanguage. \n" ;
$_Training2_Text0 = $_Training2_Text0."In order to stop executing statements based upon a condition, the ending \n" ;
$_Training2_Text0 = $_Training2_Text0."brace '}' for the macro must be reached without executing statements which \n " ;
$_Training2_Text0 = $_Training2_Text0."would fail because of the condition. \n\n ";
$_Training2_Text0 = $_Training2_Text0."At the prompt which follows, please select a file of the type 'name.kmm'. ";
macros(_Training2_EECode_L ) ;
#--   There would normally not be any additional code here, but because this is training
#--   there are these additional lines
$_Training2_Text0 = "Normal execution of a macro would have stopped at the presentation of the user's \n";
$_Training2_Catch == "true" ? &_Training2_EECodeRunC : &_Training2_EECodeRunE ;
$_Training2_Text0 = $_Training2_Text0."When the end of a macro is reached, execution control returns to the \n" ;
$_Training2_Text0 = $_Training2_Text0."macro which called the macro, if any. \n\n"
$_Training2_Text1 = "_MacroFirst { \n ";
$_Training2_Text1 = $_Training2_Text1."  <code lines> ;\n ";
$_Training2_Text1 = $_Training2_Text1."  macros( _MacroSecond ) ; \n " ;
$_Training2_Text1 = $_Training2_Text1."  # control returns here from completion of _MacroSecond \n";
$_Training2_Text1 = $_Training2_Text1."  }  \n\n " ;
$_Training2_Text1 = $_Training2_Text1."_MacroSecond { \n" ;
$_Training2_Text1 = $_Training2_Text1."  <code lines> ; \n ";
$_Training2_Text1 = $_Training2_Text1."  }   " ;
alert($_Training2_Text0.$_Training2_Text1, "Execution control", INFO);
$_Training2_Text0 = "If you selected a file from the prompforfile this time, try the training \n " ;
$_Training2_Text0 = $_Training2_Text0."again and select to cancel rather than open a file. " ;
if ($_Training2_Catch == "true") alert($_Training2_Text0,"Catch", INFO); else alert($_Training2_Text0,"End / Exit", INFO);
}

_Training2_EECodeRunE{
$_Training2_Text0 = $_Training2_Text0."answer and the code example. In the case of a choice to cancel, execution would \n";
$_Training2_Text0 = $_Training2_Text0."have stopped because no code branch was provided for that case. \n\n";
}

_Training2_EECodeRunC{
$_Training2_Text0 = $_Training2_Text0."answer and the code example. In this case the to cancel is confirmed or the user \n";
$_Training2_Text0 = $_Training2_Text0."is returned to the point in the code where another attempt can be made. \n\n";
}

_Training2_EECode_L{
#-- Method for KM ver 1.5.0 or later   ( if statement )
alert($_Training2_Text0,"End / Exit", "INFO");
macros(_Training2_EECode_L2) ;
}

_Training2_EECode_L2 { 
$_Training2_Result = promptforfile($_Training2_Path, "kmm files", "*.kmm");
$_Training2_Result = basename($_Training2_Result, ".kmm");
if ( $_Training2_Result != "" ) {
        $_Training2_Text0 = "The creation and presentation of these lines of text occur only \n" ;
        $_Training2_Text0 = $_Training2_Text0."in the lines of code executed when the result is not missing. \n\n" ;
        $_Training2_Text0 = $_Training2_Text0."_Training2_EECode_L2{ \n ";        
        $_Training2_Text0 = $_Training2_Text0."Result = promptforfile($_Training2_Path, 'kmm files', '*.kmm'); \n" ;
        $_Training2_Text0 = $_Training2_Text0."Result = basename(Result, '.kmm'); \n";
        $_Training2_Text0 = $_Training2_Text0."if ( Result != '' ) { \n";
        $_Training2_Text0 = $_Training2_Text0."   Text0 = 'The creation and presentation of these lines . . .' \n";
        $_Training2_Text0 = $_Training2_Text0."    . \n";
        $_Training2_Text0 = $_Training2_Text0."    . \n";
        $_Training2_Text0 = $_Training2_Text0."   alert('Your selection was  '. Result.'\\n\\n'. Text0, 'Name selected') \n";
        if ( $_Training2_Catch == "true" ) {
                $_Training2_Text0 = $_Training2_Text0."   Text0 = 'You selected to cancel from the prompt for file.'; \n" ;
                $_Training2_Text0 = $_Training2_Text0."   CAnswer = confirm('Are you sure you wish to cancel?',Text0, YESNO, QUESTION); \n" ;
                $_Training2_Text0 = $_Training2_Text0."   if (CAnswer == 'NO') &_Training2_EECode_L2; else alert('Cancel is confirmed'); \n" ;
        }
        $_Training2_Text0 = $_Training2_Text0."   } ";
        alert("Your selection was  ".$_Training2_Result."\n\n".$_Training2_Text0, "Name selected");
        } 
        #-- The following statements are used only if we are training on catch        
        else { if ( $_Training2_Catch == "true" )  &_Training2_CatchRun ; }
}

Training2_CatchCode{
#--  Explain what is meant by catch in programming
$_Training2_Text0 = "The term catch means to provide an error handler within the code. \n\n" ;
$_Training2_Text0 = $_Training2_Text0."If an error condition is encountered, there must be a way to \n" ;
$_Training2_Text0 = $_Training2_Text0."gracefully end the program or provide a way to recover from the error. \n\n" ;
$_Training2_Text0 = $_Training2_Text0."We will use the 'End / Exit' example, but this time a method to \n" ;
$_Training2_Text0 = $_Training2_Text0."handle the condition raised by a cancel will be added. " ; 
alert($_Training2_Text0, "Catch", INFO);
$_Training2_Catch = "true" ;
macros(_Training2_EECodeRun) ;
}

_Training2_CatchRun{
$_Training2_Text0 = "You selected to cancel from the prompt for file." ;
$_Training2_CAnswer = confirm("Are you sure you wish to cancel?",$_Training2_Text0, YESNO, QUESTION); 
if ( $_Training2_CAnswer == "NO" ) &_Training2_EECode_L2; else alert("Cancel is confirmed");
}

Training2_PromptFFCode{
#--  Use of and return from promptforfile
#    $PATH = promptforfile( INITIAL_FOLDER, FILE_TYPE_DESCRIPTION, FILE_EXTENSION_PATTERN );
$_Training2_Text0 = "The promptforfile statement returns the full path, filename, and extention \n" ;
$_Training2_Text0 = $_Training2_Text0."of the selection made by the user. \n\n " ;
$_Training2_Text0 = $_Training2_Text0."$PATH = promptforfile( INITIAL_FOLDER, FILE_TYPE_DESCRIPTION, FILE_EXTENSION_PATTERN ); \n\n ";
$_Training2_Text0 = $_Training2_Text0."Required items are: \n\n " ;
$_Training2_Text0 = $_Training2_Text0." - path to initial folder \n " ;
$_Training2_Text0 = $_Training2_Text0." - file type description \n" ;
$_Training2_Text0 = $_Training2_Text0." - extention pattern -examples  *.exe  *.txt  *.kmm  *.js \n\n " ;
$_Training2_Text0 = $_Training2_Text0."Each of these must be a quoted string or a variable containing a quoted string.\n ";
alert($_Training2_Text0, "Prompt For File", INFO) ;
$_Training2_Result = promptforfile($_Training2_Path, "kmm files", "*.kmm");
$_Training2_Text0 = "The program generated an initial folder. \n" ;
$_Training2_Text0 = $_Training2_Text0."The file type description was 'kmm files'. \n" ;
$_Training2_Text0 = $_Training2_Text0."The extention pattern was '*.kmm'. \n\n ";
$_Training2_Text0 = $_Training2_Text0."Result = promptforfile($_Training2_Path, 'kmm files', '*.kmm');";
$_Training2_Result == "" ? $_Training2_Result = "You selected to cancel." :0; 
alert($_Training2_Result."\n\n".$_Training2_Text0, "Prompt For File", INFO) ;
}

Training2_BasenameCode{
#--  $BASE = basename( URL [, SUFFIX] ); 
#--  Returns URL with any leading directory components removed. If specified,
#--  also remove a trailing SUFFIX.
$_Training2_Text0 = "Sometimes it is not desireable to have the full path, name, and extension \n" ;
$_Training2_Text0 = $_Training2_Text0."that is received from the promptforfile statement.  We may want only \n";
$_Training2_Text0 = $_Training2_Text0."the name.  For instance, if we wanted a different path and extention for \n";
$_Training2_Text0 = $_Training2_Text0."use later in the macro. \n\n";
$_Training2_Text0 = $_Training2_Text0."$BASE = basename( URL [, SUFFIX] ); \n";
$_Training2_Text0 = $_Training2_Text0."Returns URL with any leading directory components removed. If specified, \n" ;
$_Training2_Text0 = $_Training2_Text0."also remove a trailing SUFFIX. \n\n" ;
$_Training2_Text0 = $_Training2_Text0."While meant for use with URLs, basename can strip the path and extention in \n";
$_Training2_Text0 = $_Training2_Text0."just one statement.  Notice the brackets around [, SUFFIX] in the statement?  \n";
$_Training2_Text0 = $_Training2_Text0."That means removing the suffix is optional. ";
alert($_Training2_Text0, "Basename", INFO) ;
macros(_Training2_BasenameCode2) ;
}

_Training2_BasenameCode2{
$_Training2_Result = promptforfile($_Training2_Path, "kmm files", "*.kmm");
$_Training2_Result == "" ? &_Training2_BasenameCodeC : &_Training2_BasenameCodeNC ;
}

_Training2_BasenameCodeNC{
$_Training2_ResultNE = basename($_Training2_Result, ".kmm");
$_Training2_ResultE = basename($_Training2_Result);
$_Training2_Text1 = "Results without path and extension.  ( ResultNE )\n\n";
$_Training2_Text2 = "\n\nResults without path but retaining extension.  ( ResultE ) \n\n";
$_Training2_Text0 = "\n\nResult = promptforfile($_Training2_Path, 'kmm files', '*.kmm'); \n" ;
$_Training2_Text0 = $_Training2_Text0."ResultNE = basename(Result, '.kmm'); \n";
$_Training2_Text0 = $_Training2_Text0."ResultE = basename(Result);" ;
alert($_Training2_Text1.$_Training2_ResultNE.$_Training2_Text2.$_Training2_ResultE.$_Training2_Text0, "Basename", INFO);
$_Training2_Wiki = confirm("Would you like to view the code for an actual use of basename?","View the ChmView macro in the wiki Macrolibrary",YESNO, QUESTION); 
$_Training2_Wiki == "YES" ? open("http://kmeleon.sourceforge.net/wiki/KmmChmView") :0;
}

_Training2_BasenameCodeC{
$_Training2_Text0 = "You selected to cancel from the prompt for file." ;
$_Training2_CAnswer = confirm("Are you sure you wish to cancel?",$_Training2_Text0, YESNO, QUESTION); 
if ( $_Training2_CAnswer == "NO" ) &_Training2_BasenameCode2; else alert("Cancel is confirmed");
}

Training2_BuildMenu{
# add additional lines to the training menu
setmenu($Training_Popm,"macro","[2]   End / Exit","Training2_EECode");
setmenu($Training_Popm,"macro","[2]   Catch","Training2_CatchCode");
setmenu($Training_Popm,"macro","[2]   promptforfile","Training2_PromptFFCode");
setmenu($Training_Popm,"macro","[2]   basename","Training2_BasenameCode");
}

_Training2_GetPath{
## Training.kmm will be located in one of two possible locations
## If readfile finds nothing at MacroFolder then the location is UserMacroFolder
$__Data=readfile(getfolder(MacroFolder)."\\Training2.kmm");
$_Training2_Path=getfolder($__Data==""?UserMacroFolder:MacroFolder);
}

$OnInit=$OnInit."_Training2_GetPath;";
$macroModules=$macroModules."Training2;";
################  END OF Training2.KMM  ###############################


Comments & Questions

K-Meleon

(c) 2000-2010 kmeleonbrowser.org. All rights reserved.
design by splif.