Skip to content

Instantly share code, notes, and snippets.

@jbratu
jbratu / CS_OI_RESPONSE_DIALOG.oibp
Created June 21, 2016 18:18
Simple OpenInsight response dialog. See the help file for more information or see https://wiki.srpcs.com/display/Commands/Msg+Function
$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
@jbratu
jbratu / CS_SNIP_READNEXT_READWRITE.oibp
Last active December 20, 2019 22:36
Simple subroutine to select a table, read each record, and write it back. It contains a Gosub branch where you can put code to modify the record before it is written back to the database.
Subroutine CS_SNIP_ReadNext_ReadWrite(TABLE_NAME, SAVED_LIST_NAME)
declare function Set_FSError
Declare Subroutine Set_Status, Rlist
err = ''
$Insert Logical
open TABLE_NAME To TABLE else
status = Set_FSError()
return
@jbratu
jbratu / OIMSG_CUSTOM_BUTTONS.oibp
Created July 4, 2016 15:39
Example showing how to use the Msg function with custom button text.
WantsFries = '' ;* Set to 'No' or 'Yes' after Msg.
Def = ""
Def<MTEXT$> = "Do you want fries with your order?"
Def<MTYPE$> = "BNo Fries,Fries" ;*B indicates beginning of comma separated list.
Def<MICON$> = "?"
Resp = Msg(@window, Def)
Begin Case
@jbratu
jbratu / CS_SNIP_RANDOM_NUMBER.oibp
Created July 7, 2016 13:43
The OpenInsight random number generator is pseudo-random and running simultaneous sessions on the same computer can result in the same random number results. This snippet calls the JScript random number generator.
common /csRnd/ WScript, init%
If Assigned(init%) Else init% = ''
If init% else
WScript = oleCreateInstance("ScriptControl")
OlePutProperty(wscript, "Language", "JScript")
s = 'function getrandom() {return Math.random();}'
x = WScript->AddCode(s)
init% = 1
end
RetVal = WScript->Eval("getrandom();") * 1
@jbratu
jbratu / CS_BREAKON_BOUNDARY.oibp
Created July 7, 2016 19:57
Given a string of words the function breaks the string into chunks no longer than the specified length. Breaks on word boundaries and avoids breaking words into fragments.
Function CS_BREAKON_BOUNDARY(Sentence, Boundary, BreakLength)
/*
Example:
Sentence = 'The Quick Brown Fox................ Jumped Over the Lazy Dog ....'
Lines = CS_BREAKON_BOUNDARY(Sentence, ' ', 10)
Lines contains an array of sentences And words that do Not exceed 10 characters In length.
*/
@jbratu
jbratu / CS_RESOLVE_TABLE_HANDLE_TO_NAME.oibp
Last active June 19, 2024 23:10
Function accepts and OpenInsight table handle and resolve the handle back to a table name.
Function CS_RESOLVE_TABLE_HANDLE_TO_NAME(OpenTableHandle)
Declare Function List_volume_Sub
/*
Given the example:
Open 'SYSLISTS' To OpenTableHandle Else Debug
TableName = CS_RESOLVE_TABLE_HANDLE_TO_NAME(OpenTableHandle)
The Function will return the name of the table From the handle.
*/
@jbratu
jbratu / CS_LIST_RDKVIEW_CHANGED.oibp
Created July 11, 2016 00:45
Given the name of an existing RDK View Name it produces a report of the stored procedures and the modified dates. It could be adapted to list out any other entity type too.
Function CS_LIST_RDKVIEW_CHANGED(RDKView)
*Name of the RDK to list in the current repository.
If Unassigned(RDKView) Or RDKView EQ '' Then RDKView = 'TEST_RDK'
$Insert Logical
Declare Subroutine Rlist, Set_Status, Run_Report, Msg
Declare Function Get_Status, Run_Report
Err = ''
@jbratu
jbratu / OpenInsight List and Select Keywords.md
Last active August 1, 2023 01:16
The authoritative list of OpenList LIST and SELECT statement keywords for OpenInsight is found in the Programmer's Reference Manual under the section 'Appendix A: OpenList Keyword Reference > With'. It's difficult to find when using the help file index or search feature. Below are a few of my favorite examples.

Selecting Data

Executing a select statement will return the number of rows found and set the in memory active list of keys which can be accessed using a list statement.

Select records in table based on key name

@ID contains the name of the record key, use this field in you comparison criteria.

SELECT INVENTORY WITH @ID GT 100 AND @ID LT 200

Select records in table based on a search term in the beginning or ending of a field

@ID contains the name of the record key, use this field in you comparison criteria. For example find all window source code belonging to the EXAMPLES app. The right bracket operator means 'beginning with'.

@jbratu
jbratu / CS_LAUNCH_FILE_SNIPPET.oibp
Last active September 13, 2016 15:47
OpenInsight sample snippet to show how any recognized file on the system can be opened by the file extension's registered application.
Function CS_LAUNCH_FILE_SNIPPET(void)
*Common to hold our control between runs so it isn't re-initialized on each call
common /wscript_launch_control/ wsLauncher, wsLauncherAssigned
If Assigned(wsLauncherAssigned) Else wsLauncherAssigned = ''
If wsLauncherAssigned Else
*Control not initialized, do it now
@jbratu
jbratu / mailgun_check_bounce.oibp
Created July 23, 2016 01:15
OpenInsight code to check mailgun for bounced email messages.
Function mailgun_check_bounce(params)
/************************************************************************************************
* Name : MAILGUN_CHECK_BOUNCE
*
* Description: Simple example problem to query the MailGun email server to check for if the
* specified email address bounced and get the reason why.
* Program demonstrates the use of WinHTTP COM Object and JSON values.
*
* Example use only. Requires configuration of static variables for example.
* Set CheckAddressBounced, APIKey, APIDomain before use.