Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

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 = Ccur(expression)

Description

Converts any expression to a Currency.

Example

Display the value(100.44556677) of a String converted into a Currency value.

Sub Ccur_test()

 I$ = "100.44556677"

 MsgBox "The currency value is: "& Ccur(I$)

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]

 [statements]

Next [Counter [,nextcounter]…]

Description

Repeats a block of statements a specified number of times, incrementing a loop counter by a given increment each time through the loop.

Example

Sub ForCount_test()

 Dim M As String

 For X = -1 To 0

 For Y = -1 To 0

 Z = X Or Y

 M = M & Format(Abs(X), "0") & " Or"

 M = M & Format(Abs(Y), "0") & " ="

 M = M & Format(Z, "True/False") & Basic.Eoln$

 Next Y

 Next X

 MsgBox M

End Sub

Subroutine

Script

For Each member in group

 [statements]

 [Exit For]

 [statements]

Next [member]

Description

Repeats a block of statements for each element in a collection or array.

Example

Sub ForEach_test()

 Dim A(3 to 10) As Single

 Dim I As Variant

 Dim S As String

 For I = 3 To 10

 A(I) = Rnd()

 Next I

 For Each I In A

 I = I + 1

 Next I

 For Each I In A

 If S <> "" Then S = S & ","

 S = S & I

 Next I

 MsgBox S

End Sub

Subroutine

Script

GoSub label

Description

Causes execution to continue at the specified label.

Example

Sub GoSub_test()

 Uname$ = Ucase$(Inputbox$("Enter your name:","Enter Name"))

 Gosub CheckName

 MsgBox "Hello, " & Uname$

 Exit Sub

CheckName :

 If (Uname$ = "") Then

 GoSub BlankName

 Elseif Uname$ = "MICHAEL" Then

 GoSub RightName

 Else

 GoSub OtherName

 End If

 Return

BlankName :

 MsgBox " No name? Clicked Cancel? I’m shutting down"

 Exit Sub

RightName :

 Return

OtherName:

 MsgBox "I am renaming you MICHAEL!"

 Uname$ = "MICHAEL"

 Return

End Sub

Subroutine

Script

Goto label

Description

Transfers execution to the line containing the specified label.

Example

Sub Goto_test()

 Uname$ = Ucase$(Inputbox$("Enter your name:","Enter Name"))

 If Uname$ = "MICHAEL" Then

 Goto RightName

 Else

 Goto WrongName

 End If

WrongName :

 If (Uname$ = "") Then

 MsgBox " No name? Clicked Cancel? I’m shutting down"

 Else

 MsgBox "I am renaming you MICHAEL!"

 Uname$ = "MICHAEL"

 Goto RightName

 End If

 Exit Sub

RightName :

 MsgBox "Hello, MICHEAL!"

End Sub

Subroutine

Script

  1. If condition Then statements [Else else_statements]

  1. If condition Then

 [statements]

 [ElseIf else_condition Then

 elseif_statements]]

 [Else

 [else_statements]]

End If

Description

Conditionally executes a statement or group of statements.

Example

Sub If_test()

 Uname$ = Ucase$(Inputbox$("Enter your name:","Enter Name"))

 If Uname$ = "MICHAEL" Then GoSub MikeName

 If Uname$ = "MIKE" Then

 GoSub MikeName

 Exit Sub

 End If

 

 If Uname$ = "" Then

 MsgBox "Since you don’t have a name, I’ll call you Mike!"

 Uname$ = "MIKE"

 GoSub MikeName

 ElseIf Uname$ = "MICHAEL" Then

 GoSub MikeName

 Else

 GoSub OtherName

 End If

 Exit Sub

MikeName :

 MsgBox "Hello, MICHAEL!"

 Return

OtherName:

 MsgBox "Hello," & "Uname$" & "!"

 Return

End Sub

Function

Script

Iif(expression, truepart, falsepart)

Description

Returns true part if the condition is True; otherwise, returns false part.

Example

Sub Iif_test()

 S$ = "Car"

 MsgBox Iif(S$ = " Car", "Nice Car", "Nice Automobile")

End Sub

Subroutine

Script

Sub Main()

End Sub

Description

Defines the subroutine where execution begins.

Example

Sub Main()

 MsgBox "This is the Main() subroutine and entry point"

End Sub

Subroutine

Script

Return

Description

Transfers execution control to the statement following the most recent GoSub.

Example

Sub Return_test()

 GoSub SubTrue

 MsgBox "The Main routine continues here"

 Exit Sub

SubTrue:

 MsgBox "This message is generated in the subroutine."

 Return

 Exit Sub

End Sub

Subroutine

Script

Select Case testexpression

[Case expressionlist

 [statement_block]]

[Case expressionlist

 [statement_block]]

[Case Else

 [statement_block]]

End Select

Description

Used to execute a block of statements depending on the value of a given expression.

Example

The statement outputs the current operating system.

Sub Select_test()

 OpSystem% = Basic.OS

 Select Case OpSystem%

 Case 0,2

 S = "Microsoft Windows"

 Case 3, 8, 12

 S = "UNIX"

 Case 10

S = "IBM OS/2"

 Case Else

 S = "Other"

 End Select

 MsgBox :This version of BasicScript is running on:" & S

End Sub

Subroutine

Script

Sleep(milliseconds)

Description

Causes the script to pause for a specified number of milliseconds.

Example

Sub Sleep_test()

 Msg.Open "Waiting 2 seconds", 0, False, False

 Sleep (2000)

 Msg.Close

End Sub

Subroutine

Script

Stop

Description

Suspends execution of the current script, returning control to a debugger if one is present. If a debugger is not present, this command will have the same effect as End.

Example

Sub Stop_test()

 For X = 1 To 10

 Z = Random(0,10)

 If Z = 0 Then Stop

 Y = X / Z

 Next X

End Sub

Function

Script

n = Switch (condition1, expression1 [,condition2, expression2 … [, condition7, expression7]])

Description

Returns the expression corresponding to the first True condition.

Example

The statement outputs the current operating system.

Sub Switch_test()

 Dim A As Variant

 A = Switch(Basic.OS = 0, "Windows 3.1", Basic.OS = 2, "Win32", Basic.OS = 11, "OS/2")

 MsgBox "The current platform is: " & Iif(IsNull(A), "Unknown", A)

End Sub

Subroutine

Script

While condition

 [statements]

Wend

Description

Repeats a statement or group of statements while a condition is True.

Example

Sub While_test()

 X% = 0

 Count% = 0

 While X% <> 1 And Count% < 500

 X% = Rnd(1)

 If Count% > 1000 Then

 Exit Sub

 Else

 Count% = Count% + 1

 End If

 Wend

 MsgBox "The loop executed " & Count% & " times."

End Sub

Function

Script

n = Date[$][()]

Description

Returns the current system date.

Example

Const crlf = Chr$(13) + Chr$(10)

Sub Date_test()

 Date$ = "01/01/95"

 MsgBox "Saved date is : " & TheDate$ & crlf & "Changed date is : & Date$()"

 Date$ = TheDate$

 MsgBox "Restored date to: " & TheDate$

End Sub

Function

Script

Date$ [= newdate]

Description

Sets the system date to the specified date.

Example

Const crlf = Chr$(13) + Chr$(10)

Sub Date_test()

 Date$ = "01/01/95"

 MsgBox "Saved date is : " & TheDate$ & crlf & "Changed date is : & Date$()"

 Date$ = TheDate$

 MsgBox "Restored date to: " & TheDate$

End Sub

Function

Script

n = DateAdd(interval, number, date)

Description

Returns a Date variant representing the sum of date and a specified number of time intervals.

Example

Sub DateAdd_test()

 Dim sdate$

 Sdate$ = Date$

 NewDate# = DateAdd("yyyy",4,Sdate$)

 NewDate# = DateAdd("m",3,NewDate#)

 NewDate# = DateAdd("ww",2,NewDate#)

 NewDate# = DateAdd("d",1,NewDate#)

 S$ = "Four years ,three months, two weeks,"

 S$ = S$ + " and one day from now will be:"

 S$ = S$ & Format("NewDate#”, "long date")

 MsgBox S$

End Sub

Function

Script

n = DateDiff(interval, date1, date2 [, [firstdayofweek] [,firstweekofyear[]]

Description

Returns a Date variant representing the number of given time intervals between date 1 and date 2.

Example

Sub DayDiff_test()

 Today$ = Format(Date$,"Short Date")

 NextWeek = Format(DateAdd("d", 14, today$), "Short Date")

 DifDays# = DateDiff("d", Today$, NextWeek)

 DifWeek# = DateDiff("w", Today$, NextWeek)

 S$ = "The difference between " & Today$ & " and " & NextWeek

 S$ = S$ & " is: " & DifDays# & "Days or" & DifWeek# & "Weeks"

 MsgBox s$

End Sub

Function

Script

n = DatePart(interval, date[, [firstdayofweek] [,firstweekofyear[]]

Description

Returns an Integer representing a specific part of a date/time expression.

Example

Const crlf = Chr$(13) + Chr$(10)

Sub DatePart_test()

 Today$ = Date$

 Qtr = DatePart("q", Today$)

 Yr = DatePart("yyyy", Today$)

 Mo = DatePart("m", Today$)

 Wk = DatePart("ww", Today$)

 Da = DatePart("d", Today$)

 S$ = "Quarter: " & Qtr & crlf

 S$ = S$ & "Year: " & Yr & crlf

 S$ = S$ & "Month: " & Mo & crlf

 S$ = S$ & "Week: " & Wk & crlf

 S$ = S$ & "Day: " & Da & crlf

 MsgBox S$

End Sub

Function

Script

n = DateSerial(year, month, day)

Description

Returns a Date variant representing the specified date.

Example

Sub DateSerial_test()

 Tdate# = DateSerial(1993,08,22)

 MsgBox "The DateSerial Value for august 22,1993, is: " & Tdate#

End Sub

Function

Script

n = DateValue(date)

Description

Returns a Date variant representing the date contained in the specified string argument.

Example

Sub DateValue_test()

 Tdate# = Date$

 Tday = DateValue(Tdate#)

 MsgBox Tdate & " date value is: " & Tday

End Sub

Function

Script

n = Day(date)

Description

Returns the day of the month specified by date.

Example

Const crlf = Chr$(13) + Chr$(10)

Sub Day_test()

 CurDate = Now()

 MsgBox "Today is day" & Day(CurDate) & "of the monthy." & crlf & "Tomorrow is day" & Day(CurDate +1)

End Sub

Function

Script

n = Hour(time)
n = Minute(time)
n = Second(time)

Description

Returns the hour/minute/second of the day encoded in the specified time parameter.

Example

Sub HMS_test()

 Xt# = TimeValue(Time$())

 Xh# = Hour(Xt#)

 Xm# = Minute(Xt#)

 Xs# = Second(Xt#)

 MsgBox "The current time is:" & Xh# & ":" & Xm# & ":" & Xs#

End Sub

Function

Script

n = Month(date)

Description

Returns a number that represents the month of the year.

Example

Sub Month_test()

 Mons$ = "Jan., Feb., Mar., Apr., May, Jun., Jul., Aub., sep., Oct., Nov., Dec."

 Tdate$ = Date$

 Tmonth! = Month(DateValue(tdate$))

 MsgBox "The current month is:" & Item$(mons$, Tmonth!)

End Sub

Function

Script

n = Year(date)

Description

Returns a number that represents the year.

Example

Sub Year_test()

 Tdate$ = Date$

 Tyear = Year(DateValue(Tdate$))

 MsgBox Tdate & " date value is: " & Tyear

End Sub

Function

Script

n = Now()

Description

Returns a Date variant representing the current date and time.

Example

Sub Now_test()

T1$ = Now()

MsgBox "Wait a while and click OK."

T2$ = Now()

T3$ = Second(T2$)
  T3$ = T3$ - Second(T1$)

  MsgBox "The elapsed time: " & T3$ &" seconds."

End Sub

Function

Script

n = Time$[()]

Description

Returns the system time as a String or as a Date variant.

Example

Const crlf = Chr$(13) + Chr$(10)

Sub Main()

 Oldtime$ = Time$

   temp = " Time was : " & Oldtime$ & crlf

   Time$ = "10:30:54"

   temp = temp & "Time set to: " & Time$ & crlf

   Time$ = Oldtime$

   temp = temp & "Time restored to: " & Time$

   MsgBox temp

End Sub

Function

Script

n = Timer

Description

Returns the number of seconds that have elapsed since midnight.

Example

Sub timer_test()

    Start& = Timer

   MsgBox "Click the OK button, please."

   Total& = Timer

 Total& = Total& - Start&

   MsgBox "the elapsed time was: " & Total& & "seconds."

End Sub

Function

Script

n = TimeSerial(hour, minute, Second)

Description

Returns the time for a specific hour, minute, and second.

Example

Sub TimeSerial_test()

 Start# = TimeSerial(10,22,30)

 Finish# = TimeSerial(10, 35,27)

 Dif# = Abs(Start# - Finish#)

 MsgBox "The time difference is : " & Format(Dif#, "hh:mm:ss")

End Sub

Function

Script

n = TimeValue(time)

Description

Returns a Date variant representing the time contained in the specified string argument.

Example

Sub TimeValue_test()

 T1$ = "10:15"

 T2# = TimeValue(T1$)

 MsgBox "The TimeValue of " & T1$ & " is: " & T2#

End Sub

Function

Script

Close [[#] filenumber [,[#] filenumber]…]

Description

Closes the specified files.

Example

Sub Close_test()

 Open "test1" For Output As #1

 Open "test2" For Output As #2

 Open "test3" For Random As #3

 Open "test4" For Binary As #4

 MsgBox "The next available file number is :" & FreeFile()

 Close #1

 Close #2, #3

 MsgBox "The next available file number is :" & FreeFile()

End Sub

Function

Script

EOF (filenumber)

Description

Returns True if the end-of-file has been reached for the given file; returns False otherwise.

Example

Const crlf = Chr$(13) + Chr$(10)

Sub EOF_test()

 Dim S$

 Open "C:\autoexec.bat" For Input As #1

 Do While Not EOF(1)

 Input #1, S$

 Loop

 Close

 MsgBox "The last line was:" & crlf & S$

End Sub

Function

Script

n = FreeFile[(rangenumber)]

Description

Returns an Integer containing the next available file number.

Example

Sub FreeFile_test()

 A = FreeFile

 MsgBox "The next free file number is: " & A

End Sub

Subroutine

Script

Print [#]filenumber, [[{Spc(n) | Tab(n)}] [expressionlist] [{;|,}]]

Description

Writes data to a sequential disk file.

The argument can be used up to 30.

Example

Sub Print_test()

 Open "test.dat" for Output As #1

 I% = 10

 S$ = "This is a test"

 Print #1, "The value of I = "; I%, "the value of S=";S$

 Print #1, I%,, S$

 Print #1, I%; Spc(10); S$

 Print #1, I%; Tab(30); S$

 Print #1,I%;S$

 Print #1 , 67

 Close #1

 Kill "test.dat"

End Sub

Subroutine

Script

Put [#]filenumber, [recordnumber], variable

Description

Writes data from the specified variable to a Random or Binary file.

Example

Sub put_test()

   Open "test.dat" For Random Access Write As #1

   For X = 1 To 10

       R% = X * 10

       Put #1, X, R%

   Next X  

   Close

   Open "test.dat" For Random Access Read As #1

   For X = 1 to 10

       Get #1, X, R%

       temp = temp & "Record" & X & "is : " & R% & Basic.Eoln$

   Next X

   MsgBox temp

   Close

   Kill "test.dat"

End Sub

Subroutine

Script

Reset

Description

Closes all open files, writing out all I/O buffers.

Example

Sub Reset_test()

Open "test.dat" For Output Access Write As #1

Reset

Kill "test.dat"

If FileExists("test.dat") Then

MsgBox "The file was not deleted"

Else

MsgBox "The file was deleted"

End If

End Sub

Function

Script

n = Seek(filenumber)

Description

Returns the position of the file pointer in a file relative to the beginning of the file.

Example

Sub Seek_test()

Open "test.dat" For Random Access Write As #1

For X = 1 To 10

R% = X * 10

 Put #1,X,R%

 Next X

 Y = Seek(1)

MsgBox "The current file position is: " &Y

 Close

End Sub

Subroutine

Script

Write [#]filenumber [expressionlist]

Description

Writes a list of expressions to a given sequential file.

Example

Write 10 records into the file and close the file after output the contents.

Sub Write_test()

 Open "test.dat" For Output Access Write As #1

 For X = 1 To 10

 R% = X * 10

 Write #1, X, R%

 Next X

 Close

 Open "test.dat" For Input Access Read As #1

 For X = 1 To 10

 Input #1, A%,B%

 temp = temp & "Record " & A% & ":" & B% & Basic.Eoln$

 Next X

 MsgBox temp

 Close

End Sub

 

  • No labels