array() creates an array and returns it as a variant.
option explicit
sub main() ' {
dim ary as variant
ary = array("zero", "one", "two", "three", "four", "five")
dim i as long
for i = lBound(ary) to uBound(ary)
debug.print i & ": " & ary(i)
next i
end sub ' }
'
' 0: zero
' 1: one
' 2: two
' 3: three
' 4: four
' 5: five
option explicit
sub main() ' {
dim fOne, fTwo, fThree as integer
fOne = openFile(environ("TEMP") & "\one.txt" )
fTwo = openFile(environ("TEMP") & "\two.txt" )
fThree = openFile(environ("TEMP") & "\three.txt")
print# fOne , "This is file one"
print# fTwo , "This is file two"
print# fThree, "This is file three"
close# fOne
close# fTwo
close# fThree
end sub ' }
function openFile(fileName as string) ' {
'
' Open a file, use freeFile to determine next
' file number
'
dim fn as integer
fn = freeFile()
open fileName for output as #fn
openFile = fn
end function ' }
isEmpty can be used to determine if a variant was initialized. On other datatypes, this seems not possible (or probably more accurately, they are automatically initialized).
The following example displays that the variant variable is empty but the others are not.
sub testIsEmpty()
dim varVariant as variant
dim varLong as long
dim varObject as object
if isEmpty(varVariant) then
debug.print "varVariant is empty"
else
debug.print "varVariant is not empty"
end if
if isEmpty(varLong) then
debug.print "varLong is empty"
else
debug.print "varLong is not empty"
end if
if isEmpty(varObject) then
debug.print "varObject is empty"
else
debug.print "varObject is not empty"
end if
end sub
rtrim removes trailing spaces on a string's right side:
sub main()
dim txt as string
txt = " foo bar baz "
debug.print "txt: >" & txt & "<"
'
' Traim trailing spaces on the right side:
'
txt = rTrim(txt)
debug.print "txt: >" & txt & "<"
end sub
callByName gets or sets an object's property or executes an object's method. The name of the property or method are dynamic (i.e. might be stored in a variable.
curDir() returns a variant whose underlying type is a string that stores the current directory. By default, this directory seems to be C:\Users\username\Documents.