Post Reply 
Multiple Choice for CHOOSE command
08-22-2018, 09:13 PM (This post was last modified: 08-24-2018 12:11 AM by Han.)
Post: #15
RE: Multiple Choice for CHOOSE command
Here's is the code for deleting systems of equations (see SovleSys in my signature below). I added extra comments to help understand the general idea:

PHP Code:
// UI for deleting systems
ssDeleteSys()
begin
  local cmd
:="input({";
  
local systitles;
  
local j,p,p0,p1,k;
  
local selected:={};
  
local lib:={};
  
local pages:=0;

  if 
ssLibSize then
    
// 'selected' is a list of which systems have been selected for deletion
    
selected:=makelist(0,j,1,ssLibSize);
    
// dynamically create the entries using the title of each system of equations
    
systitles:=makelist(ssCurLib(j,1),j,1,ssLibSize);

    
// max of 10 pages, with 7 entries per page so break into groups of 70
    
pages:=ip((ssLibSize-1)/70);

    
// now work on each block of 70
    
for p from 0 to pages do
      
p0:=p*70+1p1:=min(p0+69,ssLibSize);
      
k:=0;

      
// here we modify 'cmd' to create a complete INPUT command sequence

      // first create a list of variables, which for us is a list of entries
      // each entry needs to be of the form { var_name, type, { location_list } }
      // in our case, var_name is actually 'selected(#)' where # is dynamically
      // generated by the index j; and k is the row number
      
for j from p0 to p1 do
        
k:=k+1;
        
cmd:=cmd "{selected(" string(j,1,0) + "),0,{94,5," string(k-1,1,0) + "}}";
        if (
j<p1then cmd:=cmd ",\n"end// this line return is for debugging purposes
      
end;

      
// now add the title (and the page number if we have more than 70 systems)
      
cmd:=cmd "},\n" string(ssTDeleteSys 
        
"[" string(p0,1,0) + "-" string(p1,1,0) + "]" ) + ",\n{";

      
// now for the list of the labels of each entry (titles of each system of equations)
      
for j from p0 to p1 do
        
cmd:=cmd string(systitles(j));
        if (
j<p1then cmd:=cmd ",\n"end;
      
end;
      
cmd:=cmd "},\n{";

      
// add list of help text, which is the same for all entries
      
for j from p0 to p1 do
        
cmd:=cmd string(ssHMarkDel);
        if (
j<p1then cmd:=cmd ",\n"end;
      
end;
      
cmd:=cmd "})";

      
// leave a copy of the actual cmd string for debugging purposes
      
Notes(ssLogFile):=cmd;

      
// j can be used to detect if user canceled the UI
      // the actual results are stored in 'selected'
      
j:=expr(cmd);
      
cmd:="input({"// reset for next loop

    
end// for p

    // current system deleted? if so set index to 0
    
if ssCurSysIndex then
      
if selected(ssCurSysIndexthen
        ssCurSysIndex
:=0;
      
end;
    
end;

    
// rebuild library and adjust index
    
for j from 1 to ssLibSize do
      if 
selected(jthen
        
if ssCurSysIndex then
          ssCurSysIndex
:=ssCurSysIndex 1;
        
end;
      else
        
lib(0):=ssCurLib(j);
      
end;
    
end;
    
ssCurLib:=lib;
    
AFiles(ssLibFN):=lib;


  else
    
ssWarn(ssNoSystems);
  
end;
end

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Multiple Choice for CHOOSE command - Han - 08-22-2018 09:13 PM



User(s) browsing this thread: 1 Guest(s)