User Tools

Site Tools


lrbuiltins

Table of Contents

Builtin Functions

A builtin functions is a predefined function, which has a special meaning for KBasic and which meaning cannot be changed. Many of them are provided for VB6 and QBasic backward compatibility. The following list contains all KBasic builtin functions.

Abs , Access , Acs , AddDays , AddHandler , AddHours , AddMinutes , AddMonths , AddSeconds , AddYears , AppActiviate , Append , Array , Asc , Asn , Atn , Beep , Bin , Bin$ , Binary (Builtin) , BLOAD , BSAVE , CBCD , CBool , CByte , CChar , CCur , CDate , CDbl , CDec , CEXT , CFIX , ChDir , ChDrive , Chr , Chr$ , CInt , Circle , Class , Clear , CLng , Close , CLS , CObj , Color , Command , Command$ , Compare , Contains , Count , Cos , CQUD , CreateObject , CShort , CSng , CsrLin , CType , CurDir , CurDir$ , CVD , CVDMBF , CVERR , CVI , CVL , CVS , CVSMBF , Date , Date$ , DateAdd , DateDiff , DatePart , DateSerial , DateValue , Day , DayName , DayOfWeek , DayOfYear , DaysInMonth , DaysInYear , DDB , Debug , Deg , DeleteSetting , Decode , DiffDay , DiffSeconds , Dir , Dir$ , DoEvents , DOF , Draw , Encode , EndsWith , Environ , Environ$ , EOF , ErDev , ErDev$ , Erl , Err , Error , Error$ , Exp , Fact , Field , FileAttr , FileCopy , FileDateTime , FileLen , File , Files , Fill , Filter , Fix , FN , Format , Format$ , FormatCurrency , FormatDateTime , FormatNumber , FormatPercent , Frac , FRE , FreeFile , Function , FV , Get , GetAllSettings , GetAttr , GetAutoServerSettings , GetObject , GetSetting , GetType , Hex , Hex$ , Hour , Hypot , IMEStatus , IndexOf , Inkey , Inkey$ , Inp , Input , Input$ , InputBox , Insert , InStr , InStRev , Int , IOCtl , IOCtl$ , IPMT , IRR , IsArray , IsBoolean , IsByte , IsCharacter , IsCollection , IsCString , IsCurrency , IsDate , IsDateValid , IsDateTimeValid , IsDouble , IsEmpty , IsError , IsInteger , IsMissing , IsLinux , IsMac , IsNull , IsNumeric , IsObject , IsShort , IsSingle , IsLeapYear , IsLong , IsString , IsTimeValid , IsVariant , IsWindows , Join , KBasicDir , Kill , LastIndexOf , LCase , LCase$ , Left , Left$ , LeftJustified , Len , Length , Line (Debug) , Ln , Load , LoadPicture , LoadResData , LoadResPicture , LoadResString , Loc , Locate , Lock , LOF , Log , Logb , Lower , LPos , LPrint , LTrim , LTrim$ , Max , Mid (Builtin) , Mid$ (Builtin) , Min , Minute , MIRR , MKD$ , MkDir , MKDMBF$ , MKI$ , #MKL$ , MKS , MKS$ , MKSMBF$, Module , Month , MonthName , MsgBox , MTIMER , Name , Now , NPER , NPV , Nz , Oct , Oct$ , Open , Out , Output , Paint , Palette , Partition , PCopy , Peek , PMAP , PMT , Point , Poke , Pos , PPMT , Prepend , Preset , Print , PrintScreen , PSet , Put , PV , QBCOLOR , Rad , Raise , RaiseEvent , RaiseSignal , Random , Randomize , Rate , ReadBinary , Remove , RemoveHandler , Replace , Return , Reset , Reversed , RGB , Right , Right$ , RightJustified , RmDir , RND , Round , RTrim , RTrim$ , SavePicture , SaveSetting , Screen , Sec , Second , Section , Seek , SeekBinary , Seg , SendKeys , SetAttr , Sgn , Shell , Simplified , Sin , Size , Sleep , Sln , Sound , Space , Space$ , Spc , Split , Sqr , Stick , StartsWith , Str , Str$ , StrComp , StrConv , String , String$ , StrReverse , Sub , SubDays , SubHours , SubMinutes , SubMonths , SubSeconds , SubYears , SYD , Tab , Tan , Time , Time$ , TimeSerial , TimeValue , Trim , Trim$ , Trimmed , Truncate , Type , TypeName , UCase , UCase$ , Unicode , UnLoad , UnLock , Upper , Using , Utf8 , Utf16 , Val , Value , VarType , View , Weekday , WeekdayName , WeekNumber , Width , Window , Write , WriteBinary , Year

__Class__ (Macro) , __File__ (Macro) , __IsClass__ (Macro) , __IsLinux__ (Macro) , __IsMacOS__ (Macro) , __IsModule__ (Macro) , __IsSub__ (Macro) , __IsWindows__ (Macro) , __Line__ (Macro) , __Module__ (Macro) , __Scope__ (Macro) , __Sub__ (Macro)



The following list is recommended for new application development. Instead of using the old builtin functions, you ought to use the new KBasic Framework.

Abs , AddDays , AddHours , AddMinutes , AddMonths , AddSeconds , AddYears , Append , Asc , Bin , Boolean , Byte , CBool , CByte , CDbl , Chr , CInt , Class , Compare , Contains , Count , Cos , CSng , Currency , Date , Date (Cast) , DateTime , Day , DayName , DayOfWeek , DayOfYear , DaysInMonth , DaysInYear , Debug , Decode , Decimal , DiffDay , DiffSeconds , DoEvents , Double , Encode , EndsWith , Exp , File , FileCopy , FileLen , Fill , Fix , Format , Function , Hex , Hour , IndexOf , InputBox , Insert , InStr , InStRev , Int , Integer , IsDateValid , IsDateTimeValid , IsLeapYear , IsLinux , IsMac , IsNull , IsWindows , IsTimeValid , LastIndexOf , LCase , Left , LeftJustified , Len , Length , Line , Log , Long , Lower , LTrim , Max , Mid (Builtin) , Min , Minute , Module , Month , MonthName , MsgBox , Now , Peek , Poke , Prepend , Print , Random , Randomize , ReadBinary , Remove , Replace , Return , Reversed , Right , RightJustified , Rnd , Round , RTrim , Second , Section , SeekBinary , Sgn , Short , Simplified , Sin , Single , Size , Space , Split , StartsWith , Str , StrComp , String (Cast) , StrReverse , Sqr , Sub , SubDays , SubHours , SubMinutes , SubMonths , SubSeconds , SubYears , Tan , Time , Trim , Trimmed , Truncate , Type , UCase , Unicode , Upper , Using , Utf8 , Utf16, Val, Value , WeekNumber , WriteBinary , Year



The following list contains the reserved builtin functions without functionality yet.

Acs , AddHandler , AppActiviate , Asn , Atn , BLOAD , BSAVE , CBCD , CChar , CDec , CEXT , CFIX , CObj , CQUD , CreateObject , CType , CVD , CVDMBF , CVI , CVL , CVS , CVSMBF , DDB , Deg , DeleteSetting , DOF , Draw , Environ , Environ$ , ErDev , ErDev$ , Fact , Field , Filter , FN , FormatCurrency , FormatNumber , FormatPercent , Frac , FV , GetAllSettings , GetAutoServerSettings , GetObject , GetSetting , GetType , Hypot , IMEStatus , Inp , IOCtl , IOCtl$ , IPMT , IRR , IsCharacter , IsCollection , IsCString , Join , Ln , Load , LoadPicture , LoadResData , LoadResPicture , LoadResString , Logb , LPos , LPrint , MIRR , MKD$ , MKDMBF$ , MKI$ , MKL$ , MKS , MKS$ , MKSMBF$ , MTIMER , NPER , NPV , Out , Paint , Palette , Partition , PCopy , PMAP , PMT , Point , PPMT , Preset , PSet , PV , QBCOLOR , RaiseEvent , RaiseSignal , Rate , RemoveHandler , SavePicture , SaveSetting , Screen , Sec, Seg , SendKeys , SetAttr , Sln , Sound , Stick , StrConv , SYD , UnLoad , UnLock , View , Width , Window


Descriptions

--------LITERAL--------

Implemented since KBasic V1.77

Return

Function Return() As String

Returns a “\n” like kbCr does. Ought to be used for creating a multi-line messagebox string.


--------CAST--------

Implemented since KBasic V1.77

If you need a different language to deal with different formats use Application.SetLanguage. If you do not set the language the current local language set by the operating system is used.

Example

Application.SetLanguage("English") ' sets for values like 23,345.45

Catching a cast exception (new style)

Try 
  date_ = Date(True) Throws CastException
  Print date_
Catch (CastException)
  Print "Could not convert expression"
End Catch

Catching a cast exception (old style)

On Error Goto myerr

date_ = Date(True) Throws CastException
Print date_

END
myerr:
If Err.Number = CastException then
  Print "Could not convert expression"
  'Resume Next
End If

Boolean

Function Boolean(EXPRESSION) As Boolean Throws CastException

If EXPRESSION is a string value, it checks if the string contains any character and returns TRUE, if so. Otherwise it returns FALSE.

If EXPRESSION is a numeric value, it checks if it's value is zero and returns TRUE, if so. Otherwise the return value is FALSE.

If EXPRESSION is a date value, it throws an exception (CastException).


String (Cast)

Function String(BOOLEAN) As String Throws CastException

Function String(STRING) As String Throws CastException

Function String(BYTE|SHORT|INTEGER|LONG, WithGroupSeparator As Boolean = True) As String Throws CastException

Function String(SINGLE|DOUBLE, Format As String = “g”, Precision As Integer = 6, WithGroupSeparator As Boolean = True) As String Throws CastException

Format might be one of the following values

eformat as [-]9.9e[+ or -]999
Eformat as [-]9.9E[+ or -]999
fformat as [-]9.9
guse e or f format, whichever is the most concise
Guse E or f format, whichever is the most concise

With “e”, “E”, and “f”, precision is the number of digits after the decimal point. With “g” and “G”, precision is the maximum number of significant digits (trailing zeroes are omitted).

Function String(DECIMAL|CURRENCY, WithGroupSeparator As Boolean = True) As String Throws CastException

Function String(DATETIME|DATE, Format As String = “ShortFormat”) As String Throws CastException

Format might contain the following characters, other characters will be ignored. If you do not set Format the current selected language will be considered, to choose the right format (“LongFormat” or “ShortFormat”).

Date related

d the day as number without a leading zero (1 to 31)
dd the day as number with a leading zero (01 to 31)
ddd the abbreviated localized day name (e.g. 'Mon' to 'Sun').
dddd the long localized day name.
M the month as number without a leading zero (1-12)
MM the month as number with a leading zero (01-12)
MMM the abbreviated localized month name (e.g. 'Jan' to 'Dec').
MMMM the long localized month name (e.g. 'January' to 'December').
yy the year as two digit number (00-99)
yyyy the year as four digit number

Time related

h the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hh the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
m the minute without a leading zero (0 to 59)
mm the minute with a leading zero (00 to 59)
s the second without a leading zero (0 to 59)
ss the second with a leading zero (00 to 59)
z the milliseconds without leading zeroes (0 to 999)
zzz the milliseconds with leading zeroes (000 to 999)
AP use AM/PM display. AP will be replaced by either “AM” or “PM”.
ap use am/pm display. ap will be replaced by either “am” or “pm”.

Byte

Function Byte(EXPRESSION) As Byte Throws CastException

See Integer for more information.


Short

Function Short(EXPRESSION) As Short Throws CastException

See Integer for more information.


Integer

Function Integer(EXPRESSION) As Integer Throws CastException

If EXPRESSION is a boolean value, it will return 0 for FALSE and -1 for TRUE.

If EXPRESSION is a string value, it tries to convert it to an integer. It must not contain a decimal point, otherwise an exception is thrown (CastException) and it must not be an empty string.

If EXPRESSION is a numeric value, it will return an integer value without rounding it.

If EXPRESSION is a date value, it throws an exception (CastException).

Example

integer_ = Integer("6,162")
Print integer_

integer_ = Integer("6,162.67") Throws CastException ' throws CastException, because of the decimal point
Print integer_

Long

Function Long(EXPRESSION) As Long Throws CastException

See Integer for more information.


Single

Function Single(EXPRESSION) As Single Throws CastException

See Double for more information.


Double

Function Double(EXPRESSION) As Double Throws CastException

If EXPRESSION is a boolean value, it will return 0 for FALSE and -1 for TRUE.

If EXPRESSION is a string value, it tries to convert it to a double. If it contains not only numbers, it tries to determine the thousand separators, otherwise an exception is thrown (CastException). By checking for thousand separator the current language is considered.

If EXPRESSION is a value from Currency or Decimal, it will return the nearest possible value.

If EXPRESSION is a date value, it throws an exception (CastException).

Example

double_ = Double("6.162,78") ' German locale
Print double_ ' prints 6162.78

Decimal

Function Decimal(EXPRESSION) As Decimal Throws CastException

If EXPRESSION is a boolean value, it will return 0 for FALSE and -1 for TRUE.

If EXPRESSION is a string value, it tries to convert it to a decimal. If it contains not only numbers, it tries to determine the thousand separators, otherwise an exception is thrown (CastException). By checking for thousand separator the current language is considered.

If EXPRESSION is a value from numeric with an exponential, it will return the nearest possible value.

If EXPRESSION is a date value, it throws an exception (CastException).


DateTime

Function DateTime(EXPRESSION, Format As String = ””) As DateTime Throws CastException

If EXPRESSION is not a date value or string value, it throws an exception (CastException).

Format might contain the following characters, other characters will be ignored. If you do not set Format the current selected language will be considered, to choose the right format (“LongFormat”, “ShortFormat”, “yyyy-MM-dd hh:mm:ss”, “yyyy-MM-dd” or “hh:mm:ss”).

Date related

d the day as number without a leading zero (1 to 31)
dd the day as number with a leading zero (01 to 31)
ddd the abbreviated localized day name (e.g. 'Mon' to 'Sun').
dddd the long localized day name.
M the month as number without a leading zero (1-12)
MM the month as number with a leading zero (01-12)
MMM the abbreviated localized month name (e.g. 'Jan' to 'Dec').
MMMM the long localized month name (e.g. 'January' to 'December').
yy the year as two digit number (00-99)
yyyy the year as four digit number

Time related

h the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hh the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
m the minute without a leading zero (0 to 59)
mm the minute with a leading zero (00 to 59)
s the second without a leading zero (0 to 59)
ss the second with a leading zero (00 to 59)
z the milliseconds without leading zeroes (0 to 999)
zzz the milliseconds with leading zeroes (000 to 999)
AP use AM/PM display. AP will be replaced by either “AM” or “PM”.
ap use am/pm display. ap will be replaced by either “am” or “pm”.

Currency

Function Currency(EXPRESSION) As Currency Throws CastException

See Decimal for more information.


Date (Cast)

Function Date(EXPRESSION, Format As String = ””) As Date Throws CastException

See DateTime for more information.


--------DEBUG--------

Implemented since KBasic V1.77

Type

Function Type(Variable) As String


Size

Function Size(Variable) As Integer


File

Function File() As String


Line (Debug)

Function Line() As Integer


IsLinux

Function IsLinux() As Boolean


IsMac

Function IsMac() As Boolean


IsWindows

Function IsWindows() As Boolean


Sub

Function Sub() As String


Function

Function Function() As String


Module

Function Module() As String


Class

Function Class() As String


--------A--------

Abs

Function Abs(Expression) As Double

Returns the absolute value of an expression.


Access

Sub Open STRINGEXPRESSION For [Input|Output|Append|Binary|Random] Access [Read|Write|Read Write] As INTEGEREXPRESSION www.kbasic.com_images_vb6.jpg

Access is not supported, but you may use still this syntax.

Example

Dim TextLine As String, ff As Integer

ff = FreeFile ' next availaible filehandle

Open "c:\kbasic15\examples\test\test.txt" For Input Access Read As #ff ' open test file

Do While Not EOF(ff) ' while end of file has not been reached
   Line Input #ff, TextLine ' store next line in string
   print TextLine 
Loop

Close #ff ' close file

AddDays

Function AddDays(DateTime, Days As Integer) As DateTime


AddHours

Function AddHours(DateTime, Hours As Integer) As DateTime


AddMinutes

Function AddMinutes(DateTime, Minutes As Integer) As DateTime


AddMonths

Function AddMonths(DateTime, Months As Integer) As DateTime


AddSeconds

Function AddSeconds(DateTime, Seconds As Integer) As DateTime


AddYears

Function AddYears(DateTime, Years As Integer) As DateTime


Append

  • Function Append(String, String) As String

Appends the string onto the end of this string and returns it.

  • Sub Open STRINGEXPRESSION For [Input|Output|Append|Binary|Random] As INTEGEREXPRESSION

www.kbasic.com_images_vb6.jpg

Opens a file for appending. Supported for backward compatibility.

Example

OPTION OLDBASIC

DIM Rec1$, Rec2$   
 
CLS
 OPEN "c:\kbasic\examples\test\LISTEN.TXT" FOR APPEND AS #1
 DO
     INPUT "   NAME:       ", Name$
     INPUT "   AGE:        ", Age$
     WRITE #1, Name$, Age$
     INPUT "More entries?"; R$
 LOOP WHILE UCASE$(R$) = "Y"
CLOSE #1

 'print file on screen
 OPEN "c:\kbasic\examples\test\LISTEN.TXT" FOR INPUT AS #1
 CLS
 PRINT "Entries of file:": PRINT
DO WHILE NOT EOF(1)
    INPUT #1, Rec1$, Rec2$   
    PRINT Rec1$, Rec2$       
LOOP
CLOSE #1
KILL "LIST"

Array

Function Array(ARGUMENTS) As Variant www.kbasic.com_images_vb6.jpg

Creates an array of variant values.

If no arguments are specified, an array of zero length is created.

Example

Dim A As Variant
A = Array(10,20,30)
B = A(2)

Asc

Function Asc(String) As Integer

Returns the ASCII code for the first character of a STRING. A STRING of length zero returns 0.

Example

PRINT ASC("Bernd") ' will show 66

See also Chr


--------B--------

Beep

Sub Beep() www.kbasic.com_images_vb6.jpg

Produces a sound. Depends on the system if it works.

The BEEP function is implemented using the Qt function http://doc.trolltech.com/4.3/qapplication.html#beep

Use Application.PlaySound(String) instead.

Example

Beep 

Bin

Function Bin(EXPRESSION) As String

Bin or BIN$ returns a string giving the binary (base 2) representation of 'number'. The return string has as many characters as necessary to represent the integer in binary.

Example

PRINT BIN$(128)

See also Hex


Binary (Builtin)

Sub Open STRINGEXPRESSION For [Input|Output|Append|Binary|Random] As INTEGEREXPRESSION www.kbasic.com_images_vb6.jpg

Opens a file in binary mode. Supported for backward compatibility.

Example

OPTION OLDBASIC

DIM Name$, Age$, R$, Rec1$, Rec2$



CLS
OPEN "c:\kbasic15\examples\test\LISTEN2.txt" FOR BINARY AS #1
DO
     INPUT "   NAME:       ", Name$
     INPUT "   AGE:        ", Age$
     WRITE #1, Name$, Age$
     INPUT "More entries?"; R$
LOOP WHILE UCASE$(R$) = "Y"
CLOSE #1

'print file on screen
OPEN "c:\kbasic15\examples\test\LISTEN2.txt" FOR INPUT AS #1
CLS
PRINT "Entries of file:": PRINT
DO WHILE NOT EOF(1)
    INPUT #1, Rec1$, Rec2$
    PRINT Rec1$, Rec2$       
LOOP
CLOSE #1
 

--------C--------

CBool

Function CBool(EXPRESSION) As Boolean

It converts any number to a boolean.

Example

PRINT CBOOL(300.5012)

' Output:
' true

CByte

Function CByte(EXPRESSION) As Byte

It converts any number to a byte.

Example

PRINT CByte(30.5012)

' Output:
' 30

CCur

Function CCur(EXPRESSION) As Currency www.kbasic.com_images_vb6.jpg

It converts any number to a currency.

Example

PRINT CCUR(8.8)

CDate

Function CDate(EXPRESSION) As Date www.kbasic.com_images_vb6.jpg

It converts any number to a date.

Example

'PRINT CDATE(899999998) ' integer not allowed
PRINT CDATE("2006-12-12") ' must be like this format yyyy-mm-dd

CDbl

Function CDbl(EXPRESSION) As Double

It converts any number to a double. CDbl takes any number and tries to convert it to a double.

Example

PRINT CDBL(300.5012)

' Output:
' 300.5012

See also CSng, CInt, CLng


ChDir

Sub ChDir(String) www.kbasic.com_images_vb6.jpg

Changes the current directory to new one.

Example

MKDIR "C:\TEMP\TEST"
CHDIR "C:\TEMP"
FILES
RMDIR "TEST"

See also CurDir, MkDir, ChDrive, Files


ChDrive

Sub ChDrive(String) www.kbasic.com_images_vb6.jpg

Changes to another current drive.

Example

CHDRIVE "D" ' change to D:

Chr

Function Chr(EXPRESSION) As String

Returns the ASCII character corresponding to the value of Val. EXPRESSION must be a numerical expression.

Example

PRINT CHR(34)

See also Asc


CInt

Function CInt(EXPRESSION) As Integer

It converts any number to an integer and takes any number and convert it to an integer. This will remove any precision from a single or a double.

Example

PRINT CINT(300.5012)
'
' Output:
' 300

See also CLng


Circle

Sorry. Not supported yet. www.kbasic.com_images_vb6.jpg


Clear

Sub Clear() www.kbasic.com_images_vb6.jpg

It is a method of the error object, which is provided for VB6 backward compatibility. Use the exception handling instead,.

Example

Dim Msg

On Error Resume Next

Err.Clear
Err.Raise(6)

If Err.Number <> 0 Then
  
   Msg = "Error # " & Str(Err.Number) & " " _
       & Err.Source & Chr(10) & Err.Description
  
    Print Msg
  
End If

See also Try


CLng

Function CLng(EXPRESSION) As Long

It takes any number and tries to convert it to a long. This will remove any precision from a single or a double.

Example

PRINT CINT(300.5012)
'
' Output:
' 300

See also CInt


Close

Sub Close [ [#]FileNo As Integer ] {[ , [#]FileNo As Integer ]} www.kbasic.com_images_vb6.jpg

Closes the specified file(s).

Example

Dim I, filename
For I = 1 To 3 ' repeat loop 3 times
  filename = "TEST" & I ' create filename
  Open filename For Output As #I ' open file
  Print #I, "Ein Test." ' write string into file
Next I
Close ' close all 3 opened files

See also Open, Reset


CLS

Sub CLS() www.kbasic.com_images_vb6.jpg

In the terminal screen, CLS will clear the screen and returns the cursor to the upper left corner (line 1, column 1).

Example

' CLS clearing the terminal screen
' with a new background color

PRINT "This is to show the CLS command"
INPUT "To clear the screen, press [Return]", keypressed$

' changes the background color:
COLOR (2, 4)
CLS
PRINT "This is green text on a blue screen!"

Color

Sub Color(Fore As Integer [, Back As Integer]) www.kbasic.com_images_vb6.jpg

Calling COLOR will set the color of either the foreground and optionally the background. Passing only one integer will change the fore color. Passing 2 will change both the fore and background color.

Example

COLOR(5)
PRINT "Hi"
COLOR(15,1)
PRINT "Nadja"

Command

Function Command() As String www.kbasic.com_images_vb6.jpg

Returns the arguments which have been given to your application by the OS while starting.

Example

PRINT COMMAND()

Compare

Function Compare(String, String, CaseSensitive As Boolean = True) As Integer

Lexically compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other string.


Contains

Function Contains(String, String, CaseSensitive As Boolean = True) As Boolean

Returns true if this string contains an occurrence of the string str; otherwise returns false.


Count

Function Count(String, String, CaseSensitive As Boolean = True) As Integer

Returns the number of (potentially overlapping) occurrences of the string str in this string.


Cos

Function Cos(EXPRESSION) As Double

It returns the cosine of the argument 'number' in radians. EXPRESSION must be a numerical expression.

Example

CONST PI=3.141592654
PRINT ATN(TAN(PI/4.0)), PI/4.0 'result: .7853981635 .7853981635
PRINT (COS(180 * (PI / 180))) 'result: -1
PRINT (SIN(90 * (PI / 180))) 'result: 1
PRINT (TAN(45 * (PI / 180))) 'result: 1.000000000205103

See also Sin, Tan


CShort

Function CShort(EXPRESSION) As Short

Sorry. Not implemented yet. Use CInt instead of it.

See also CInt


CSng

Function CSng(EXPRESSION) As Single

It converts any number to a single. EXPRESSION must be a numerical expression.

Example

PRINT CSNG(300.5012)

' Output:
' 300.5012

See also CDbl


CSRLin

Function CSRLin() As Integer www.kbasic.com_images_vb6.jpg

It returns the current line of the cursor.

Example

PRINT CSRLIN()

PRINT "row = " + POS(0)

INPUT s$

PRINT "line = " + CSRLIN

PRINT s$

See also Pos, Locate


CurDir

Function CurDir([Drive As String]) As String www.kbasic.com_images_vb6.jpg

It returns the current path.

Example

' Windows:
' current path of C: ist "C:\WINDOWS\SYSTEM32".
' current path of D: ist "D:\kbasic".
' C: is the active drive.
Dim path
path = CurDir' returns "C:\WINDOWS\SYSTEM32".
path = CurDir("C") ' returns "C:\WINDOWS\SYSTEM32".
path = CurDir("D") ' returns "D:\kbasic".

CVErr

Function CVErr(EXPRESSION) As Variant www.kbasic.com_images_vb6.jpg

It returns a user defined error.

Example

Option OldBasic

Sub test()
 Print doubleit("395.45bernd")
End Sub

Function doubleit(no)
 If IsNumeric(no) Then
  doubleit = no* 2 ' return result
 Else
  doubleit = CVErr(2001) ' return user defined error
 End If
End Function

test()

--------D--------

Date

Function Date() As String www.kbasic.com_images_vb6.jpg

Date or DATE$ returns the current system date as a string. Setting the date is not possible with this builtin function.

Format is yyyy-MM-dd.

Example

PRINT DATE

See also Time


DateAdd

Function DateAdd(Interval As String, Number As Integer, DateToChange As Date) As Date www.kbasic.com_images_vb6.jpg

Adds something to a date.

interval values:

  • yyyy year
  • q quarter
  • m month
  • y day of year
  • d day
  • w weekday
  • ww week
  • h hour
  • n minute
  • s second

Example

Dim Date1 As Date
Dim Interval As String
Dim Number As Integer
Dim Msg
Interval = "m"
Date1 = InputBox("Input the date") ' #yyyy-mm-dd#
Number = Val(InputBox("Input the number of months to add"))
Msg = "New date: " & DateAdd(Interval, Number, Date1)
MsgBox Msg

See also DateDiff, DatePart, DateSerial, DateValue


DateDiff

Function DateDiff(Interval As String, Date1 As Date, Date2 As Date[, FirstDayOfWeek As String[, FirstWeekOfYear As String]]) As Date www.kbasic.com_images_vb6.jpg

Returns the number of interval laying between date1 and date2.

interval values:

  • yyyy year
  • q quarter
  • m month
  • y day of year
  • d day
  • w weekday
  • ww week
  • h hour
  • n minute
  • s second

Example

Dim Date1 As Date
Dim Msg
Date1 = InputBox("Input the date")
Msg = "Days till today: " & DateDiff("d", Now, Date1)
MsgBox Msg

See also DateAdd, DatePart, DateSerial, DateValue


DatePart

Function DatePart(Interval As String, DateToAsk As Date [, FirstDayOfWeek As String[, FirstWeekOfYear As String]]) As Integer www.kbasic.com_images_vb6.jpg

Returns the desired part of a date.

interval values:

  • yyyy year
  • q quarter
  • m month
  • y day of year
  • d day
  • w weekday
  • ww week
  • h hour
  • n minute
  • s second

Example

Dim Date1 As Date
Dim Msg
Date1 = InputBox("Input a date:")
Msg = "quarter: " & DatePart("q", Date1)
MsgBox Msg

See also DateAdd, DateDiff, DateSerial, DateValue


DateSerial

Function DateSerial(Year As Integer, Month As Integer, Day As Integer) As Date www.kbasic.com_images_vb6.jpg

Converts a date given by year, month and day into a big number.

Example

Dim Date1
Date1 = DateSerial(1969, 2, 12)' return Date1

See also DateAdd, DateDiff, DatePart, DateValue


DateValue

Function DateValue(STRINGEXPRESSION) As Date www.kbasic.com_images_vb6.jpg

Converts a date given in a string into a date type.

Example

Dim Date1
Date1 = DateValue("1979-02-03")

See also DateAdd, DateDiff, DatePart, DateSerial


Day

Function Day(DATEEXPRESSION) As Integer www.kbasic.com_images_vb6.jpg

Returns the day part of an date expression.

Example

Dim Date1, Day1
Date1 = #2006-12-12#
Day1 = Day(Date1) ' --> 12

DayName

Function DayName(DateTime, Format As String = ””) As String

Format may be “ShortFormat” or “LongFormat”. If no Format is given, “LongFormat” is used.


DayOfWeek

Function DayOfWeek(DateTime, Format As String = ””) As String

Format may be “ShortFormat” or “LongFormat”. If no Format is given, “LongFormat” is used.


DayOfYear

Function DayOfYear(DateTime) As Integer


DaysInMonth

Function DaysInMonth(DateTime) As Integer


DaysInYear

Function DaysInYear(DateTime) As Integer


Decode

Function Decode(String) As String


DiffDays

Function DiffDays(DateTime, DateTime) As Integer


DiffSeconds

Function DiffSeconds(DateTime, DateTime) As Integer


Dir

Function Dir([Path As String [, Attribute]]) As String www.kbasic.com_images_vb6.jpg

Attributes:

  • kbNormal 0 normal
  • kbHidden 2 hidden
  • kbSystem 4 system file
  • kbVolume 8 volume name
  • kbDirectory 16 directory

Example

file1 = Dir("C:\WINDOWS\*.INI")

Path1 = "c:\" 
Name1 = Dir(Path1, kbDirectory) ' first entry
Do While Name1 "" ' loop
If Name1 "." And Name1 ".." Then
If (GetAttr(Path1 & Name1) And kbDirectory) = kbDirectory Then
Print Name1 
End If
End If
Name1 = Dir ' next entry
Loop

DoEvents

Sub DoEvents()

Enables the application to process events.

Example

DoEvents()

--------E--------

Encode

Function Encode(String) As String

Escapes forbidden correctors in sql statements.


EndsWith

Function EndsWith(String, String, CaseSensitive As Boolean = True) As Boolean

Returns true if the string ends with s; otherwise returns false.


EOF

Function EOF([#]FileNo) As Boolean www.kbasic.com_images_vb6.jpg

It returns true if end of file has been reached. In other words, it checks if end of file has been reached and return true if it has happened.

Example

Dim data
Open "file1" For Input As #1 ' open file for reading
Do While Not EOF(1) ' test for end of file
  Line Input #1, data ' get the data from file
  Print data 
Loop
Close #1 ' close file

See also Open, Write, LOF, Close, LOC


Erl

Function Erl() As Integer www.kbasic.com_images_vb6.jpg

It returns the line in which the last error occured.

Example

PRINT ERL

See also Error, Resume, Err, On Error


Err

Function Err() As Integer www.kbasic.com_images_vb6.jpg

As for VeryOldBasic, it returns the runtime error code, as for OldBasic it is an object for error handling.

Properties (OldBasic):

  • Property Number As Integer (ReadOnly)
  • Property Source As String (ReadOnly)
  • Property Description As String (ReadOnly)

Methods (OldBasic):

  • Sub Clear() ' reset
  • Sub Raise(Number As Integer, Source As String, Description As String) ' raise error

Example

Dim Msg
On Error Resume Next
Err.Clear
Err.Raise 6
If Err.Number 0 Then
  Msg = "Error # " & Str(Err.Number) & " " _
  & Err.Source & Chr(13) & Err.Description
  MsgBox Msg, , "Error"
End If

See also Error, Resume, Err, On Error


Error

Function Error(EXPRESSION) As String www.kbasic.com_images_vb6.jpg

Simulates an error. EXPRESSION must be a numerical expression.

Example

ERROR 4 ' throws an error

Dim errorno
For errorno = 61 To 64 
Print Error(errorno) 
Next

See also Erl, Resume, Err, On Error


Exp

Function Exp(EXPRESSION) As Double

It returns the exponential value of an expression. EXPRESSION must be a numerical expression.

Example

PRINT EXP(0), EXP(1) 'result: 1 2.718282
PRINT LOG(1), LOG(EXP(1)) 'result: 0 1

See also Log


--------F--------

FileAttr

Function FileAttr([#]FileNo As Integer, ReturnType As Integer) As Double www.kbasic.com_images_vb6.jpg

It returns the access mode for an opened file.

if ReturnType = 1 then the following values can be returned:

  • Input 1
  • Output 2
  • Random 4
  • Append 8
  • Binary 32

Example

Dim filehandle, Mode
filehandle = 1
Open "file1" For Append As filehandle
Mode = FileAttr(filehandle, 1) ' returns 8 (Append).
Close filehandle ' close file

See also Open


FileCopy

Function FileCopy(Source As String, Destination As String) As Boolean

It copies a file from source to destination.

Example

FILECOPY "c:\kbasic\examples\test\test.dat", "c:\kbasic\examples\test\test2.dat"

FILECOPY "test.dat", "test2.dat"
FILECOPY "test2.dat", "test.dat"

FileDateTime

Function FileDateTime(FileName As String) As Date www.kbasic.com_images_vb6.jpg

It returns the date of the file.

Example

Print FileDateTime("c:\kbasic14\examples\test\liste.txt")

FileLen

Function FileLen(FileName As String) As Long

It returns the length of a file in bytes.

Example

Print FileLen("c:\kbasic\parser.cpp")

Files

Sub Files() www.kbasic.com_images_vb6.jpg

Provided for QBasic compatibility.

Example

PRINT "listening of directory" 
FILES

Fill

Function Fill(String, String, Length As Integer = -1) As String

Sets every character in the string to character ch and returns it. If size is different from -1 (the default), the string is resized to size beforehand.


Fix

Function Fix(EXPRESSION) As Long

It cuts off the trail of a number. EXPRESSION must be a numeric expression.

Example

PRINT FIX(12.49), FIX(12.54) 'result: 12 

See also Int, CInt, CLng


Format

Function Format(EXPRESSION, [Format As String, [FillChar As String[, RightAligned As Boolean]]]) As String

Implemented since KBasic V1.6(q).

This functions is slightly different than the FORMAT function of VB6.

EXPRESSION might be any scalar expression except object expressions or user defined type.

Format characters for

  • Boolean
 True/False
 Yes/No
 You may enter two strings (first is used for true, the second one for false). Separate them with /
  • String
 Each # represent one character. All # determines the minimum length of the string returned.
  • Byte, Short, Integer, Long
 Each # represent one character. All # determines the minimum length of the string returned.
  • Single, Double
 Each # represent one character. All # determines the minimum length of the string returned.
 Formats are "e" means format as [-]9.9e[+|-]999 and "E" means format as [-]9.9e[+|-]999.
 Formats are "f" or no character means format as [-]9.9.
 e.g. ####.## minimum are seven characters with two characters after the dot. (The dot adds an extra output character).
  • Currency, Decimal
 Each # represent one character. All # determines the minimum length of the string returned.
 e.g. ####.## minimum are seven characters with two characters after the dot. (The dot adds an extra output character).
  • Date, DateTime

Date related

d the day as number without a leading zero (1 to 31)
dd the day as number with a leading zero (01 to 31)
ddd the abbreviated localized day name (e.g. 'Mon' to 'Sun')
dddd the long localized day name (Monday' to 'Sunday')
M the month as number without a leading zero (1-12)
MM the month as number with a leading zero (01-12)
MMM the abbreviated localized month name (e.g. 'Jan' to 'Dec').
MMMM the long localized month name (e.g. 'January' to 'December').
yy the year as two digit number (00-99)
yyyy the year as four digit number

Time related

h the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hh the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
m the minute without a leading zero (0 to 59)
mm the minute with a leading zero (00 to 59)
s the second without a leading zero (0 to 59)
ss the second with a leading zero (00 to 59)
z the milliseconds without leading zeroes (0 to 999)
zzz the milliseconds with leading zeroes (000 to 999)
AP use AM/PM display. AP will be replaced by either “AM” or “PM”.
ap use am/pm display. ap will be replaced by either “am” or “pm”.
Examples are
dd.MM.yyyy 21.05.2001
ddd MMMM d yy Tue May 21 01
hh:mm:ss.zzz 14:13:09.042
h:m:s ap 2:13:9 pm
If you would like to have uppercase or lowercase outputs, please use the UCase or LCase functions. If you would like to have maximum length, please use Left.

The String FillChar (actually only the first character of it) is used to fill up (default value is ” ”). If RightAligned = True, the EXPRESSION set right, instead of left (default). In most cases, you do not have to set FillChar and RightAligned.

Example

  Dim b As Boolean = True
  Dim n As Integer = 12
  Dim s As String = "Hello"
  Dim d As Double = 12.9999
  Dim c As Currency = 12.9999
  Dim da As Date = #2006-12-12 4:4:44#
 
  Print "b="& Format(b, "True/False", False)
  b = False
  Print "b="& Format(b, "Yes/No", False)
 
  Print "n="& Format(n, "&#####$", , False)
  Print "n="& Format(n, "&#####/", ".", True)
  Print "n="& Format(n, "")
 
 
  Print "s="& Format(s, "##") & "!"
  Print "s="& s.Format("Value: ######## in $", "-", True) & "!"
  Print "s="& s.Format("Value: ######## in $", ".", False) & "!"
  
  Print "s="& Format(d, "Value: ##.####e in M", ".", True) & "!"
  Print "s="& Format(d, "Value: ########.####E in M", ".", True) & "!"
  Print "s="& Format(d, "Value: ########.##f in M", ".", True) & "!"
  
  Print "s="& Format(d, "Value: ##.## in M", ".", True) & "!"
  Print "s="& Format(d, "Value: ######.##### in M", ".", True) & "!"
  
  Print "s="& Format(c, "Value: ######.## in M", ".", False) & "!"
  Print "s="& Format(c, "Value: ######.#### in M", ".", False) & "!"
  
  Print "s="& Format(da, "dd-mm-yyyy hh:mm:ss", ".") & "!"
  Print "s="& Format(da, "dddd MMM dd-mm-yyyy hh:mm:ss AM", ".") & "!"
 

FormatDateTime

Function FormatDateTime(STRINGEXPRESSION[{, EXPRESSION,…]}) As String

Sorry. Not implemented yet.

Please use Format instead.


Fre

Function Fre(EXPRESSION) As Long www.kbasic.com_images_vb6.jpg

It returns the available memory.

Example

PRINT FRE
FRE(-1)
PRINT FRE("")

FreeFile

Function FreeFile([Range]) As Integer www.kbasic.com_images_vb6.jpg

It returns the next free available file handle.

Example

Dim Index1, filehandle
For Index1 = 1 To 5

filehandle = FreeFile ' next free available file handle 

Open "TEST" & Index1 For Output As #filehandle
Write #filehandle, "example text."
Close #filehandle 
Next

See also Open


--------G--------

Get

Function Get([#]FileNo As Integer[, RecordNo As Integer], Variable As AnyType) www.kbasic.com_images_vb6.jpg

It reads a record from file.

Example

TYPE TestRecord
  Student AS STRING * 20
  Result AS SINGLE
END TYPE

DIM MyClass AS TestRecord

OPEN "ENDRESULTS.DAT" FOR RANDOM AS #1 LEN = LEN(MyClass)

MyClass.Student = "Bernd Noetscher"
MyClass.Result = 99
PUT #1, 1, MyClass
CLOSE #1

OPEN "ENDRESULTS.DAT" FOR RANDOM AS #1 LEN = LEN(MyClass)
GET #1, 1, MyClass
PRINT "STUDENT:", MyClass.Student
PRINT "SCORE:", MyClass.Result
CLOSE #1

KILL "ENDRESULTS.DAT"

See also Type, Put


GetAttr

Function GetAttr(Path As String) www.kbasic.com_images_vb6.jpg

It returns attributes of files or directories.

Possible return values are:

  • kbNormal 0 normal
  • kbReadOnly 1 read only file
  • kbHidden 2 hidden file
  • kbSystem 4 system file (not supported yet)
  • kbDirectory 16 directory (not supported yet)
  • kbArchive 32 (not supported yet)

Example

Dim Attr1
' "hidden" has been set for TSTFILE
Attr1 = GetAttr("TSTFILE")	' returns 2.

--------H--------

Hex

Function Hex(EXPRESSION) As String

It returns a string giving the hexadecimal (base 16) value. EXPRESSION must be a numerical expression. It will be rounded to the nearest whole number before being evaluated. Integers (or results of expressions within that range) are returned as a string of up to 4 hexadecimal characters, long integers are returned as a string of up to 8 hexadecimal characters.

Example

/*
Characters of Hex (0 - 9, A - F)

Hexadecimal -> Decimal
0 -> 0
1 -> 1
2 -> 2
3 -> 3
4 -> 4
5 -> 5
6 -> 6
7 -> 7
8 -> 8
9 -> 9
A -> 10
B -> 11
C -> 12
D -> 13
E -> 14
F -> 15
10 -> 16
*/
INPUT "Please type in a number: ", number
PRINT "The hexadecimal representation is "; HEX$(number)

' Output:
' 
' Please type in a number: 123456
' The hexadecimal representation is 1E240

See also Oct


Hour

Function Hour(DATEEXPRESSION) As Integer www.kbasic.com_images_vb6.jpg

Returns the day part of an date expression.

Example

 
Dim dd As Date = "#2006-12-12 4:35:17"

Dim Time1, Hour1
Time1 = #4:35:17 PM#
Hour1 = Hour(Time1)
 

--------I--------

IndexOf

Function IndexOf(String, Sub As String, Start As Integer = 1, CaseSensitive As Boolean = True) As Integer

Finds one string inside another.


Inkey

Function Inkey() As String www.kbasic.com_images_vb6.jpg

Provided for QBasic compatibility. Returns the key code, which was pressed.

Example

CLS

PRINT "Press Esc, to stop ..."
DO
LOOP UNTIL INKEY$ = CHR$(27)    '27 is the ASCII-Code for Esc.

Input

  • INPUT [;][STRINGEXPRESSION{;,}] VARIABLENAME[,VARIABLENAME…]

www.kbasic.com_images_vb6.jpg

Combined screen output and keyboard input.

1. semicolon prevent EOL after pressing return. If the 2. semicolon is replaced by a comma, no question mark will be displayed

The INPUT command prompts for a value to be stored in a variable. Values are entered with the keyboard. The simplest way to use it is just followed by a variable name which will hold the value entered: INPUT n

prompts a quotation mark at the beginning of a line and waits until the user has typed a value and pressed the RETURN key.

KBasic does not make any control whether the variable has been previously used with another value or not and therefore, destroys the previous value of the variable. Because variables need not to be declared (only veryoldbasic or oldbasic with option explicit off) INPUT serves also as initialization for the variable, which assumes value of 0 (zero) when only RETURN is pressed. It is often convenient to explain a bit more what we want from the user so it is preferable to prompt an explanation message on what kind of input we're expecting. This is done by just placing a double quoted text after the keyword, like:

INPUT “How many seconds”; s

As shown the prompt is now clearer and we know what kind of input is expected. The message can be as long as wanted and must be inside double quotes, single quotes are not allowed. Instead of the semicolon a comma can be used to separate message prompt and the variable name, like:

INPUT “Enter time (in seconds): ”, s

in this case the usual question mark is suppressed and the cursor is placed immediately afterwards the last character of the message string. The use of one or the other is a choice of the developer but the message and the variable name must be separated by one of the two characters. A semicolon can be used immediately after the INPUT command, like:

INPUT; “Enter age”; a INPUT ” and height”; b

this will cause the second INPUT command prompt to be placed immediately after the last character typed by the user:

Enter age? 156 and height? INPUT permits also to enter as many different values as we want. The different values are stored in different variables: INPUT “age and height: ”, age, height

this prompts the message and waits till the user has entered the coordinates separate with a comma. It is not possible to use any other separation character here. The two (or three, four, etc.) may be variables of different type, like:

INPUT “Enter full longitude coords (degree, cardinal): ”, long, card$

Whenever the number of variables expected is different from the entered ones or a variable type mismatch occurs a “redo from start” warning message is displayed and the command is prompted again to the user.

Example

INPUT "How many seconds"; s
INPUT; "Enter longitude"; a

INPUT " and latitude"; b
INPUT "longitude and latitude: ", longitude, latitude
INPUT "Enter full longitude coords (degree, cardinal): ", long, card$
  • Sub Open STRINGEXPRESSION For [Input|Output|Append|Binary|Random] As INTEGEREXPRESSION

www.kbasic.com_images_vb6.jpg

Opens a file for writing. Supported for backward compatibility.

Example

OPTION OLDBASIC


DIM REC$

CLS
OPEN "c:\kbasic\examples\test\LISTE.TXT" FOR OUTPUT AS #1
DO
    INPUT "   NAME:       ", Name$  'input from keyboard
    INPUT "   Age:        ", Age$
    WRITE #1, Name$, Age$
    INPUT "Type a new entry"; R$
LOOP WHILE UCASE$(R$) = "Y"
CLOSE #1

'print content of file
OPEN "c:\kbasic\examples\test\LISTE.TXT" FOR INPUT AS #1
CLS
PRINT "entries of file:": PRINT
DO WHILE NOT EOF(1)
    LINE INPUT #1, REC$  
    PRINT REC$           
LOOP
CLOSE #1

InputBox

Function InputBox(Prompt As String [, Title As String] [, Default As String]) As String

Get a string from the user using a input box on screen.

Example

Dim Msg, Titel, default2, val1

Msg = "Input value between 1 and 3"
Titel = "InputBox-Demo"
default2 = "1"

val1 = InputBox(Msg /*, Titel , default2*/ )

MsgBox("You have inputted: " + val1)
 

Insert

Function Insert(String, Insert As String, Position As Integer) As String

Inserts the string “Insert” at the given index position and returns it.


InStr

Function InStr([Start As Integer,] Source As String, Find As String, CaseSensitive As Boolean = True) As Integer

InStr finds one string inside another. Returns 0, if Find could not be found. First position in Source is referenced as 1.

Example

DIM s As String

s = "Bernd Noetscher's KBasic"
PRINT "string position = "& INSTR(1, s, "KBasic")

See also Mid ,Right ,Len ,Mid ,InStRev


InStRev

Function InStRev([Start As Integer,] Source As String, Find As String, CaseSensitive As Boolean = True) As Integer

InStRevsearches the Source string for and occurance of the Find string and returns the index of the Find string in the Source string. 0 is returned if the Find string is not found. Start tells the positon from which the searching starts from.

Example

Dim x As String, y As String

x = "This is a string"
y = "s"

Print InStRev(x, y)

See also Mid ,Right ,Len ,Mid ,InStr


Int

Function Int(EXPRESSION) As Long

Returns the next integer number < = given number.

Example

DIM n AS INTEGER

n = INT(12.54)
PRINT n

n = INT(-99.4)
PRINT n

See also Fix ,CInt ,CLng


IsArray

Function IsArray(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if a variable represents an array type.

Example

 
Dim i[8] As Integer
Dim x As String

Print IsArray(i)
Print IsArray(x)

IsBoolean

Function IsBoolean(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if a variable represents a boolean type.

Example

Dim x As Boolean

Print IsBoolean(x)

IsByte

Function IsByte(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if a variable represents a byte type.

Example

Dim i As Byte 
Dim x As String

Print IsByte(i) 
Print IsByte(x)

IsCurrency

Function IsCurrency(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if a variable represents a currency type.

Example

Dim c As Currency


c = 23

Print IsCurrency(c)

IsDate

Function IsDate(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if a variable represents a date type.

Example

PRINT ISDATE(34)
PRINT ISDATE(#2006-12-12#)

IsDateValid

Function IsDateValid(DateTime) As Boolean


IsDateTimeValid

Function IsDateTimeValid(DateTime) As Boolean


IsDouble

Function IsDouble(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if a variable represents a double type.

Example

Dim i As Double 
Dim x As String

Print IsDouble(i) 
Print IsDouble(x)

IsEmpty

  • Function IsEmpty(EXPRESSION) As Boolean

www.kbasic.com_images_vb6.jpg

Returns true if expression represents a empty value.

Example

Dim v As Variant
Dim n As Integer

v = Empty

Print IsEmpty(v)
Print IsEmpty(n)

v = 99

Print IsEmpty(v)

IsError

Function IsError(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if the expression represents an error type.

Example

Dim v As Variant
'Dim v As integer

v = Error 

Print IsError(v)


IsInteger

Function IsInteger(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if the expression represents an integer type.

Example

Dim i As Integer
Dim k As String

Print IsInteger(i)
Print IsInteger(k)

IsLeapYear

Function IsLeapYear(DateTime) As Boolean


IsMissing

Function IsMissing(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns if an optional argument of a sub/function has not been given = is missing.

Example

Sub test(Optional k As String)
  
  If IsMissing(k) Then
    Print "k is missing"     
  Else
    Print "k: " + k     
  End If
End Sub


test()
test("hello here is k")

IsNull

Function IsNull(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if the expression represents null.

Example

Dim o As Object

o = Null

Print IsNull(o)

IsNumeric

Function IsNumeric(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if expression represents a numeric value.

Example

Dim v As Variant
v = 12
v = "!"

Print IsNumeric(v)
Print IsNumeric(3343.678)
Print IsNumeric("hey")

IsObject

Function IsObject(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if expression represents an object value.

Example

Class t
  
End Class

Dim k As New t

Dim o As New Object
Dim z As Integer

Print IsObject(k)
Print IsObject(o)
Print IsObject(z)

IsShort

Function IsShort(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if expression represents a short value.

Example

Dim i As Short 
Dim x As String

Print IsShort(i) 
Print IsShort(x)

IsSingle

Function IsSingle(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if expression represents a single value.

Example

Dim i As Single 
Dim x As String

Print IsSingle(i) 
Print IsSingle(x)

IsLong

Function IsLong(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if expression represents a long value.

Example

Dim i As Long
Dim k As String

Print IsLong(i)
Print IsLong(k)

—–

IsString

Function IsString(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if expression represents a string value.

Example

Dim i As Long
Dim k As String

Print IsString(i)
Print IsString(k)

—–

IsTimeValid

Function IsTimeValid(DateTime) As Boolean


IsVariant

Function IsVariant(EXPRESSION) As Boolean www.kbasic.com_images_vb6.jpg

Returns true if expression represents a variant value.

Example

Dim i As Variant   
Dim x As String

Print IsVariant(i) 
Print IsVariant(x)

—–

--------K--------

KBasicDir

Function KBasicDir() As String

It returns the path to the KBasic installation directory.


Kill

Sub Kill FileName As String www.kbasic.com_images_vb6.jpg

Deletes a file specified by a filename. Like for DOS-based Basics, KILL deletes only files.

Example

' This deletes the file "test.xml":
KILL "c:\kbasic\examples\test\test.xml"

—–

--------L--------

LastIndexOf

Function LastIndexOf(String, Sub As String, Start As Integer = -1, CaseSensitive As Boolean = True) As Integer

Finds one string inside another (reversed).


LCase

Function LCase(STRINGEXPRESSION) As String

It returns a new string. It contains the source string converted to all lower case.

LCASE take a string and converts all its characters to lower case. It then returns a copy of the string.

Example

DIM src as string
src = "Mr. Big was HERE"
PRINT LCASE( src )

' Output:
' mr. big was here

See also UCase


Left

Function Left(STRINGEXPRESSION, Len As Integer) As String

LEFT returns a string containing the first characters of a string.

Example

DIM src AS STRING
src = "What a nice day"
PRINT LEFT(src, 4)

See also Right, Mid


LeftJustified

Function LeftJustified(String, Width As Integer, Fill As String = ” ”, Truncate As Boolean = False) As String

Returns a string of size width that contains this string padded by the fill character.


Len

  • Function Len(STRINGEXPRESSION) As Integer
  • Function Len(VARIABLENAME) As Integer

LEN returns the length of a string or the size of a variable in bytes.

Example

Dim s As String

s = "Bernd Noetscher's KBasic"

Print Len(s) 
''Print s.Len() 
''? "hi".Len() 

dim x as string
x = "a string"
PRINT LEN(x)

' Output:
' 8

See also SizeOf


Length

  • Function Length(STRINGEXPRESSION) As Integer

Returns the length of a string.

See also Size


Line

  • Sub Line[(x1!, y1!)] - (x2!, y2!) [, Color As Integer] ]

www.kbasic.com_images_vb6.jpg

Draws a line on the screen. Color might be a value between 0…255. Provided for QBasic compatibility.

 
CLS

For a As Integer = 1 To 15
  Line(10, a * 80) - (1000, a * 80), 15
Next

For a = 1 To 15
  Line(a * 80, 10) - (a * 80, 1000), 15
Next


For y As Integer = 1 To 100
    
  For i As Integer = 1 To 600
    Locate 1, 1 : Print "y=" + y + " : i=" + i
    
    Line(11 + i + y, 11 + i + y) - (2 * i + y, 11 + i + y), i / 10
    
  Next

Next
        
  • Sub Line Input [#]FilenNo As Integer, VARIABLENAME

www.kbasic.com_images_vb6.jpg

Reads line of text from file into variable. Provided for QBasic compatibility.

Example

Dim text2 As String
 
Open "c:\kbasic14\examples\test\test.txt" For Input As #1	' open file
Do While Not EOF(1)	' loop until end of file
	Line Input #1, text2	' read line into variable
	Print text2
Loop
Close #1

See also Print , Open , Write , Input , Inkey


Ln

Function Ln(n As Double) As Long

LN returns the natural logaritm of a number. The LN function calculates the base “e” (or natural) logaritm of a number. Input number must be a positive (i.e. > 0).

Example

DIM x AS INTEGER
x = 12
PRINT LN(x)

See also Log


Loc

Function Loc([#]FileNo As Integer) As Long www.kbasic.com_images_vb6.jpg

Returns the current position for reading or writing in a file.

Example

Dim Position1, Line1
Open "file1" For Binary As #1
Do While Not EOF(1)
Line1 = Line1 & Input(1, #1) 
Position1 = Loc(1) 

Print Line1; Tab; Position1
Loop
Close #1

See also EOF , Seek


Locate

Sub Locate [Y As Integer] [,X As Integer] [,Cursor As Integer] www.kbasic.com_images_vb6.jpg

Sets the cursor position on screen. Provided for QBasic backward compatibility.

Example

OPTION OLDBASIC

CLS
LOCATE 5, 5
row% = CSRLIN
column% = POS(0)
PRINT "position 1 (press any key)"
DO
LOOP WHILE INKEY$ = ""
LOCATE (row% + 2), (column% + 2)
PRINT "position 2"

See also CSRLin , Pos , Print


LOF

Function LOF([#]FileNo As Integer) As Long www.kbasic.com_images_vb6.jpg

Returns the length of a file in bytes. It returns -1 if the file is not available.

Example

OPTION OLDBASIC

INPUT "input filename: "; f$
'f$ = "c:\capture.avi"

OPEN f$ FOR BINARY AS #1
PRINT "file len is = "; LOF(1)
CLOSE

See also EOF , Open , Write


Log

  • Sub Log(STRING)

Implemented since KBasic V1.77

Prints a string to the Log window.

  • Function Log(n As Double) As Long

The LOG function calculates the ten-based logarithmic of a number. Input number must be a positive (i.e. > 0).

Example

DIM x AS INTEGER
x = 12
PRINT LOG(x)

See also LN


Lower

  • Function Lower(String) As String

Returns a new string. It contains the source string converted to all lower case.


LTrim

Function LTrim(STRINGEXPRESSION) As String

LTRIM function removes the source string's leading spaces, from the beginning of the source string.

Example

DIM x as string
x = " My house is on fire."
PRINT LTRIM( x )

' Output:
' My house is on fire.

See also RTrim , Trim


--------M--------

Max

Function Max(EXPRESSION, EXPRESSION) As Double

Returns the major value of two values. Both expressions must be numeric.

Example

PRINT MAX(44, 3)

See also Min


Mid (Builtin)

Function Mid(Variable As String, Start As Integer[, Len As Integer]) As String

Gets a part of a string.

Example

OPTION OLDBASIC

text$ = "The dog bites the cat"

text$ = MID$(text$, 10, 1)

PRINT text$

See also Trim , InStr


Min

Function Min(EXPRESSION, EXPRESSION) As Double

Returns the minor value of two values. Both expressions must be numeric.

Example

PRINT MIN(44, 3)

See also Max


Minute

Function Minute(DATEEXPRESSION) As Integer www.kbasic.com_images_vb6.jpg

Returns the minute part of a time expression.

Example

Dim Time1, Minute1
Time1 = #4:35:17 PM#	
Minute1 = Minute(Time1)	' Minute1 contains 35.
 

MkDir

Sub MkDir(String) www.kbasic.com_images_vb6.jpg

Creates a new directory.

Example

MKDIR "C:\TEMP\TEST"
CHDIR "C:\TEMP"
FILES
RMDIR "TEST"

See also CurDir, ChDir, ChDrive, RmDir


Month

Function Month(DATEEXPRESSION) As Integer www.kbasic.com_images_vb6.jpg

Returns the month part of a date expression.

Example

Dim Date1, Month1
Date1 = #1979-02-02#
Month1 = Month(Date1)	' Month1 contains 2.
Print Month1
 

MonthName

  • Function MonthName(DateTime, Format As String = ””) As String

Format may be “ShortFormat” or “LongFormat”. If no Format is given, “LongFormat” is used.



  • Function MonthName(Month As Integer, ShortName As Boolean) As String

www.kbasic.com_images_vb6.jpg

Returns the month part of a date expression.

Example

Dim strMonatsname 

strMonatsname = MonthName(1)  ' January
strMonatsname = MonthName(1, True)  ' Jan
 

MsgBox

Sub MsgBox(Prompt As String [, Buttons As Integer] [, Title As String])

Prints a message in a GUI dialog box.

buttons:

  • kbOKOnly 0 show only [OK].
  • kbOKCancel 1 show [OK] and [Cancel]
  • kbAbortRetryIgnore 2
  • kbYesNoCancel 3
  • kbYesNo 4
  • kbRetryCancel 5
  • kbCritical 16 Stop symbol
  • kbQuestion 32 question mark symbol
  • kbExclamation 48 exclamation mark symbol
  • kbInformation 64 information mark symbol
  • kbDefaultButton1 0
  • kbDefaultButton2 256
  • kbDefaultButton3 512

return values:

  • kbOK 1 OK
  • kbCancel 2 Cancel
  • kbAbort 3 Abort
  • kbRetry 4 Retry
  • kbIgnore 5 Ignore
  • kbYes 6 Yes
  • kbNo 7 No

Example

 
' text in richtext is possible as well
'n = MsgBox("<b>message</b> or <i>not</i>", kbOKOnly, "title text")

'n = MsgBox("message", kbOKOnly, "title text")
'n = MsgBox("message", kbOKCancel, "title text")
'n = MsgBox("message", kbAbortRetryIgnore, "title text")
'n = MsgBox("message", kbYesNoCancel, "title text")
'n = MsgBox("message", kbYesNo, "title text")
'n = MsgBox("message", kbRetryCancel, "title text")
'    
'n = MsgBox("message", kbOKOnly Or kbCritical, "title text")
'n = MsgBox("message", kbOKOnly Or kbQuestion, "title text")
'n = MsgBox("message", kbOKCancel Or kbExclamation, "title text")
'n = MsgBox("message", kbOKOnly Or kbInformation, "title text")
'    
'n = MsgBox("message", kbYesNoCancel Or kbDefaultButton1, "title text")
'n = MsgBox("message", kbYesNoCancel Or kbDefaultButton2, "title text")
'n = MsgBox("message", kbAbortRetryIgnore Or kbDefaultButton3, "title text")
'

n = MsgBox(" to save succeeding generations from the scourge of war, which twice in our lifetime has brought untold sorrow to mankind, and", kbOKOnly, "WE THE PEOPLES OF THE UNITED NATIONS DETERMINED")

See also InputBox


--------N--------

Name

Sub Name(OldName As String, NewName As String) www.kbasic.com_images_vb6.jpg

Renames a file or a directory.

Example

NAME "c:\old.txt" AS "c:\new.txt"

Now

Function Now() As DateTime

Returns the current system date.

Example

PRINT NOW()

Nz

Function Nz(EXPRESSION) As String

Changes to expression from null to nullstring ””, if needed.

Example

  
Function test()
  Return Null   
End Function

Print "'_" + Nz(test) + "_'" ' --> ""

--------O--------

Oct

Function Oct(EXPRESSION) As String www.kbasic.com_images_vb6.jpg

Returns a string giving the octal (base 8) representation of 'number'.

The return string has as many characters as necessary to represent the integer in octal, or the number specified by the second argument, whichever is larger. Octal numbers are just for fun.

Example

PRINT OCT(8)

/*
Oct (0 - 7)

Octal -> Decimal
0 -> 0
1 -> 1
2 -> 2
3 -> 3
4 -> 4
5 -> 5
6 -> 6
7 -> 7
10 -> 8
11 -> 9
12 -> 10

*/

See also Hex


Open

  • Sub Open STRINGEXPRESSION For [Input|Output|Append|Binary|Random] As [#]FileNo [LEN=RecordLen As Integer]

www.kbasic.com_images_vb6.jpg

Opens a file related on the given mode. Supported for backward compatibility.

STRINGEXPRESSION is the name of the file. It can contain path information.

mode

  • One of the following modes: APPEND, BINARY, INPUT, OUTPUT or RANDOM.

access (not supported)

  • READ, WRITE or READ WRITE.

READ Opens a file only for reading from file WRITE Opens a file only for writing to file READ WRITE Opens a file for writing and reading. READ WRITE is only possible for direct access and sequentiel files, and for files, which are opened for APPEND (sequentiel access)

lock(not supported)

Access permission inside network filesystem: SHARED, LOCK READ, LOCK WRITE or LOCK READ WRITE.

FileNo is an integer between 1 and 255, which names a file, which is opened. RecordLen is for direct access files: It is the length of the record (default is 128 byte). For sequentiel files: The amount of buffer characters (default is 512 Byte).

Example

INPUT "Input filename: "; n$
OPEN n$ FOR OUTPUT AS #1
PRINT #1, "This is stored in a file."
CLOSE
OPEN n$ FOR INPUT AS #1
INPUT #1, a$
PRINT "Readed from file: "; a$
CLOSE

See also Close , FreeFile , Type

  • Sub Open MODE, [#]FileNo, STRINGEXPRESSION, RecordLen As Integer

www.kbasic.com_images_vb6.jpg

Needed to open files (alternate syntax).

MODE “O” or “o” for output, “I” or “i” for input, “A” or “a” for append.

FileNo is an integer between 1 and 255, which names a file, which is opened.

STRINGEXPRESSION is the name of the file. It can contain path information.

RecordLen For direct access files: It is the length of the record (default is 128 byte).

For sequentiel files: The amount of buffer characters (default is 512 Byte).

Example

INPUT "What input file to use ??(e.g. C:\file.inp)? ", file$
OPEN "I", #1, file$  ' Open the input file
INPUT "What output file to use ??(e.g. C:\file.out)? ", file$
OPEN "O", #2, file$  ' Open the output file

See also Open


Output

Sub Open STRINGEXPRESSION For [Input|Output|Append|Binary|Random] As INTEGEREXPRESSION www.kbasic.com_images_vb6.jpg

Opens a file for writing. Supported for backward compatibility.

Example

OPTION OLDBASIC 

 
CLS
OPEN "c:\kbasic\examples\test\LISTEN.TXT" FOR OUTPUT AS #1
DO
    INPUT "   NAME:       ", Name$  'input from keyboard
    INPUT "   Age:        ", Age$
    WRITE #1, Name$, Age$
    INPUT "Type a new entry"; R$
LOOP WHILE UCASE$(R$) = "Y"
CLOSE #1

'print content of file
OPEN "c:\kbasic\examples\test\LISTEN.TXT" FOR INPUT AS #1
CLS
PRINT "entries of file:": PRINT
DO WHILE NOT EOF(1)
    LINE INPUT #1, REC$  
    PRINT REC$           
LOOP
CLOSE #1

--------P--------

Peek

Implemented since KBasic V1.77:

Sub Peek(ByRef String, UDF, Length As Integer) www.kbasic.com_images_vb6.jpg

Reads from a user defined type, length bytes of memory into a string.

Example

Type _udf
  Name As CString * 3
  Sec As CString * 6
End Type
Dim udf As _udf

Dim s As String = File.ReadBinary("C:\fish2.gif")

s.Poke(udf, Len(udf))
Print Left(udf.Name, 3)
Print Left(udf.Sec, 6)
    
s = ""
Peek(s, udf, Len(udf))
Print "-->" & Left(s, Len(udf))

See also Poke


Poke

Implemented since KBasic V1.77:

Sub Poke(STRING, UDF, Length As Integer) www.kbasic.com_images_vb6.jpg

Writes from a string into a user defined type (length bytes).

Example

Type _udf
  Name As CString * 3
  Sec As CString * 6
End Type
Dim udf As _udf

Dim s As String = File.ReadBinary("C:\fish2.gif")

s.Poke(udf, Len(udf))
Print Left(udf.Name, 3)
Print Left(udf.Sec, 6)
    
s = ""
Peek(s, udf, Len(udf))
Print "-->" & Left(s, Len(udf))

See also Peek


Pos

Function Pos(EXPRESSION) As Integer www.kbasic.com_images_vb6.jpg

POS returns the current cursor position in the line. EXPRESSION is obsolete, just write 0 for it.

Provided for QBasic backward compatibility.

Example

OPTION OLDBASIC 

PRINT POS(0)

INPUT s$

PRINT CSRLIN

PRINT s$

See also CSRLin , Locate


Prepend

Function Prepend(String, Prepend As String) As String

Prepends the string “Prepend” to the beginning of this string and returns it.


Print

  • Sub Print {[ [#]FileNo ,] (EXPRESSION Spc(EXPRESSION ) Tab(EXPRESSION) [; | ,]) }

www.kbasic.com_images_vb6.jpg

Provided for QBasic backward compatibility.

Example

PRINT "Hello baby!"; ":-)", "----"

DIM s AS STRING = "1"
DIM s2 AS STRING = "2"
DIM s3 AS STRING = "3"
 
PRINT s, s2, s3

2nd Example

OPTION OLDBASIC 

DIM Name$, Age$
 
CLS

OPEN "c:\kbasic14\examples\test\LIST4.txt" FOR OUTPUT AS #1
DO
  INPUT "   NAME:       ", Name$
  INPUT "   AGE:        ", Age$
  PRINT #1, Name$, Age$   
  INPUT "More entries?"; R$
LOOP WHILE UCASE$(R$) = "Y"
CLOSE #1

See also Input , Write , Using


PSet

Sorry. Not implemented yet. Please use Line instead.

  • Sub PSet [Step] (X As Integer ,Y As Integer ) [, Color As Integer]

www.kbasic.com_images_vb6.jpg

Draws a point on screen. Step is not supported. Provided for QBasic backward compatibility.

Example

 
OPTION OLDBASIC
OPTION EXPLICIT OFF 


FOR y% = 0 TO 200
  FOR x% = 0 TO 320
    PSET(x%, y%)
  NEXT
NEXT
 

See also Line


PrintScreen

  • Sub PrintScreen (PrintDialog As Boolean)

www.kbasic.com_images_vb6.jpg

Prints the screen. If PrintDialog = True, the print dialog appears before printing.


Put

Function Put([#]FileNo As Integer[, RecordNo As Integer], Variable As AnyType) www.kbasic.com_images_vb6.jpg

It writes a record to a file.

Example

TYPE TestRecord
    Student AS STRING * 20
    Result AS SINGLE
END TYPE

DIM meineKlasse AS TestRecord

OPEN "ENDRESULTS.DAT" FOR RANDOM AS #1 LEN = LEN(meineKlasse)
meineKlasse.Student = "Bernd Noetscher"
meineKlasse.Result = 99
PUT #1, 1, meineKlasse
CLOSE #1

OPEN "ENDRESULTS.DAT" FOR RANDOM AS #1 LEN = LEN(meineKlasse)
GET #1, 1, meineKlasse
PRINT "STUDENT:", meineKlasse.Student
PRINT "SCORE:", meineKlasse.Result
CLOSE #1

KILL "ENDRESULTS.DAT"

See also Type, Get


--------R--------

Rad

Function Rad(EXPRESSION) As Double

Example

PRINT RAD(8)

See also Sin, Cos


Raise

Sub Raise(Number As Integer[, Source As String[, Description As String] ]) www.kbasic.com_images_vb6.jpg

It is a method of the error object, which is provided for VB6 backward compatibility. Use exception handling instead, e.g. Try.

Example

Dim Msg

On Error Resume Next

Err.Clear
Err.Raise(6)

If Err.Number <> 0 Then
  
   Msg = "Error # " & Str(Err.Number) & " " _
       & Err.Source & Chr(10) & Err.Description
  
    Print Msg
  
End If

See also Try


Random

  • Function Random(EXPRESSION) As Double

Returns an integer pseudo-random number between 0 and int(EXPR)-1 inclusive. If EXPRESSION is 1, then returns a rational number between 0 (inclusive) and 1. If EXPRESSION is negative then EXPRESSION seeds the random number generator.

Example

RANDOMIZE
x% = INT(RANDOM(6)) + 1 
y% = INT(RANDOM(6)) + 1 
PRINT "2 turns with one dice: turn 1 ="; x%; "and turn 2 ="; y%

See also Randomize

  • Sub Open STRINGEXPRESSION For [Input|Output|Append|Binary|Random] As INTEGEREXPRESSION

www.kbasic.com_images_vb6.jpg

Opens a file for random access. Supported for backward compatibility.

Example

OPTION OLDBASIC

DIM Rec1$, Rec2$   
 
CLS
 OPEN "c:\kbasic\examples\test\LISTEN.TXT" FOR APPEND AS #1
 DO
     INPUT "   NAME:       ", Name$
     INPUT "   AGE:        ", Age$
     WRITE #1, Name$, Age$
     INPUT "More entries?"; R$
 LOOP WHILE UCASE$(R$) = "Y"
CLOSE #1

 'print file on screen
 OPEN "c:\kbasic\examples\test\LISTEN.TXT" FOR INPUT AS #1
 CLS
 PRINT "Entries of file:": PRINT
DO WHILE NOT EOF(1)
    INPUT #1, Rec1$, Rec2$   
    PRINT Rec1$, Rec2$       
LOOP
CLOSE #1
KILL "LIST"

Randomize

Sub Randomize [StartValue As Integer]

Start the random generator.

If you use Randomize with (), it will implicitly use TIMER.

Randomize()  ' --> same as RANDOMIZE TIMER

Example

RANDOMIZE TIMER 
x% = INT(RND * 6) + 1 
y% = INT(RND * 6) + 1 
PRINT "2 throws with one dice: 1st throw ="; x%; "and 2nd throw ="; y%

ReadBinary

Implemented since KBasic V1.78.

Function ReadBinary(String) As Boolean Throws Exception

Function ReadBinary(String) As String Throws Exception

Function ReadBinary(String) As Byte Throws Exception

Function ReadBinary(String) As Short Throws Exception

Function ReadBinary(String) As Integer Throws Exception

Function ReadBinary(String) As Long Throws Exception

Function ReadBinary(String) As Single Throws Exception

Function ReadBinary(String) As Double Throws Exception

Function ReadBinary(String) As Decimal Throws Exception

Function ReadBinary(String) As DateTime Throws Exception

Function ReadBinary(String) As Currency Throws Exception

Function ReadBinary(String) As Date Throws Exception


Remove

Function Remove(String, Position As Integer, Length As Integer) As String

Removes n characters from the string, starting at the given position index and returns it.


Replace

Function Replace (Str As String, SearchFor As String, ReplaceWith As String, CaseSensitive As Boolean = True) As String

Replaces string occurances with another string.

Example

DIM s = "Das ist alles was wir brauchen. Fang nochmal von vorne an."
DIM search = vorne"
DIM replace = "hinten"
PRINT REPLACE(s, search, replace) 

Reset

Sub Reset www.kbasic.com_images_vb6.jpg

Closes all opened files.

Example

Reset

Reversed

Function Reversed(String) As String

Returns a given string reversed


RGB

Function RGB(Red As Integer, Green As Integer, Blue As Integer) As Long www.kbasic.com_images_vb6.jpg

Returns a long value generated by a triple.

Example

Dim red As Integer

red = RGB(255, 0, 0)

Print Hex(red)

Function Right(STRINGEXPRESSION, Len As Integer) As String

Right returns a string containing the last characters of a string.

Example

 
PRINT RIGHT$("I'm living in Germany", 7)
'PRINT RIGHT$("I'm living in Germany", LEN("Germany"))

See also Left, Mid


RightJustified

Function RightJustified(String, Width As Integer, Fill As String = ” ”, Truncate As Boolean = False) As String

Returns a string of size() width that contains the fill character followed by the string.


RmDir

Sub RmDir(String) www.kbasic.com_images_vb6.jpg

Deletes a complete directory.

Example

MKDIR "C:\TEMP\TEST"
CHDIR "C:\TEMP"
FILES
RMDIR "TEST"

See also CurDir, ChDir, ChDrive, MkDir


RND

Function RND(EXPRESSION) As Double

Returns an integer pseudo-random number between 0 and int(EXPR)-1 inclusive. If EXPRESSION is 1, then returns a rational number between 0 (inclusive) and 1. If EXPRESSION is negative then EXPRESSION seeds the random number generator.

Example

RANDOMIZE TIMER 
x% = INT(RND * 6) + 1 
y% = INT(RND * 6) + 1 
PRINT "2 turns with one dice: turn 1 ="; x%; "and turn 2 ="; y%

See also Randomize


Round

Function Round(EXPRESSION, Precision As Integer = 0) As Currency/Double/Long

Implemented since KBasic V1.6 (q).

Rounds a value, while Precision determines the number of digits after the dot.

Example

Print Round(34.45@, 2)
Print Round(34.456@, 2)
Print Round(34.451@, 2)
Print Round(34.4567@, 2)
Print Round(34.4561@, 2)
Print Round(34.4517@, 2)

Print Round(34.4567@, 3)
Print Round(34.4517@, 3)
Print Round(34.4567@, 4)
Print Round(34.4561@, 4)

See also Int


RTrim

Function RTrim(STRINGEXPRESSION) As String

RTRIM function removes the source string's trailing spaces, from the end of the source string.

Example

PRINT RTRIM$("  bedazzeled  ")

See also LTrim , Trim


--------S--------

Second

Function Second(DATEEXPRESSION) As Integer www.kbasic.com_images_vb6.jpg

Returns the second part of a date expression.

Example

Dim Time1, Second1 
Time1 = #4:35:47 PM# 
Second1 = Second(Time1) ' Second1 contains 47

Section

Function Section(String, Separator As String, Start As Integer, End As Integer = -1, SectionFlags = “SectionDefault”) As String

This function returns a section of the string.


Seek

Sub Seek #FileNo, RecordPosition As Long www.kbasic.com_images_vb6.jpg

Returns the current position in file or set the new position in file.

Example

Option OldBasic

Type myRecordset ' define type
 id As Integer
 Name2 As String * 20
End Type

Dim DSet1 As myRecordset, MaxSize, DSetNo 

' file with random access
Open "c:\kbasic\examples\test\file1.txt" For Random As #1 Len = Len(DSet1)
MaxSize = 10 ' define count of records in file

For DSetNo = MaxSize To 1 Step - 1
  Seek #1, DSetNo ' set position
  
  DSet1.id = DSetNo
  DSet1.Name2 = "Bernd" + DSetNo * 1000
  
  Put #1, , DSet1  ' write recordset
Next
Close #1 ' close file


' file with random access
Open "c:\kbasic\examples\test\file1.txt" For Random As #1 Len = Len(DSet1)
MaxSize = LOF(1) \ Len(DSet1) ' define count of records in file
Print "MaxSize = " + MaxSize

For DSetNo = MaxSize To 1 Step - 1
  Seek #1, DSetNo  ' set position
  Get #1, , DSet1 ' read recordset
  
  Print DSet1.id
  'Print DSet1.Name2

Next
Close #1 ' close file

See also Open ,Get ,Put ,Write ,Print —–

SeekBinary

Implemented since KBasic V1.77

Function SeekBinary(String, Integer) As Integer Throws Exception

Set and returns the current position for binary reading and writing.


Sgn

Function Sgn(EXPRESSION) As Integer

SGN returns the sign of the argument 'number', +1 for positive numbers, 0 for 0, and - 1 for negative numbers.

Example

PRINT ABS(45.5 - 100!) 'result: 54.5
PRINT SGN(1), SGN(-1), SGN(0) 'result: 1 -1 0

See also Abs


Shell

Function Shell(EXPRESSION{, WAIT AS BOOLEAN = False}) As Long

Send a command to the environment. Return value is -255, if an error occured.

If WAIT = True, the executed command blocks until the command finished execution. If blocking works depends on the application started.

Example

SHELL ("DIR") ' on Windows
'SHELL ("LS")

Simplified

Function Simplified(String) As String

Returns a string that has whitespace removed from the start and the end, and that has each sequence of internal whitespace replaced with a single space.


Sin

Function Sin(EXPRESSION) As Double

SIN returns the sine of the argument 'number' in radians.

Example

CONST PI=3.141592654
PRINT ATN(TAN(PI/4.0)), PI/4.0 'result: .7853981635 .7853981635
PRINT (COS(180 * (PI / 180))) 'result: -1
PRINT (SIN(90 * (PI / 180))) 'result: 1
PRINT (TAN(45 * (PI / 180))) 'result: 1.000000000205103

See also Cos, Tan


Sleep

Sub Sleep [Seconds As Integer] www.kbasic.com_images_vb6.jpg

Waits for until a key was pressed, or the after a time period.

Example

PRINT "Pausing 10 seconds..."
SLEEP 10
PRINT "Continue..."

Space

Function Space(INTEGEREXPRESSION) As String

SPACE function creates a string consisting of spaces. SPACE creates a string of spaces based on x length. This function is similar to the STRING function.

Example

PRINT "*" + SPACE(5) + "*"

' Output:
' * *

PRINT SPACE$(4.3 + 2)

PRINT "*" + SPACE(5) + "*"

Spc

Function Spc(INTEGEREXPRESSION) As String

Returns a string with a number of spaces. Used together with Print.

Example

PRINT "Text1"; SPC(10); "Text2"

Split

Function Split(STRINGEXPRESSION, Separator As String, KeepEmptyParts As Boolean, CaseSensitive As Boolean) As Strings

Implemented since KBasic V1.6 (l).

This works a little different than the VB6 SPLIT function, because the return value is not String() - an array of String, but the data type Strings (which is internally a QStringList).


Sqr

Function Sqr(EXPRESSION) As Double

SQR returns the square root of the argument 'number'.

Example

PRINT SQR(25), SQR(2) 'result: 5 1.414214

StartsWith

Function StartsWith(String, String, CaseSensitive As Boolean = True) As Boolean

Returns true if the string starts with s; otherwise returns false.


Str

Function Str(EXPRESSION) As String

Converts a number to a string.

Example

PRINT STR$(239.546)

See also Asc , Val


StrComp

Function StrComp(STRINGEXPRESSION, STRINGEXPRESSION [, ComparisionMode As Integer]) As Integer

Compares two strings.

ComparisionMode : defines how to compare the two strings. Do not need to be given (optional)

Possible values are 0 and 1. The value 0 (default) means a binary compare. The value 1 means a text-based compare. If compare is not given, Option Compare defines how to compare.

Example

Dim Text1, Text2, Vergl

Text1 = "ABCD": Text2 = "abcd" ' 
Verg1 = StrComp(Text1, Text2, 1) ' result:0.
Verg1 = StrComp(Text1, Text2, 0) ' result:-1.
Verg1 = StrComp(Text2, Text1) ' result:1.

See also Asc , Val


String

The following functions only works, if OPTION VERYOLDBASIC or OPTION OLDBASIC has been set. Otherwise String (Cast) is executed.

If you need a similar function within OPTION KBASIC, use Fill and Unicode instead.

  • Function String(STRINGEXPRESSION, Len As Integer) As String

STRING function creates a string of characters.

Example

PRINT STRING(20, "x")

' Output:
' xxxxxxxxxxxxxxxxxxxx
  • Function String(Len As Integer, Ascii As Integer) As String

STRING function creates a string of characters.

Example

PRINT STRING(20, 65)
' would output AAAAAAAAAAAAAAAAAAAA.

StrReverse

Function StrReverse(STRINGEXPRESSION) As String

Returns a given string reversed.

Example

DIM s = "Mondscheinsonate by Beethoven"
PRINT STRREVERSE(s) ' --> nevohteeB yb etanosniehcsdnoM

SubDays

Function SubDays(DateTime, Days As Integer) As DateTime


SubHours

Function SubHours(DateTime, Hours As Integer) As DateTime


SubMinutes

Function SubMinutes(DateTime, Minutes As Integer) As DateTime


SubMonths

Function SubMonths(DateTime, Months As Integer) As DateTime


SubSeconds

Function SubSeconds(DateTime, Seconds As Integer) As DateTime


SubYears

Function SubYears(DateTime, Days As Integer) As DateTime


--------T--------

Tab

Function Tab(EXPRESSION) As String

Print Tabs. Used together with Print.

Example

CLS

Print "1", Tab(25) "Hio"
 
'Print "Hi", "2"


Tan

Function Tan(EXPRESSION) As Double

TAN returns the tangent of the argument 'number' in radians.

Example

CONST PI=3.141592654
PRINT ATN(TAN(PI/4.0)), PI/4.0 'result: .7853981635 .7853981635
PRINT (COS(180 * (PI / 180))) 'result: -1
PRINT (SIN(90 * (PI / 180))) 'result: 1
PRINT (TAN(45 * (PI / 180))) 'result: 1.000000000205103

See also Cos , Sin


Time

Function Time() As String www.kbasic.com_images_vb6.jpg

Date or TIME$ returns the current system time as a string. Setting the time is not possible with this builtin function.

Example

PRINT TIME

See also Date


TimeSerial

Function TimeSerial(Hour As Integer, Minute As Integer, Second As Integer) As Long www.kbasic.com_images_vb6.jpg

Returns a time as a integer.

Example

Dim Time1 
Time1 = TimeSerial(16, 35, 17) ' in integer format --> 16:35:17

TimeValue

Function TimeValue(STRINGEXPRESSION) As Date www.kbasic.com_images_vb6.jpg

Returns a time given in a string expression as a date.

Example

Dim Time1 
Time1 = TimeValue("4:35:17 PM") ' return time as date

Trim

Function Trim(STRINGEXPRESSION) As String

TRIM function removes the source string's leading and trailing spaces.

TRIM function removes the source string's leading and trailing spaces, from the beginning and end of the source string.The “trimmed” string is return to the function caller.

Example

DIM x as string
x = " My house is on fire. "
PRINT TRIM( x )

' Output:
' My house is on fire.

See also LTrim , RTrim


Trimmed

Function Trimmed(String) As String

Returns a string that has whitespace removed from the start and the end.


Truncate

Function Truncate(String, Position As Integer) As String

Truncates the string at the given position index and returns it.


TypeName

Function TypeName(VARIABLENAME) As String

Returns the type name of a variable as string

possible returns:

  • Byte
  • Integer
  • Long
  • Single
  • Double
  • Currency
  • Date
  • String
  • Boolean
  • Error
  • Empty
  • Null
  • Object
  • Nothing

Example

Class k
   
End Class

Enum e
  o 
End Enum
  
Type t
  o As Integer
End Type
  
   
Dim kk As k
Dim ee As e
Dim tt As t
Dim ll As Label
 
Dim NullVar, Type1, StrVar As String, IntVar As Integer, CurVar As Currency
Dim ArrayVar(1 To 5) As Integer

NullVar = Null ' Null zuweisen.
'NullVar = CVERR(2)
'NullVar = Empty 
  
Type1 = TypeName(StrVar)' returns "String".
Type1 = TypeName(IntVar) ' returns "Integer".
Type1 = TypeName(CurVar)' returns "Currency".

Type1 = TypeName(NullVar) ' returns "Null".

Type1 = TypeName(ArrayVar) ' returns "Integer()"
  
Type1 = TypeName(kk)

Type1 = TypeName(ee) ' returns the internal id only
Type1 = TypeName(tt) ' returns the internal id only

Type1 = TypeName(ll)
  
 

--------U--------

UCase

Function UCase(STRINGEXPRESSION) As String

It returns a new string. It contains the source string converted to all upper case.

It takes a string and converts all its characters to upper case. It then returns a copy of the string.

Example

DIM src as string
src = "Mr. Big was HERE"
PRINT UCASE( src )

' Output:
' MR. BIG WAS HERE

See also UCase


Unicode

  • Function Unicode(EXPRESSION) As String

Returns the Unicode character corresponding to the value of EXPRESSION. EXPRESSION must be a numerical expression.

  • Function Unicode(String, Position As Integer = 1) As Integer

Returns the character at the given index position in the string, if Position is unequal 1. Otherwise it returns it for the first character of the string.


Upper

  • Function Upper(String) As String

Returns a new string. It contains the source string converted to all upper case.


Using

Sub Print Using STRINGEXPRESSION; STRINGEXPRESSION [;|,]

Prints strings or numbers using a specified format

Formatted strings:

formatstring may contain \\ or ! or &

you can use "\\" to print a certain number of characters (n-2), so

"\\" will print 2
"\ \" will print 4 characters

A "!" will print only the first character of the string

A "&" will print the whole string

----------
Formatted numbers:
you can choose the width of the printing, the number of decimals and the place of the decimal point. Also the place of $, kommas and + or minus

- every # is a decimal digit (max 18)
- additional spaces right of the decimal point will be filled with 0
- additional spaces left of the decimal point will be filled with spaces
- exception: 1 > n > -1 when a 0 is before the decimal point
- all numbers rounded to number of digits
- negative numbers with a leading -
- this leading - takes one # in the formatstring

0.468 ##.## 0.47 one leading space
0.468 #.#### 0.4680 no leading space
12.5 ##.## 12.50 no leading space
12.5 ####.# 12.5 two leading spaces

Well, this is a bit confusing:

- a plus at the beginning produces a leading + or - before the number
- a minus at the beginning produces always a - (for positive and negative)
- a plus at the end produces a trailing + or -
- a minus at the end produces a space for positive and a - for negative numbers

Now the $ and stuff:
- a $ at the beginning: $ before the number
- for a negative value, the - is between $ and first digit
- several $ reserve additional spaces, but only one $ is printed
- two * fill the spaces with ***
- you can combine ** and $
- a comma left of decimal point marks thousands (1,000,000 - English style)

Exponentials:
- scientific notation by including 3 - 6 "^" signs
- one for "E", one for +/- and two to four for the exponents

Literals:
literals must be preceeded by a "_":

print using "_##"; 1 'prints #1
print using "#_#"; 1 'prints 1#

- if the number doesn't fit, the formatstring is ignored and the whole number with a leading "%" is printed

- variables may be used as formatstrings

- formatstrings may be emedded into normal text:

a = 12.56
x$= "sum"
PRINT USING "The & is $##.##";x$,a


  The formatstring is a string literal (or variable) containing literal
characters to print (such as labels) and special formatting characters.  These
  formatting characters determine the field and the format of the printed
string or numbers.  Spaces, commas, and semicolons in the expressionlist
have the same meaning as they do in a PRINT statement.

The expressionlist contains the string expressions or numeric expressions
to be printed, separated by semicolons.

When PRINT USING is used to print strings, you may use one of three formatting
characters to format the string field, as described in the following list:





!

Only the first character in the given string is
to be printed



\    \

Prints 2+n characters from a string where n is the
number of spaces between the two backslashes.  If the backslashes are typed
with no spaces, two characters are printed, and so on.  If the field is longer
than the string, the string is left-justified in the field and padded with
spaces to the right.



&

Indicates a variable length string field.  When
the field is specified with the ampersand (&), the string is output without
modification.



When PRINT USING is used to print numbers, the following special characters
can be used to format the numeric field:



Character

Description



#

Represents each digit position.  Digit positions
are always filled.  If the number to be printed has fewer digits than positions
specified, the number is right justified (preceded by spaces) in the field.



.

Prints a decimal point.  A decimal point may be
inserted at any position in the field. If the format string specifies that
a digit is to precede the decimal point, the digit is always printed (as
0, if necessary).  If necessary, numbers are rounded.



+

Causes the sign of the number (plus or minus) to
be printed before the number (if it appears at the beginningat
string) or after (if it appears at the endat string).



-

Causes a negative number to be printed with a trailing
minus sign if it appears at the endat string.



**

Causes leading spaces in the numeric field to be
filled with asterisks.  The double asterisk also specifies positions for
two more digits.



$$

Causes a dollar sign to be printed to the immediate
leftatted number.  The $$ specifies two more digit positions,
one of which is the dollar sign.



**$

Combines the effects of the double-asterisk and
double-dollar sign signals.  Leading spaces are asterisk filled, and a dollar
sign is printed before the number.  The **$ symbols specify three more digit
positions, one of which is the dollar sign. When negative numbers are printed,
the minus sign appears to the immediate left of the dollar sign.



,

If the comma appears to the left of the decimal
point, in a format string, it causes a comma to be printed to the left of
every third digit left of the decimal point.  If it appears at the end of
the format string, it is printed as part of the string.  A comma specifies
another digit position. The comma has no effect if used with exponential
(^^^^ or ^^^^^) format.



^^^^

Specifies exponential format.  You can also use
five carets (^^^^^) to allow E+xxx to be printed for larger numbers.  Any
decimal point position may be specified.  The significant digits are left
justified and the exponent is adjusted.  Unless a leading +, trailing +,
or - is specified, one digit position is used to the left of the decimal
point to print a space or a minus sign. 



_

An underscore in the format string prints the next
character as a literal character.  A literal underscore is printed as the
result of two underscores in the format string.



If he number to be printed is larger than the specified numeric field, a
percent sign (%) is printed in front of the number.  If rounding causes a
number to exceed the field, a percent sign is printed in front of the rounded
number. If the number of digits specified exceeds 24, an error message results
that reads <tt>Illegal function call.</tt>

Example

CLS

' numeric

PRINT USING "###"; 1


'PRINT USING "#####"; 12.12545 
'PRINT USING "###.##"; 12.12545 ' rounds automatically

'PRINT USING "+###"; +12.12345
'PRINT USING "+####"; -12.12345

'PRINT USING "x###x"; 12.12345
'PRINT USING "###.###"; 12.12345

'PRINT USING "$$####"; -12.12345
'PRINT USING "$$####"; -1234.12345
'PRINT USING "**####"; -12.12345
'PRINT USING "**$###"; -1.12345

'PRINT USING "$####"; -1.12345
'PRINT USING "*####"; - 1.12345

'PRINT USING "$$####"; -1.12345
'PRINT USING "####"; -12.12345

'PRINT USING "**$####-x"; -12.12345
'PRINT USING "####-x"; -12.12345
'PRINT USING "####-x"; 12.12345

'PRINT USING "+^^^^"; 12.12345 ' not allowed


'PRINT USING "**^^^^"; 290.12345
'PRINT USING "**^^^^^"; -999912.12345


'PRINT USING "##,.##"; 1.12345
'PRINT USING "##,.##"; 12.12345
'PRINT USING "##,.##"; 1234.12345
'PRINT USING "##,.##"; 123456.12345
'PRINT USING "##,.##"; 1234567.12345




' string

PRINT USING "x&x x&x"; "Hello World!", "Bernd"
'PRINT USING "x&x x&x"; "Hello World!"
'PRINT USING "x&x x&x"; "Hello World!",
'PRINT USING "x&x x&x"; "Hello World!";
'PRINT USING "x&x"; "Hello World!"
'PRINT USING "&"; "Hello World!"

'PRINT USING "_!_"; "Hello World!"

'PRINT USING "_\   \_"; "Hello World!"

'PRINT "Hello World!"

' escape code

'PRINT USING "x_&x&x"; "Hello World!"

See also Print


Utf8

Function Utf8(STRINGEXPRESSION) As CString

Returns a CString containing the unicode characters encoded as UTF8.

Function Utf8(CSTRINGEXPRESSION) As String

Returns a unicode String containing from a CString containing characters encoded in UTF8.

Example

' non-latin characters are lost when using CString
Dim c As CString = "论Bernd Nötscher" ' Unicode String is stored as Local8Bit ASCII C-String (information loosing)
Print c

Dim u As String
u = c ' Local8Bit C-String is converted to Unicode
Print u

u = "论Bernd Nötscher"
c = u ' store Unicode as Local8Bit in C-String (information loosing)
Print c

Print
Print "UTF8"
u = "论Bernd Nötscher"
c = Utf8(u) ' store Unicode as UTF8 in C-String
Print c

c = Utf8("论Bernd Nötscher") ' store Unicode as UTF8 in C-String
Print c

u = Utf8(c) ' store C-String encoded as UTF8 in Unicode
Print u

Print
Print "UTF16"

u = "论Bernd Nötscher"
c = Utf16(u, Len(u)) ' store Unicode as UTF16 in C-String
Print c

u = Utf16(c, 15) ' store C-String encoded as UTF16 in Unicode
Print u

See also UTF16


Utf16

Function Utf16(STRINGEXPRESSION, Length As Integer) As CString

Returns a CString containing the unicode characters encoded as UTF16.

Function Utf16(CSTRINGEXPRESSION, Length As Integer) As String

Returns a unicode String from a CString containing characters encoded in UTF16.

Example

Print "UTF16"
Dim u As String
Dim c As CString

u = "论Bernd Nötscher"
c = Utf16(u, Len(u)) ' store Unicode as UTF16 in C-String
Print c

u = Utf16(c, 15) ' store C-String encoded as UTF16 in Unicode
Print u

See also UTF8


--------V--------

Val

Function Val(STRINGEXPRESSION) As Double

VAL returns the numerical value of a string.

Example

Print Val("344") ' --> 344
Print Val("21st day") ' --> 21
Print Val("BASIC") ' --> 0

See also Str


Value

Function Value(STRINGEXPRESSION) As Double

Value returns the numerical value of a string.


VarType

Function VarType(VARIABLENAME) As Integer www.kbasic.com_images_vb6.jpg

Returns the type of a variable.

values are:

  • kbEmpty 0
  • kbNull 1
  • kbInteger 2
  • kbLong 3
  • kbSingle 4
  • kbDouble 5
  • kbCurrency 6
  • kbDate 7
  • kbString 8
  • kbObject 9
  • kbError 10
  • kbBoolean 11
  • kbVariant 12
  • kbByte 17
  • kbArray 8192

Example

 
Dim s As String

Print VarType(s)
 

See also Str


--------W--------

Weekday

Function Weekday(DATEEXPRESSION [,FirstDayOfWeek As Integer]) As Integer www.kbasic.com_images_vb6.jpg

Returns the weekday of a date.

Example

Dim Date1, Weekday1
Date1 = #2006-05-10#
Weekday1 = Weekday(Date1)	' Weekday1 contains 4

WeekdayName

Function WeekdayName(Weekday As Integer [,ShortName As Boolean, [,FirstDay As Integer] ]) As Integer www.kbasic.com_images_vb6.jpg

Returns the name of the given weekday.

Example

Dim sWDay As String
 
Dim n As Integer = Weekday(#2006-05-10#)

sWDay = WeekdayName(n)
 
MsgBox sWDay

WeekNumber

Function WeekNumber(DateTime) As Integer


Write

Sub Write [ [#]FileNo As Integer, EXPRESSION, EXPRESSION… www.kbasic.com_images_vb6.jpg

Writes data to the screen or a file.

FileNo is the number of an opened sequentiel file. If no fileno is given, the output is done to the screen. EXPRESSIONs, comma separated, which should be written to file or screen.

While writing between the elements commas and quotations are inserted.

Example

CLS
OPEN "LIST" FOR OUTPUT AS #1
DO
INPUT " NAME: ", Name$
INPUT " AGE: ", Age$
WRITE #1, Name$, Age$
INPUT "More entries?"; R$
LOOP WHILE UCASE$(R$) = "Y"
CLOSE #1
'print file on screen
OPEN "LIST" FOR INPUT AS #1
CLS
PRINT "Entries of file:": PRINT
DO WHILE NOT EOF(1)
INPUT #1, Rec1$, Rec2$ 
PRINT Rec1$, Rec2$ 
LOOP
CLOSE #1
KILL "LIST"

See also Input , Line , Open , Print


WriteBinary

Implemented since KBasic V1.78.

Sub WriteBinary(String, Boolean) Throws Exception

Sub WriteBinary(String, String) Throws Exception

Sub WriteBinary(String, Byte) Throws Exception

Sub WriteBinary(String, Short) Throws Exception

Sub WriteBinary(String, Integer) Throws Exception

Sub WriteBinary(String, Long) Throws Exception

Sub WriteBinary(String, Single) Throws Exception

Sub WriteBinary(String, Double) Throws Exception

Sub WriteBinary(String, Decimal) Throws Exception

Sub WriteBinary(String, DateTime) Throws Exception

Sub WriteBinary(String, Currency) Throws Exception

Sub WriteBinary(String, Date) Throws Exception


Year

Function Year(DATEEXPRESSION) As Integer www.kbasic.com_images_vb6.jpg

Returns the year of a date.

Example

Dim Date1, Year1 
Date1 = #2006-12-12# 
Year1 = Year(Date1) ' Year1 contains 1969.

--------MACRO--------

__Class__ (Macro)

This macro is replaced by the current class name at runtime. Use this for more information on your error messages.

Class lordoftherings
  
  Sub gandalf()
    
    Dim s As String
    
    If __IsClass__ Then
      s = __Class__       
    Else
      s = ""       
    End If
    
    Print "Gandalf is inside the class " + s
    
  End Sub    
  
End Class


' main part

Dim c As lordoftherings

c = New lordoftherings
c.gandalf()

If __IsClass__ Then
  Print "inside a class"
Else
  Print "is not inside a class"
EndIf
  

__File__ (Macro)

This macro is replaced by the current file name at runtime. Use this for more information on your error messages.


__IsClass__ (Macro)

This macro is replaced by ‘True’ if current scope is a class at runtime. Use this for more information on your error messages.


__IsLinux__ (Macro)

This macro is replaced by ‘True’ if your program is running on Linux. Use this for more information on your error messages.


__IsMacOS__ (Macro)

This macro is replaced by ‘True’ if your program is running on Mac. Use this for more information on your error messages.


__IsModule__ (Macro)

This macro is replaced by ‘True’ if current scope is inside a module at runtime. Use this for more information on your error messages.


__IsSub__ (Macro)

This macro is replaced by ‘True’ if current scope is inside a sub or function. Use this for more information on your error messages.


__IsWindows__ (Macro)

This macro is replaced by ‘True’ if your program is running on Windows. Use this for more information on your error messages.


__Line__ (Macro)

This macro is replaced by the current line at runtime. Use this for more information on your error messages.


__Module__ (Macro)

This macro is replaced by the current module name at runtime. Use this for more information on your error messages.


__Scope__ (Macro)

This macro is replaced by the current scope name at runtime (might be class/module/and/or sub/function. Use this for more information on your error messages.


__Sub__ (Macro)

This macro is replaced by the current sub or function name at runtime. Use this for more information on your error messages.


COMMENTS

How a comment should be

Some description here…

Example

some code

Written by AUTHOR

Date 2007-02-22

lrbuiltins.txt · Last modified: 2013/04/09 22:57 (external edit)