[VB] Functions supported in CIMON

[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’.
[Int(-1234.5224) = -1235]

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)
n = AscB(string)
n = AscW(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)
n = CVDate(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)
n = ChrB[$] (charcode)
n = ChrW[$] (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

  1. Do {While | Until} condition statements Loop

  1. Do

Β 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)
Sub Do_Test()

Β 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)
Sub Do_Test2()

Β 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)
Sub Do_Test3()

Β 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)
Sub Do_Test4()

Β 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]