|
Problem:How can I implement autocompletion when typing into a dialog edit control?
Response: This example piece of code in the message section of the edit control will do autocompletion.
The local integer variables TEXTLEN and LASTLEN have been declared and LASTLEN preset to zero. The local string TEXT should be
long enough to hold any input. This example gets the completed strings from a database record type so the code must be in a
retrieval, and you would need a way to maintain these data once a new string was entered.
c
c AUTOCOMPLETE SURNAMES
c
. COMPUTE TEXT= UPPER(GETTXT(M_ID))
. COMPUTE TEXTLEN = LEN(TEXT)
. IFTHEN (TEXTLEN GT LASTLEN)
. CASE IS -1
. PROCESS RECORD NAMES FROM (TEXT) THRU (TEXT+"ZZZ")
. SET ITEM M_ID,SURNAME
. EXIT RECORD
. END RECORD
. END CASE
. COMPUTE DUMMY = SETPOS(M_ID,TEXTLEN+1)
. SELECT ITEM M_ID,LEN(GETTXT(M_ID))+1
. ENDIF
. COMPUTE LASTLEN = TEXTLEN
|
|
Problem: Do you know a good way to implement a pop-up calendar for entering dates?
Response: There is a subroutine in (SIR/XS) SYSPROC called TOOLS.DATEPICK that does this. See this
article for a list of all the subroutines in the TOOLS family.
TOOLS.DATEPICK can be called from PQL or PQLForms.
The two parameters passed to the subroutine are a title for the dialog and a default date. (if the default date is a missing
value then today's date is default). Two parameters returned are the selected date and return code (0 = ok, -1 = cancel).
Here is an example using this from PQLForms to enter/modify a birthday:
. FIELD BIRTHDAY
DATA AT 6,20 WIDTH 13
NOLABELS
PROMPT VARLABEL AT 6,1 WIDTH 18
. FBUTTON ACTION
(
execute subroutine sysproc.tools.datepick ("Date of Birth",birthday) returning (date,rc);
if (rc eq 0) compute birthday = date;
)
AT 6,33 WIDTH 3
PROMPT ">>"
TOOLS.DATEPICK can be compiled in sir2002 if you remove the four lines that start SET IMAGE... in the initial section.
(you will then see << < > >> instead of the arrow buttons).
(In SIR/XS you can use SET IMAGE on button controls so you could have a button with a tiny on it to invoke this subroutine.)
|
|
Problem: Do you have any general PQL for sorting an array?
Response: Here is a program that sorts an array
PROGRAM
. INTEGER TEMP
. INTEGER ARRAY X (50)
c
c Create unsorted array
c
. WRITE "Unsorted:"
. FOR I = 1,50
. COMPUTE X(I) = AINT(RAND(0)*100)
. WRITE X(I)
. END FOR
c
c Sort the array
c
. FOR I = 2,50
. SET TEMP (MISSING)
. FOR J = 1,I-1
c
c Use IFTHEN (X(I) GT X(J)) to sort Decending
c
. IFTHEN (X(I) LT X(J))
. COMPUTE TEMP = X(J); COMPUTE X(J) = X(I)
. FOR K = J+1,I
. COMPUTE TEMP1 = X(K)
. COMPUTE X(K) = TEMP
. COMPUTE TEMP = TEMP1
. END FOR
. EXIT FOR
. ENDIF
. END FOR
. END FOR
c
c Print Sorted Array
c
. WRITE "Sorted:"
. FOR I = 1,50
. WRITE X(I)
. END FOR
END PROGRAM
|
Problem: The CALL (or INCLUDE MEMBER) command doesn't work in sirbatch.
OLD FILE COMPANY
PASSWORD COMPANY
SECURITY HIGH,HIGH
CALL EXAMPLES.HELLO
Response: This is a known and interesting feature.
In SIR 3.2 and before you had to connect to one and only one database in a SIR DBMS session.
There were a special set of commands known as BATCH INITIALISATION commands which were executed
as soon as the first command not from that set was found. The database connecton commands OLD FILE,
PASSWORD etc belonged to this set and all these commands had to be read before connection was made.
In SIR2000 these commands can appear anywhere and the various pieces can be in CALLed procedures.
Still the database is not connected until all the connection commands are read and you need to
explicitly end the database connection command set with END TASK.
In the above example the database is not connected at the CALL, the database procfile is not connected
so the CALL cannot find the member.
OLD FILE COMPANY
PASSWORD COMPANY
SECURITY HIGH,HIGH
END TASK
CALL EXAMPLES.HELLO
|
Problem: Can I access operating system environment variables from SIR2000?
Response: Yes, with the new GETENV(str) PQL function.
PROGRAM
c
c Put the environment variable into a PQL local variable
c
COMPUTE HOME = GETENV('HOME')
c
c Put the PQL local variable value into a SIR GLOBAL variable
c
COMPUTE DUMMY = GLOBALS('HOME',HOME)
END PROGRAM
c Use the GLOBAL
INCLUDE FILE '<HOME>/myprog.pql'
|
|
Problem: Can I change the size of the Execution Window?
Response: The execution window supports old PQL programs that
referenced the screen by row and column coordinates. It is fixed at 30 rows x 80 columns. You can increase the font size which makes the window larger but the number of character cells in not changable.
In the Settings / Preferences menu change the EW (Execution Window) font size. This setting will not take effect until the next SIR session. Under XWindows you need to specify the font name rather than its size. The name incorporates all font metrics inc
A list of font names available can be got with the unix command xlsfonts.
note: you can also specify the name of the font used under Windows. To do this you need to manually edit the sir.ini file in your windows directory.
[exw]
fname=Terminal
The font name is only recognised by windows if its name does not start with '-'
|
|
Problem: I am getting an error message which does not seem relevant. This program worked in older versions of SIR.
Response: The problem may be related to implied computes.
In SIR you can have explicit computes:
COMPUTE VAR = expression
and implicit computes:
VAR = expression
Implicit computes only work when the variable name is not a command word. In SIR2000 we've added many new functions with names that may clash with program variable names:
eg TEXT or MESSAGE. The compiler thinks it has a valid command and starts translating the rest of that command. You usually end up with a ^ pointer
just before your equal sign and a message like (but not neccesarily)
Name is missing or invalid. (Error 32 - ) or
Cannot define dialog item at this point. (Error 767) or
Character is invalid at this point. (Error 72) or
String value required. (Error 736)
Note: impiled computes occur not only at the start of a command. eg:
PROGRAM
...
. IF (A EQ 0 AND E2A GT DATE) DATE=E2A
. COMPUTE A = B ; TEXT = "Hello"
...
END PROGRAM
Will work if it is changed to
PROGRAM
...
. IF (A EQ 0 AND E2A GT DATE) COMPUTE DATE=E2A
. COMPUTE A = B ; COMPUTE TEXT = "Hello"
...
END PROGRAM
|
|
Problem:SIR crashes after I print.
Response: There are some memory problems unrelated to SIR with HP LaserJet
printer drivers and Windows. Essentially the printer driver writes to memory that
Windows has already allocated to the SIR process. After printing SIR tries to use
the corrupt memory as a pointer to other memory and crashes.
The solution is to install a compatible driver from your MS Windows CD.
Note: Some LexMark printers also are effected.
|
Problem:Does SIR2000 return end of execution error codes to the OpSystem (Windows, WindowsNT)?
Response: Yes. The variable errorlevel will contain the error code under windows.
@echo off
sirbatch in=hello.pql
if errorlevel 2 goto L2
if errorlevel 1 goto L1
if errorlevel 0 goto L0
echo you should never see this message
:L2
echo errorlevel ge 2
goto theend
:L1
echo errorlevel = 1
goto theend
:L0
echo errorlevel = 0
goto theend
:theend
echo the end
Under unix:
sirbatch in=hello.pql
echo $?
Return codes are:
0 = success
1 = user warnings
2 = user errors
more = sir error
|