congruityservice
congruityservice
Reputation Top 1%
Congruity Service
11 Snippets  (83rd place)
Published
2 Channels
Created
4 Channels
Following
503 points  (65th place)
Reputation
Junior Code Generator
Serious Code Generator
Junior Publisher
Serious Publisher
Junior Topic Creator
Junior Topic Hub
Junior Trend Maker
Serious Trend Maker
Junior Popular Coder
Serious Popular Coder
Senior Popular Coder
Junior Autobiographer
Senior Autobiographer
Senior Famous Coder
Senior Popular Coder

Recent Snippets See all snippets by congruityservice

public by congruityservice  2801  2  5  0

Basic Commuter Module

OpenInsight contains a commuter module generator to create a shell program capable of handling window events. It doesn't work so well in OpenInsight 9.4 so below is a basic version generated from the commuter module generator that can be easily customized for your window.
Function YOUR_WINDOW_NAME_EVENTS(CtrlEntID,Event,Param1,Param2,Param3,Param4,Param5,Param6,Param7,Param8)
*
* Blank Commuter Module
*
Declare Subroutine Msg, FsMsg, Set_Status, Set_Property

Declare Function Msg, Get_Property, Get_Status, Set_Property, Popup
Declare Function  Repository, Send_Message, Send_Event, Unassigned, Utility, XLate
Declare Function  ContextMenu

$Insert COLORS
$Insert MSG_Equates
$Insert Popup_Equates
$Insert Logical

If Unassigned(CtrlEntID) Then CtrlEntID = ''
If Unassigned(Event) Then Event = ''
If Unassigned(Param1) Then Param1 = ''
If Unassigned(Param2) Then Param2 = ''
If Unassigned(Param3) Then Param3 = ''
If Unassigned(Param4) Then Param4 = ''
If Unassigned(Param5) Then Param5 = ''
If Unassigned(Param6) Then Param6 = ''
If Unassigned(Param7) Then Param7 = ''
If Unassigned(Param8) Then Param8 = ''
*
*
If index(CtrlEntID,".",1) then
	WinName = Field(CtrlEntID,'.',1)
	Control = Field(CtrlEntID,'.',2)
End else
	WinName = CtrlEntID
	Control = WinName
End
*
Parent = @window
Frame = Get_Property(Parent,'MDIFRAME')
If len(Frame) then Parent = Frame
*
Retval = 1
*
Begin Case

	Case Control = "YOUR_WINDOW_NAME" And Event = 'CREATE'
		*Gosub handle create event
	Case Control = "BTN_DOSOMETHING"
		*Events for CONTROL go here
		Begin Case
			Case Event = "CLICK"
				*Gosub handle click event
		End Case
		
End Case
*
return retval
*
* End Main Routine
*
            
;

public by congruityservice  2322  1  5  0

OpenInsight POPUP Function Example With Literal Data

The Popup function (see https://wiki.srpcs.com/display/Commands/Popup+Function) is very flexible but with flexibility comes complexity. This is a code example showing a multi-column Popup with literal data.
$Insert POPUP_EQUATES
Declare Function Popup

PopDisp = ''
PopDisp<PCOL$> = -1
PopDisp<PROW$> = -1
PopDisp<PWIDTH$> = -1
PopDisp<PHEIGHT$> = -1
PopDisp<PFILE$> = ''
PopDisp<PMODE$> = 'L'
PopDisp<PTITLE$> = 'Please choose a line'
PopDisp<PTYPE$> = 'E'

//Show multi-column list
PopDisp<PDISPLAY$> = "One":@SVM:"A is for Apple":@VM:"Two" :@SVM: "B is for Banna":@VM:"Three":@SVM:"C is for Code"
PopDisp<9> = 1:@SVM:10:@SVM:'L':@SVM:'L':@SVM:'':@SVM:'Num Col':@VM:2:@SVM:25:@SVM:'L':@SVM:'L':@SVM:'':@SVM:'Phrase'

//For simple single column list
/*
PopDisp<PDISPLAY$> = "One":@VM:"Two":@VM:"Three"
PopDisp<PFORMAT$> = 1:@SVM:10:@SVM:'L':@SVM:'L':@SVM:'':@SVM:'Num Col'
*/

Resp = Popup(@WINDOW, PopDisp)
;

public by congruityservice  2752  2  5  0

Save List of Attached Tables as Code

Run routine To parse the list of attached tables And save the list To an OS file In a form that is suitable For copying And pasting into source code For re-attaching the same list of tables.
Function CS_SAVE_ATTACHED_TABLES(void)
/*
Usage:
Run routine To parse the list of attached tables And save the list
To an OS file In a form that is suitable For copying And pasting into
source code For re-attaching the same list of tables.
*/
declare function Set_FSError
$Insert Logical
 
*Location to save the generated list of attached tables
OutputFile = "C:\temp\tables.txt"

*Readnext through the systables which contains a list of currently attached tables.
TABLE_NAME = "SYSTABLES"

*Storage for list of attached tables
AttachEntry = ''

open TABLE_NAME To TABLE else
	status = Set_FSError()
	return
End

select TABLE
Done = False$
 
Loop
	ReadNext @ID else Done = True$
Until Done Do


	read @RECORD From TABLE, @ID Then
		
		Gosub processRecord
	   
	End Else
		status = Set_FSError()
		return
	End
	
Repeat
 
*Write the list of attached tables to a file
Swap @FM With \0D0A\ In AttachEntry
OSWrite AttachEntry To OutputFile
 
return
*
* End Main
*
processRecord:

	//Don't bother processing Index or Dictionary tables
	If @ID[1,1] EQ "!" Then Return
	If @ID[1,5] EQ "DICT." Then Return

	//Check the volume against certain system volumes and exclude them
	Vol = Field(@RECORD<1>, "*", 2)
   
	*Exclude tables in RevBoot
	ExVol = ''
	If Vol = ExVol Then Return
   
	*exclude tables in various system directories
	ExVol = 'REPOSITORY'
	If Vol[1,Len(ExVol)] = ExVol Then Return
   
	ExVol = 'MEMORY_RESIDENT'
	If Vol[1,Len(ExVol)] = ExVol Then Return
   
	ExVol = 'O4WFILES'
	If Vol[1,Len(ExVol)] = ExVol Then Return
   
	ExVol = 'WEBOI'
	If Vol[1,Len(ExVol)] = ExVol Then Return
   
	ExVol = 'REVBOOT'
	If Vol[1,Len(ExVol)] = ExVol Then Return
   
	ExVol = 'DATAVOL'
	If Vol[1,Len(ExVol)] = ExVol Then Return
   
	*Tables attached outside of the revboot directory have absolute
	*paths and will be changed to be relative.
	Swap "\\SERVER1\SHARE\REVTABLES\" With "" In Vol
	Swap "\\SERVER2\SHARE\REVTABLES\" With "" In Vol
   
	TableName = @RECORD<2>
	App = @RECORD<3>
   
	*Build a list of tables in an openinsight data structure suitable for compiling in source code
	*Generated output will look like:
	*Tables<-1> = 'TEST_VOL,PERSON_INFO_TEST,GLOBAL' ;* TEST_VOL
	AttachEntry<-1> = "Tables<-1> = '" : VOL : "," : TableName : "," : APP : "' ;* " : VOL

return
;

public by congruityservice  2063  3  6  0

Gas Gauge Processing Message with Updating Text

The standard help file for the OpenInsight Msg function shows a sample gas gauge for showing progress but it doesn't contain an example of how to change the processing text to indicate what the loop is currently working on. This example expands upon the help file example for Msg() and includes the ability to change the text during each processin
Subroutine CS_TEST_MSG_GASGAUGE(void)
$Insert Msg_Equates

//Number of example processing loops
MAX_LOOPS = 1000

def = ''
def<MCAPTION$> = 'Gas Guage with Cancel Button'
def<MTYPE$> = 'GCU'
def<MTEXT$> = 'Initializing...'
def<MEXTENT$> = MAX_LOOPS 
def<MTEXTWIDTH$> = 400 ;* Width of the progress window

//Display the message for the first time
msgup = Msg(@WINDOW, def)

For i = 1 To MAX_LOOPS

	//Update the text and progress of the message
	Call Set_Property("MSG.ST_TEXT", "TEXT", "Working on loop " : i)
	Resp = Msg(@WINDOW,MsgUp, i, MSGINSTUPDATE$)
	
	//If user canceled then abort the loop
	If Resp EQ 0 Then
		i = MAX_LOOPS
	End
	
	//Allow processing of cancel events
	Call Yield()

Next

//Take down the message
Call Msg(@WINDOW, MsgUp)            
;

public by congruityservice  2139  2  5  0

Simple OpenInsight Response Dialog

Uses the Msg function to display a dialog prompting the user to enter a response. See the Msg function in OpenInsight help file for more information.
$Insert MSG_EQUATES

Def = ""
Def<MTEXT$> = "What did you eat for breakfast?"
Def<MTYPE$> = "RC"
Def<MICON$> = "?"

Response = Msg(@window, Def)

if Response = char(27) or Response = "" then
   * Message was escaped or not entered
   Return
end
;