[VB] Functions supported in CIMON
Function | Script | n = GetTagVal(βTag Nameβ) |
Description | Reads the current value of a tag. | |
Example | Stores the value of βTag_1β in the parameter, βTag1β. Sub Func1() Tag1 = GetTagVal(βTag_1β) End Sub |
Β
Function | Script | n = GetTagValEx(βTag Nameβ, βTag Variableβ) |
Description | Reads the value of tag variable from a tag. | |
Example | Stores the maximum value of βTag_2β in the parameter, βTag2β. Sub Func2() Tag2 = GetTagValEx(βTag_2β, βMAXβ) End Sub |
Subroutine | Script | SetTagVal βTag Nameβ, Value |
Description | Writes the value to a tag. If a string tag is used, the value must be written in βValueβ format. | |
Example | Set the value of βTag_3β as 10. Sub Func3() SetTagVal βTag_3β, 10 End Sub |
Subroutine | Script | SetTagValEx βTag Nameβ, βTag Variableβ, Value |
Description | Writes the value of tag variable to a tag. | |
Example | Set the description ofβTag_4β as βThis is a description of βTag_4β.β Sub Func4() SetTagValEx βTag_4β, βDESCβ, βThis is a description of βTag_4β. End Sub |
Function | Script | n = Abs(number) |
Description | Returns the absolute value of a number. | |
Example | Set the absolute value at βMath_1β as -10.55. Sub AbsTest() Β SetTagVal βMath_1", Abs(-10.55) End Sub |
Function | Script | n = Atn(number) |
Description | Returns the arc tangent of a number. | |
Example | Set the arc tangent value at βMath_2β. [Atn(1.0) = 0.79] Sub AtnTest() SetTagVal βMath_2", Atn(1.00) End Sub | |
Note | Pi(3.1415) radians = 1800 degrees. 1 radian = 57.2957795131 degrees. 1 degree = .0174532925 radians. |
Function | Script | n = Cos(number) |
Description | Returns the cosine of an angle. | |
Example | Set the cosine value at βMath_3β. [Cos(3.141592/4) = 0.71] Sub CosTest() Β SetTagVal βMath_3", Cos(3.141592/4) End Sub |
Function | Script | n = Exp(number) |
Description | Returns e raised to a power | |
Example | Assign βMath_4β to e raised to the 1 power. [Exp(1) = 2.71828183] Sub ExpTest() Β SetTagVal βMath_4", Exp(1) End Sub |
Function | Script | n = Int(number) |
Description | Returns the integer portion of a number. | |
Example | Assign the integer portion from given value at the βMath_6β. Sub IntTest() SetTagVal "Math_6", Int(-1234.5224) End Sub |
Function | Script | n = Log(number) |
Description | Returns the natural logarithm of a number. | |
Example | Assign the log from given value at the βMath_7β. [Log(100) = 4.61] Sub LogTest() SetTagVal "Math_7", Log(100) End Sub |
Function | Script | n = Random(min, max) |
Description | Returns a random number between two values. | |
Example | Set the random value between 1 and 10 at the βMath_8β for every 2 seconds. Sub RandomTest() While 1 SetTagVal "Math_8", Random(1, 10) Sleep(2000) WEnd End Sub |
Subroutine | Script | Randomize [number] |
Description | Initializes the random number generator with a new seed. | |
Example | Generate the initial random number as 9, then set the random value between 1 and 10 at the βMath_9β for every 2 seconds. Sub RandomizeTest() Randomize 9 While 1 SetTagVal "Math_9", Random(1, 10) Sleep(2000) WEnd End Sub |
Function | Script | n = Rnd ([number]) |
Description | Generates a random number between 0 and 1. | |
Example | Set the random value between 0 and 1 at the βMath_10β for every 2 seconds. Sub RndTest() While 1 SetTagVal "Math_10", Rnd() Sleep(2000) WEnd End Sub |
Function | Script | n = Sgn (number) |
Description | Returns an Integer indicating whether a number is less than, greater than, or equal to 0. Returns 1 if number is greater than 0. Returns 0 if number is equal to 0. Returns -1 if number is less than 0. | |
Example | Determine the value of βMath_11β whether positive or negative and return the result. Sub SgnTest() SetTagVal "Math_11", Sgn(100) End Sub |
Function | Script | n = Sin(number) |
Description | Returns the sine of an angle. | |
Example | Set the sine of an angle at the βMath_12β. [Sin(3.141592/4) = 0.71] Sub SinTest() Β SetTagVal βMath_12", Sin(3.141592/4) End Sub |
Function | Script | n = Sqr(number) |
Description | Returns the square root of a number. | |
Example | Set the square root of 9 at the βMath_13β. [Sqr(9) = 3] Sub SqrTest() Β SetTagVal βMath_13", Sqr(9) End Sub |
Function | Script | n = Tan(number) |
Description | Returns the tangent of an angle. | |
Example | Set the tangent of an angle at the βMath_14β. [Tan(3.141592/4) = 1.00] Sub TanTest() Β SetTagVal βMath_14", Tan(3.141592/4) End Sub |
Function | Script | n = Asc(string) |
Description | Returns the integer containing the numeric code for the first character of string. | |
Example | Return the ASCII value of alphabet βAβ. Sub Asc_Test() Dim nNum nNum = Asc(βAβ) End Sub |
Function | Script | n = Cbool(expression) |
Description | Converts expression to True or False, returning a Boolean value. | |
Example | Use Cbool to determine whether a string is numeric or just text. Sub Cbool_test() Β Dim IsNumericOrDate As Boolean Β S$ = "34224.54" Β IsNumericOrDate = Cbool(IsNumeric(S$) Or IsDate(S$)) Β If IsNumericOrDate = True Then Β MsgBox S$ & " is either a valid date or number!" Β Else Β MsgBox S$ & " is not a valid date or number!" End if End Sub Β |
Function | Script | n = CDate(expression) |
Description | Converts expression to a date, returning a Date value. | |
Example | Input two dates and compute the difference between them. Sub CDate_Test() Dim Date1 As Date Dim Date2 As Date Dim Diff As Date Β Date1 = Cdate(#1/1/2018#) Date2 = Cdate("01/02/2018") Diff = DateDiff("d", Date1, Date2) MsgBox "The date difference is " & Cint(diff) & " days." End Sub Β |
Function | Script | n = CDbl(expression) |
Description | Converts any expression to a Double. | |
Example | Sub CDbl_test() MsgBox "The double value is : " & CDbl(535.22 * 5.4 * 0.01) End Sub Β |
Function | Script | n = CInt(expression) |
Description | Converts expression to an Integer. | |
Example | Sub CInt_test() Β I% = 100.55 Β MsgBox "The value of CInt(I) = " & CInt(I%) End Sub Β |
Function | Script | n = CLng(expression) |
Description | Converts expression to a Long. | |
Example | Sub CLng_test() Β I% = 10.55 Β J% = 123.66 MsgBox "The result is" & CLng(I% * J%) End Sub Β |
Function | Script | n = CSng(expression) |
Description | Converts expression to a Single. | |
Example | Sub CSng_test() Β I% = 100 Β MsgBox "The single value is: " & CSng(I%) End Sub Β |
Function | Script | n = CStr(expression) |
Description | Converts expression to a String. | |
Example | Sub Cstr_test() Β I% = 123.456 Β MsgBox "The string value is: " & CStr(I%) End Sub Β |
Function | Script | n = Cvar(expression) |
Description | Converts expression to a Variant. | |
Example | Sub Cvar_test() Β Dim V As Variant Β V = 4 & "th" Β MsgBox "You came in:" & V Β V = Cvar(4 & "th") Β MsgBox "You came in: " & V End Sub Β |
Function | Script | n = Chr[$] (charcode) |
Description | Returns the character whose value is charcode. | |
Example | Sub Chr_test() Β Dim A%(2) Β For I = 0 To 2 Β A%(I) = (65 + I) Β Next I Β MsgBox "The first three elements of the array are: " Β N=Chr$(A%(0)) & Chr$(A%(1)) & Chr$(A%(2)) End Sub |
Function | Script | n = CVErr(expression) |
Description | Converts expression to an error. | |
Example | Sub CVErr_test() Β MsgBox "The error is: " & CStr(CVErr(2046)) End Sub |
Function | Script | n = Hex[$] (number) |
Description | Converts a number to a hexadacimal string. | |
Example | Sub Hex_test() Β Do Β XS$ = InputBox$("Enter a number to convert: "," Hex Convert") Β X = Val(XS$) Β IF X <> 0 Then Β MsgBox "Dec: " & X & " Hex: " & Hex$(X) Β Else Β MsgBox "Goodbye." Β End if Β Loop While X<> 0 End Sub |
Function | Script | n = IsDate(expression) |
Description | Returns True if the expression can be converted to a date; returns False otherwise. | |
Example | Sub IsDate_test() Β Dim A As Variant Β Retry : Β A = InputBox("Enter a date "," Enter Date") Β If IsDate(A) Then Β MsgBox Format(A, "long date") Β Else Β MsgBox "Not quite, please try again!" Β Goto retry Β End if End Sub |
Function | Script | n = IsNumeric(expression) |
Description | Returns 1 if expression can be converted to a number; returns 0 otherwise. | |
Example | Sub IsNumeric_test() Β Dim S As String Β S$ = InputBox("Input a number in the text field.","Input number") Β IF IsNumeric(S$) Then Β MsgBox "You have input a valid text." Β Else Β MsgBox "You have input a wrong text." Β End if End Sub |
Function | Script | n = Oct[$] (number) |
Description | Converts a number to an octal string. | |
Example | Sub Oct_test() Β ST$ = "The octal values are: " Β For X = 1 To 5 Β Y% = X * 10 Β ST$ = ST$ & Y% & ":" & Oct6$(Y%) Β Next X Β Msgbox ST$ End Sub |
Function | Script | n = Str[$] (number) |
Description | Converts a number to a string. | |
Example | Sub Strtest() Β X# = 100.22 Β MsgBox "The stirng value is :" + Str$(X#) End Sub |
Function | Script | n = Val (string) |
Description | Converts a string expression to a number. | |
Example | Sub Val_test() Β A$ = InputBox("Enter anything containing a number", "Enter Number") Β B# = Val(A$) Β MsgBox "The value is:" & B# End Sub |
Function | Script | n = Choose(index, expression1. Expression2, β¦. Expression13) |
Description | Returns the expression at the specified index position. | |
Example | Sub Choose_test() Β Dim A As Variant Β Dim C As Integer Β C% = 2 Β A = Choose(C%, "Hello, world", #1/1/94#,5.5,Flase) Β MsgBox "Item" & C% & " isβ" & A & "β" End Sub Β |
Subroutine | Script |
Β statements Β Loop {While | Until} condition Do Β statements Loop |
Description | Repeats a block of statements while a condition is True or until a condition is True. | |
Example | E.g. 1) Β Dim A$(100) Β I% = -1 Β Do Β I% = I% + 1 Β If I% = 0 Then Β A(I%) = Dir$("*") Else Β A(I%) = Dir$ Β End if Β Loop While (A(I%) <> "" And I% <= 99) Β R% = SelectBox(I% & " files found",,a) End Sub β============================= E.g. 2) Β Dim A$(100) I% = 0 A(I%) = Dir$("*") Β Do While (A(I%) <> "" And I% <= 99) Β I% = I% + 1 Β A(I%) = Dir$ Β Loop Β R% = SelectBox(I% & " files found",,A) End Sub β============================= E.g. 3) Β Dim A$(100) Β I% = 0 A(I%) = Dir$("*") Do Until (A(I%) = "" Or I% = 100) Β I% = I% + 1 Β A(I%) = Dir$ Β Loop Β R% = SelectBox(I% & " files found",,A) End Sub β============================= E.g. 4) Β Dim A$(100) Β I% = -1 Β Do Β I% = I% + 1 Β If I% = 0 Then Β A(I%) = Dir$("*") Β Else A(I%) = Dir$ Β End if Β Loop Until (A(I%) <> "" Or I% = 100) R% = SelectBox(I% & " files found",,a) End Sub |
Subroutine | Script | End |
Description | Terminates execution of the current script, closing all open files. | |
Example | Sub En_test() Β MsgBox" The next line will terminate the script" Β End End Sub |
Subroutine | Script | Exit Do |
Description | Causes execution to continue on the statement following the Loop clause. | |
Example | Load an array with directory entries unless there are more than 10 entries; in which case, the Exit Do terminates the loop. Const crlf = Chr$(13) + Chr$(10) Sub ExitDo_test() Dim A$(100) I% = -1 Β Do Β I% = I% + 1 Β If I% = 0 Then Β A(I%) = Dir$("*") Β Else Β A(I%) = Dir$ Β End if Β If I% >= 10 Then Exit Do Β Loop While (A(I%) <> "") Β If I% = 10 Then Β MsgBox I% & " entries processed!" Β Else Β MsgBox "Less then " & I% & "entries processed!" Β End if End Sub |
Subroutine | Script | Exit For |
Description | Causes execution to exit the innermost For loop, continuing execution on the line following the Next statement. | |
Example | Const crlf = Chr$(13) + Chr$(10) Sub ExitFor_test() Dim A$(100) I% = -1 Β For I = 1 To 100 Β I% = I% + 1 Β If I% = 0 Then Β A(I%) = Dir$("*") Β Else Β A(I%) = Dir$ Β End if Β If I% >= 10 Then Exit For Next I End Sub |
Subroutine | Script | For counter = start To end [Step increment] Β [statements] Β [Exit For] |