User Tools

Site Tools


language_reference

Basic Language Reference

Functions

Standard library functions are supported as follows. These functions work as specified in this Language Reference unless comments indicate otherwise. String functions can be called using the syntax of methods, just as in REALbasic.

Abs

Abs (Double) As Double

Returns the absolute value of the number specified.

Dim d As Double

d=Abs(23.9) //returns 23.9
d=Abs(-23.9) //returns 23.9

Acos

Acos (Double) As Double

Returns the arccosine of the value specified. The arccosine is the angle whose cosine is value. The returned angle is given in radians.

Dim d As Double

Const PI=3.14159265358979323846264338327950
d=Acos(.5) //returns 1.0471976
d=Acos(.5)*180/PI //returns 60

Asc

Asc (String) As Integer

Returns as an Integer, the ASCII value for the first character of a String.

Dim a As Integer

a = Asc("@") //returns 64

The Asc function returns the code point for the first character in the String passed. Characters 0 through 127 are the standard ASCII set. They will be the same on practically every platform. Asc returns the code point for whatever encoding the string is in. If the string is in MacRoman, you get the code point specified by MacRoman, and so forth.

If you need to get the ASCII code of the first byte of the string rather than the first character, use the AscB function.

AscB

AscB (String) As Integer

Returns as an Integer, the value for the first byte of a String.

MsgBox Str(AscB("a")) //returns 97
MsgBox Str(AscB("A")) //returns 65

The AscB function returns the code for the first byte in the String passed. If you need to get the character code of the first character of the string rather than the first byte, use the Asc function.

AscB should be used instead of Asc when the string represents binary data or when your application will run on a one-byte character set (such as the US system) and you want case-sensitivity.

Asin

Asin (Double) As Double

Returns the arcsine of the value specified.

Dim d as Double

Const PI=3.14159265358979323846264338327950
d=Asin(.5) //returns 0.5235988
d=Asin(.5)*180/PI //returns 30

The arcsine is the angle whose sine is value. The Asin function returns the angle (in radians) of the sine passed to it. To express the arcsine in degrees, multiply the result by 180/PI.

Atan

Atan (Double) As Double

Returns the arctangent of the value specified. The arctangent is the angle whose tangent is value.

Dim d as Double

Const PI=3.14159265358979323846264338327950
d=Atan(1) //returns 0.785398 (PI/4 radians)
d=Atan(1)*180/PI // returns 45

Atan2

Atan2 (Double, Double) As Double

Returns the arctangent of the point whose coordinates are x and y. The arctangent is the angle from the x-axis to a line drawn through the origin (0,0) and a point with coordinates x, y.

Dim d as Double

Const PI=3.14159265358979323846264338327950
d=Atan2(1,0) //returns 1.57
d=Atan2(1,0)*180/PI //returns 90

BCDToTCString

Timecode from Devices with Sony 9-pin protocol and compatible usually comes in BCD format (4 Bytes FFSSMMHH). This function converts it to a string (HH-MM-SS-FF)

dim sTC, sBCD as string
//assign value to sBCD
//by reading the value from a device
sTC = BCDToTCString(sBCD)

Ceil

Ceil (Double) As Double

Returns the value specified rounded up to the nearest Integer.

Dim d as Double

d=Ceil(1.234) //returns 2

CheckSum8Bit

CheckSum8Bit(string) As Integer

Returns the Check-sum of a string. Each byte of the string is treated as binary value (not as ASCII code) and is added to the Check-sum. If the Check-sum exceed 256 in “roll over” to zero.

Dim c as integer

c = CheckSum8Bit("ABC")   // returns 198
c = CheckSum8Bit(chr(1)+chr(2)+chr(3)) // returns 6

checksumXOR

Returns the XOR Checksum od a given string

dim sXor as string
sXour = checksumXOR("My String to Checksum")

CRC16

Returns the CRC16 Checksum od a given string

dim sCrc as string
sCrc = CRC16("My String to Checksum")

Chr

Chr (Double) As String

Returns the character whose ASCII value is passed.

Dim Tab,CR,MyA as String

Tab=Chr(9) //returns a tab
CR=Chr(13) //returns carriage return
MyA = Chr(65) //returns "A"

The Chr function will return a single byte String when running on single byte systems and return a double byte string when running on double byte systems. If you need to get a single byte string regardless of whether the system software is single or double byte, use the ChrB function.

ChrB

ChrB (Double) As String

Returns a single byte String whose value is passed.

Dim s as String

s=ChrB(32) //returns a space
s=ChrB(13) //returns carriage return

The ChrB function returns a single byte string whose value is specified. ChrB should be used rather than Chr when value represents binary data.

If you need to get a single byte string when running on single byte system software and a double byte string when running on double byte system software, use the Chr function.

If you need to specify a code point above 127, use the Chr property of the TextEncoding class. With it, you specify both the encoding and the character code in that encoding.

Const

Const name = value

Declares a value as a local constant.

Const Pi=3.14159265358979323846264338327950

The Const statement can be used in place of the Dim statement followed by an assignment statement when you are sure that the value of the variable should not change within the method. Using Const instead of Dim provides a convenient way to manage such values.

A Const statement can be placed anywhere in a method, including inside a conditional structure, such as an If statement, or a looping structure. Constants declared in this manner are local to the method.

Cos

Cos (Double) As Double

Returns the cosine of the given angle.

Dim d as Double

Const PI=3.14159
d=Cos(45*PI/180) //returns 0.707

CountFields

CountFields (String, String) As Integer

Returns the number of values (fields) in the string passed that are separated by the separator string passed. If the source string is binary data or you require case-sensitivity, use CountFieldsB instead.

The example below returns 5.

Dim count as Integer
Dim s as String

s="Dan*Smith*11/22/69*5125554323*Male"
count=CountFields(s, "*")

The following example returns three because it counts the null “field” after the (unnecessary) final field delimiter.

Dim count as Integer
Dim s as String

s="Dan*Smith*"
count=CountFields(s, "*")

CRC16

Returns a CRC16 calculated checksum

Delay

Delay (String)

Waits the given number in ms. The given number must be a string.

Delay("1000")    //Wait 1 Second
Dim i as integer

i = 500
Delay(str(i))     //Wait 500 ms

Exit

Exit

The Exit statement causes control to exit a loop and jump to another line of code without the loop conditions being satisfied. The optional keywords enable you to control where execution will resume.

  • If you use Exit without any optional keywords, V-Control exits whatever loop the Exit statement is in.
  • If you use Exit with the Do keyword, V-Control exits the Do loop it is in, even if it is also inside another type of loop.
  • If you use Exit with the While keyword, V-Control exits the While loop it is in, even if it is also inside another type of loop.
  • If you use Exit with the For keyword without passing a parameter, it exits the innermost For loop it is in, even if it is also inside another loop.
  • If you have nested For statements, you can pass the For keyword the variable that controls the loop you want to exit. For example, if you are testing all the elements of a two-dimensional array with nested For statements, you can use the loop variable for the outermost loop to exit at that point.
 
For i= 0 to 255
   For j= 0 to 255

     If myArray(i,j) = 23 then
       Exit For i
     End if
   Next
Next

Exp

Exp( Double) As Double

Returns “e” to the power of the value specified.

Dim d as Double

d=Exp(10) //returns 22026.4657948

Floor

Floor( Double) As Double

Returns the value specified rounded down to the nearest Integer.

Dim d as Double

d=Floor(1.234) //returns 1

For...Next

For…Next

Executes a series of statements a specified number of times. The For Each…Next statement is a variation that executes once for each element of a one-dimensional array.

The counter variable in a For statement can be declared inside the For statement rather than externally, as a local variable. For example, the code:

Dim i as Integer

For i=0 to 10
    //your code goes here
Next

The following example uses the DownTo keyword to decrement the counter:

Dim i as Integer

For i=5 DownTo 1 Step 1
   Beep
Next

Format

Format (Double, String) As String

Returns as a String a formatted version of the number passed based on the parameters specified. The Format function is similar to the way spreadsheet applications format numbers. Format will use the information based on the user's locale even if the user's locale is a Unicode-only locale.

Syntax

result = Format( number, formatSpec )

The formatSpec is a string made up of one or more special characters that control how the number will be formatted:

Character Description
# Placeholder that displays the digit from the value if it is present.If fewer placeholder characters are used than in the passed number, then the result is rounded.
0 Placeholder that displays the digit from the value if it is present.If no digit is present, 0 (zero) is displayed in its place.
. Placeholder for the position of the decimal point.
, Placeholder that indicates that the number should be formatted with thousands separators.
% Displays the number multiplied by 100.
( Displays an open paren.
) Displays a closing paren.
+ Displays the plus sign to the left of the number if the number is positive or a minus sign if the number is negative.
- Displays a minus sign to the left of the number if the number is negative. There is no effect for positive numbers.
E or e Displays the number in scientific notation.
\characterDisplays the character that follows the backslash.

The absolute value of the number is displayed. You must use the + or - signs if you want the sign displayed.

Although the special formatting characters are U.S. characters, the actual characters that will appear are based on the current operating system settings. For example, Windows uses the settings in the user's Regional and Language Options Control Panel. Formatting characters are specified in similar ways on other operating systems.

The formatSpec can be made up of up to three formats separated by semicolons. The first format is the format to be used for positive numbers. The second format is the format to be used for negative numbers and the third format is the format to be used for zero.

The following are several examples that use the various special formatting characters.

Format Number Formatted String
#.## 1.786 1.79
#.0000 1.3 1.3000
0000 5 0005
#% 0.25 25%
###,###.##145678.5145,678.5
#.##e 145678.51.46e+5
-#.## -3.7 -3.7
+#.## 3.7 +3.7
#.##;(#.##);\z\e\r\o3.73.7
#.##;(#.##);\z\e\r\o-3.7(3.7)
#.##;(#.##);\z\e\r\o0zero

The following example returns the number 3560.3 formatted as $3,560.30.

Dim s as String

s=Format(3560.3, "\$###,##0.00")

FramecodeToTimecode

returns a string that contains a Timecode in the format “hh-mm-ss-ff”. The function needs two parameters, the framecode and the number of frames per second. The following example converts a framecode to a timecode with 25 fps.

dim tc as string
tc = FramecodeToTimecode(123456,25)

GetDayOfMonth

Returns the day of the current month (1..31)
Result integer

GetDayOfWeek

Result integer (Sunday=0, Monday = 1…)

GetHour

Result integer

GetYear

Result integer

GetMinute

Result integer

GetMonth

Result integer

GetSeconds

Result integer

Hex

Hex (Integer) As String

Returns as a String the hexadecimal version of the number passed.

If the value is not a whole number, the decimal value will be truncated.

You can specify binary, hex, or octal numbers by preceding the number with the & symbol and the letter that indicates the number base. The letter b indicates binary, h indicates hex, and o indicates octal.

Dim hexVersion As String

hexVersion=Hex(5) //returns "5"
hexVersion=Hex(75) //returns "4B"
hexVersion=Hex(256) //returns "100"

HexToStr

HexToStr (String) As String

Returns as a String hexadecimal numbers converted to string

dim s as string

s = HexToStr("414243")  
   // Returns "ABC", because "A" has ASCII code &h41 or 65 decimal,
   //         "B" has ASCII code &h42 or 66 decimal etc.

If...Then...Else

If…Then…Else

Conditionally executes a group of statements, depending on the value of a Boolean expression.

When executing an If statement, the condition is tested. If condition is True, the statements associated with the If statement following the Then statement are executed. If condition is False and an Else clause follows, its statements will be executed. If condition is False and there is no Else clause or it is preceded by an ElseIf statement, the condition following the ElseIf statement is tested. After executing the statements following Then, ElseIf or Else execution continues with the statement that follows End If.

If error=-123 Then
 Beep
 MsgBox "Whoops! An error occured."
End If
Dim theNumber As Integer
Dim digits As Integer

theNumber=33
If theNumber<10 Then
   digits=1
ElseIf theNumber<100 Then
   digits=2
ElseIf theNumber<1000 Then
   digits=3
Else
   digits=4
End If

InStr

InStr (Integer, String, String) As Integer

Returns the position of the first occurrence of a String inside another String. The first character is numbered 1.

 
Dim first As Integer

first = InStr("This is a test", "t")     //returns 1
first = InStr("This is a test", "is")    //returns 3
first = InStr(4, "This is a test", "is") //returns 6
first = InStr("This is a test", "tester")//returns 0

InStrB

InStrB (Integer, String, String) As Integer

If the find string is not found within the source string, 0 (zero) is returned. InStrB is case-sensitive; it treats source as a series of raw bytes. It should be used instead of InStr when the string represents binary data or when your application will run in a one-byte character set (such as the US system) and you want case-sensitivity.

Dim first As Integer

first = InStrB("This is a test", "T")     //returns 1
first = InStrB("This is a test", "t")     //returns 11
first = InStrB("This is a test", "is")    //returns 3
first = InStrB(4, "This is a test", "is") //returns 6
first = InStrB("This is a test", "tester")//returns 0
first = InStrB("This Is a test", "Is")    //returns 6

Left

Left (String, Integer) As String

Returns the first n characters in a source String.

Dim s As String

s=Left("Hello World", 5) //returns "Hello"
s="Hello World"
s=s.Left(5) //returns "Hello"

LeftB

LeftB (String, Integer) As String

Returns the first n bytes in a source String.

The LeftB function returns bytes from the source string starting from the left side (as the name implies). If you need to read characters rather than bytes, use the Left function.

This example uses the LeftB function to return the first 5 bytes from a string.

Dim s As String
s=LeftB("Hello World", 5) //returns "Hello"
 
s="Hello World"
s=s.LeftB(5) //returns "Hello"

Len

Len (String) As Integer

Returns the number of characters in the specified String.

Dim n As Integer
n=Len("Hello world") //returns 11
 
Dim s as String
s="Hello World"
n=s.Len //returns 11

LenB

LenB (String) As Integer

Returns the number of characters in the specified String.

LenB treats string as a series of bytes, rather than a series of characters. It should be used when string represents binary data. If you need to know the number of characters in string rather than the number of bytes, use the Len function.

Log

Log (Double) As Double

Returns the natural logarithm of the value specified.

Dim d As Double
d=Log(10) //returns 2.3025851

Lowercase

Lowercase (String) As String

Converts all characters in a String to lowercase characters.

Dim s As String
s=Lowercase("tHe Quick fOX") //returns "the quick fox"
s=Lowercase("THE 5 LAZY DOGS") //returns "the 5 lazy dogs"
 
s="tHe Quick fOX"
s=s.Lowercase /returns "the quick fox"

LTrim

LTrim (String) As String

Returns the String passed with leading (left side) whitespaces removed.

Dim s as String
s=LTrim(" Hello World ")
//Returns "Hello World "
s=" Hello World "
s=s.LTrim //Returns "Hello World "

Max

Max (Double, Double) As Double

Returns the largest value passed to it.

Dim d As Double

d=Max(3.01, 4.05) //returns 4.05
d=Max(3.012, 3.011, 1.56) //returns 3.012

Microseconds

Microseconds As Double

Returns the number of microseconds (1,000,000th of a second) that have passed since the user's computer was started.

Dim minutes As Integer

minutes=Microseconds/1000000/60
MsgBox "Your computer has been on for "+ Str(minutes)+" minutes."

Because modern operating systems can stay running for so long, it's possible for the machine's internal counters to “roll over.” This means that if you are using this function to determine how much time has elapsed, you may encounter a case where this time is inaccurate.

Mid

Mid (String, Integer, Integer) As String

Returns a portion of a String. The first character is numbered 1.

Dim s As String

s = Mid("This is a test", 6) //returns "is a test"
s = Mid("This is a test", 11, 4) //returns "test"

s="This is a test"
s=s.Mid(11,4) //returns "test"

MidB

MidB (String, Integer, Integer) As String

Returns a portion of a String. The first character is numbered 1.

Dim s As String

s=MidB("This is a test", 6) //returns "is a test"
s=MidB("This is a test", 11, 4) //returns "test"
 
s="This is a test"
s=s.MidB(11,4) //returns "test"

MidB treats source as a series of bytes, rather than a series of characters. MidB should be used when source represents binary data. If you need to extract characters rather than bytes, use the Mid function. To determine the number of bytes in a String, use the LenB function.

Min

Min (Double, Double) As Double

Returns the smallest of the numbers passed.

Dim d As Double

d=Min(3.01, 4.05) //returns 3.01
d=Min(3.012, 3.011) //returns 3.011

Nil

Nil

Used to determine if an object is nil (no value).

NthField

NthField (String, String, Integer) As String

Returns a field from a row of data. The first field is numbered 1. If you need to parse binary data, use NthFieldB instead.

This example returns “Smith”

Dim field As String
field=NthField("Dan*Smith*11/22/69*5125554323*Male","*",2)

Oct

Oct (Integer) As String

Returns as a String, the octal version of the number passed.

Dim OctVersion As String

OctVersion=Oct(5) //returns "5"
OctVersion=Oct(75) //returns "113"
OctVersion=Oct(256) //returns "400"

Pow

Pow (Double, Double) As Double

Returns the value specified raised to the power specified.

This example uses the Pow function to return four raised to the power of seven.

Dim d As Double
d=Pow(4,7) //returns 16384

Redim

Redim Array(x,y)

Resizes the passed array.

This example reduces the aNames array to 11 elements.

Redim aNames(10)

This example adds 10 elements to the aNames array

Redim aNames( Ubound(aNames)+10)

This example reduces the aPeople array to 11 elements for the first dimension and 6 elements for the second dimension

Redim aPeople(10,5)

The Redim method is used to increase or reduce the number of elements in the array specified. Arrays are zero-based (the first element is zero) so you resize the array using a number that is one less than the number of elements you actually want. The number of parameters passed is the number of dimensions of the array being resized.

Rem

Rem any comment

Used to add comments to your code.

Replace

Replace (String, String, String) As String

Replaces the first occurrence of a String with another String.

Dim result As String

result=Replace("The quick fox","fox","rabbit") //returns "The quick rabbit"
result=Replace("The quick fox","f","b") //returns "The quick box"
result=Replace("The quick fox","quick","") //returns "The fox"

ReplaceB

ReplaceB (String, String, String) As String

Replaces the first occurrence of oldString in sourceString with newString. ReplaceB is the byte version of Replace.

  • If newString is an empty string (“”), the ReplaceB function deletes the first occurrence of the oldString in the sourceString.
  • If oldString is an empty string (“”), the ReplaceB function returns an unchanged copy of the sourceString.

ReplaceB is case-sensitive; it treats sourceString as a series of raw bytes. It should be used instead of Replace when the string represents a series of bytes or when your application will run in a one-byte character set (such as the US system) and you want case-sensitivity.

ReplaceAll

ReplaceAll (String, String, String) As String

Replaces all occurrences of a String with another String.

Dim result As String

result=ReplaceAll("xyxyxy","x","z") //returns "zyzyzy"
result=ReplaceAll("The quick fox"," ","") //returns "Thequickfox"
 
result="The Quick Fox"
result=result.ReplaceAll(" ",",") //returns "The,Quick,Fox"

ReplaceAllB

ReplaceAllB (String, String, String) As String

The ReplaceAllB function replaces all occurrences of oldString in sourceString with newString. ReplaceAllB is case-sensitive because it treats the source string as a series of raw bytes.

  • If newString is an empty string (“”), the ReplaceAllB function deletes every occurrence of the oldString in the sourceString.
  • If oldString is an empty string (“”), the ReplaceAllB function returns an unchanged copy of the sourceString.

ReplaceAllB is case-sensitive; it treats sourceString as a series of raw bytes. It should be used instead of ReplaceAll when the string represents a series of bytes or when your application will run in a one-byte character set (such as the US system) and you want case-sensitivity.

Right (String, Integer) As String

Returns the last n characters from the String specified.

Dim s As String
s=Right("Hello World", 5) //returns "World"
 
s="Hello World"
s=s.Right(5) //returns "World"

RightB

RightB (String, Integer) As String

The RightB function returns bytes from the source string starting from the right side (as the name implies). RightB treats source as a series of bytes rather than a series of characters. It should be used when source represents binary data. If you need to read characters rather than bytes, use the Right function.

Rnd

Rnd As Double

Returns a randomly generated number in the range 0 ⇐ Rnd < 1. The equivalent functionality is provided by the Random class as a special case. The Random class also provides additional options, such as a random number selected from a Normal distribution.

Round

Round (Double) As Double

Returns the value specified rounded to the nearest Integer.

Dim d as Double

d=Round(1.499) //returns 1
d=Round(1.500) //returns 2

RTrim

RTrim (String) As String

Returns the String data type passed with trailing (right side) whitespaces removed.

Dim s as String
s=RTrim(" Hello World ") //Returns " Hello World"
 
s=" Hello World "
s=s.RTrim //Returns " Hello World"

Rtrim uses the list of unicode “whitespace” characters at http://www.unicode.org/Public/UNIDATA/PropList.txt.

Select Case

Select Case

Executes one of several groups of statements, depending on the value of an expression.

The Select Case statement is useful when there are several possible conditions that must be checked. Unlike an If statement, the Select Case statement will exit as soon as it finds a matching Case expression and executes any statements that follow the Case expression up to the next Case expression. If there are no Case expressions that match, the elseStatements are executed. The expression Case Else can be used as a synonym for Else. The Case statement can accept several types of expressions. The expression can be a single value, a comma-delimited list of values, a function that returns a value, a range of values specified with the 'To“ keyword, or an expression that uses the “Is” keyword to do an equality or inequality test. You can combine types of expressions, separating them by commas Here are some examples:

Case 2, 4, 6, 8 //several values
Case 2 To 5 //range of values using To
Case 2 To 5, 7,9,11 //Both separate values and range
Case myFunction(x) // a Function
Case Is >= 42 // greater than/equal to operator
Case Is <19 //less than operator
Dim d as New MessageDialog //declare the MessageDialog object
Dim b as MessageDialogButton //for handling the result

d.icon= MessageDialog.GraphicCaution //display warning icon
d.ActionButton.Caption="Save"
d.CancelButton.Visible= True //show the Cancel button
d.CancelButton.Cancel= True//esc key works for Cancel
d.AlternateActionButton.Visible= True //show the "Don't Save" button
d.Message="Save changes before closing?"
d.Explanation="If you don't save your changes, you will lose " _
+"all that important work you did since your last coffee break."
b=d.ShowModal //display the dialog
Select Case b //b is a MessageDialogButton
Case d.ActionButton //determine which button was pressed.
//user pressed Save
Case d.AlternateActionButton
//user pressed Don't Save
Case d.CancelButton
//user pressed Cancel
End Select

Sin

Sin (Double) As Double

Returns the sine of the value specified.

Dim d As Double
Const PI=3.14159265358979323846264338327950
d=Sin(0.5) //returns 0.4794255
d=Sin(30*PI/180) //returns .5

Sqrt

Sqrt (Double) As Double

Returns the square root of the value specified.

Dim d As Double
d=Sqrt(16) //returns 4

Str

Str (Double) As String

Returns the String form of the value passed.

Dim s As String

s=Str(123) //returns "123"
s=Str(-123.44) //returns "-123.44"
s=Str(123.0045) //returns "123.0045"
Const Pi=3.14159265358979323846264338327950
s= Str(pi) // returns "3.141593"
s= Str(3141592653589012345) // returns "3141592653589012345"

StrComp

StrComp (String, String, Integer) As Integer

Makes a binary (case-sensitive) or text (lexicographic) comparison of the two strings passed and returns the result.

The following example returns -1 because the two strings are the same in every way except in case.

StrComp(“Spam”, “spam”, 1)

The following example returns -1 because in a text comparison of the two strings, string2 is greater than string1. The ASCII value of “s” is greater than the ASCII value of “S”.

StrComp(“Spam”, “spam”, 0)

StrToHex

StrToHex (String) As String

Returns a String of hexadecimal numbers

dim s as string

s = HexToStr("ABC")  
// Returns "414243", because "A" has ASCII code &h41 or 65 decimal,
//         "B" has ASCII code &h42 or 66 decimal etc.

Tan

Tan (Double) As Double

Returns the tangent of the angle specified.

Dim d As Double
Const PI=3.14159265358979323846264338327950
d=Tan(45*PI/180) //returns 1.0

Ticks

Ticks as Integer

Returns the number of ticks (60th of a second) that have passed since the user's computer was started.

Dim minutes As Integer
minutes=Ticks/60/60
MsgBox "Your computer has been on for"+ Str(minutes)+" minutes."

Because modern operating systems can stay running for so long, it's possible for the machine's internal counters to “roll over.” This means that if you are using this function to determine how much time has elapsed between two events, you may encounter a case where it appears that the stop time is prior to the start time.

Titlecase

Titlecase (String) As String

Returns the String passed to it with all alphabetic characters in Titlecase.

Dim s As String
s=Titlecase("tHe Quick fOX") //returns "The Quick Fox"
s=Titlecase("THE LAZY DOG") //returns "The Lazy Dog"

Trim

Trim (String) As String

Returns the String passed with leading and trailing whitespaces removed.

Dim s as String
s=Trim(" Hello World ") //Returns "Hello World"

Ubound

Ubound (array) As Integer

Returns the index of the last element in an array.

The Ubound function can be used to determine the last element of an array, but it can also be used to determine the size of an array. It may appear at first that the last element number and the size of the array are the same but in fact they are not. All arrays have a zero element. In some cases element zero is used and in other cases it is not. You will need to keep this in mind when using the Ubound function to determine the number of values you have in the array. If the array is zero-based, then element zero is used to store a value and you will have to add one to the value returned by the Ubound function to make up for it.

This example replaces each occurrence of X in an array with Y.

Dim i As Integer
For i=0 to Ubound(Names)
 If Names(i)="X" Then
    Names(i)="Y"
 End If
Next

Uppercase

Uppercase (String) As String

Converts all characters in a String to uppercase characters.

Dim s As String
s=Uppercase("tHe Quick fOX") //returns "THE QUICK FOX"
s=Uppercase("the 5 lazy dogs") //returns "THE 5 LAZY DOGS"

Val

Val (String) As Double

Returns the numeric form of a String.

Dim n As Integer
n = Val("12345") //returns 12345
n = Val(" 12345") //returns 12345
n = Val("123 45") //returns 123
n = Val(" &hFFF") //returns 4095
n = Val(" &b1111") //returns 15

The Val function stops reading the String at the first character it doesn't recognize as part of a number. All other characters are automatically stripped. It does recognize prefixes &o (octal), &b (binary), and &h (hexadecimal). However, spaces are not allowed in front of the ampersand. That is, ” &hFF“ returns 0, but ” &hFF“ returns 255. The CDbl function is the same as the Val function but is used when you need to pass a String that uses a character other than the period (.) as the decimal separator. It uses the decimal character specified by the operating system. For example, on Windows XP, it is set in the Regional and Language Options Control Panel. Val should generally be used to convert internal data, but not data entered by the user. Val is not international-savvy, but CDbl is. The CStr function is the same as the Str function but is used when you need to pass a number that uses a character other than the period (.) as the decimal separator. It uses the decimal character specified by the operating system. Val returns zero if string contains no numbers.

language_reference.txt · Last modified: 2016/11/16 08:17 by admin