Integer | -1, 2, -44, 4453 |
Float | 21.32, 0.344, -435.235421.21 |
Decimal | 21.99D, 0.3456D |
String | Is simply text, but it must start with a " and end with a " so that Q7Basic can recognize it as string. Strings uses the same escape codes as C++ strings. Important escape codes are: \" = Double quotation mark, \\ = Backslash |
Boolean | True, False |
MsgBox(Bin(128))
MsgBox(Str(239.546))
' CLS clearing the terminal screen
' with a new background color
Dim keypressed
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!"
Dim s
Print CSRLin()
Print "row = " + Pos()
Input s
Print "line = " + CSRLin
Input s
Signal on_ProjectOpen()
MsgBox("Hello")
End Signal
Event Init()
ExecAfterMSec(100, "on_ProjectOpen")
End Event
Color(5)
Print "Hi"
Color(15, 1)
Print "Nadja"
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
Dim Date1 As DateTime
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)
Dim Date1 As DateTime
Dim Msg
Date1 = InputBox("Input a date:")
Msg = "quarter: " & DatePart("q", Date1)
MsgBox(Msg)
Dim Date1 As DateTime
Date1 = DateSerial(1969, 2, 12) ' return Date1
Dim Date1 As DateTime
Date1 = DateValue("1979-02-03")
Dim Date1, Day1
Date1 = DateValue("1979-02-12")
Day1 = Day(Date1) ' --> 12
MsgBox(Str(239.546))
Signal on_ProjectOpen()
MsgBox("Hello")
End Signal
Event Init()
ExecAfterMSec(100, "on_ProjectOpen")
End Event
MsgBox(Exp(0), Exp(1)) ' result: 1 2.718282
MsgBox(Log10(1), Log10(Exp(1))) ' result: 0 1
Function test()
Dim x As Float
Dim y As Float
y = 1
For x = 1 To argument
y = y * x
Next
Return y
End Function
MsgBox(Fix(12.49), Fix(12.54)) ' both results are : 12
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
' 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
Dim v = InputBox("Please type in a number: ")
MsgBox("The hexadecimal representation is ", Hex(v))
Dim s As String
s = "Bernd Noetscher's Q7Basic"
MsgBox("string position = " & InStr(1, s, "Q7Basic"))
Dim x As String, y As String
x = "This is a string"
y = "s"
MsgBox(InStRev(x, y))
Dim s As String
s = "Bernd Noetscher's Q7Basic"
MsgBox("string position = " & InStr(1, s, "Q7Basic"))
Dim Msg, Titel, default2, val1
Msg = "Input value between 1 and 3"
Titel = "InputBox-Demo"
default2 = "1"
val1 = InputBox(Msg)
MsgBox("You have inputted: " + val1)
Dim n As Integer
n = Int(12.54)
MsgBox(n)
n = Int( - 99.4)
MsgBox(n)
Dim x As Boolean
Print IsBoolean(x)
Dim i As Byte
Dim x As String
Print IsByte(i)
Print IsByte(x)
Dim x As Boolean
Print IsBoolean(x)
Dim c As Decimal
c = 23.67D ' decimal literal
MsgBox(IsDecimal(c))
Dim i As Float
Dim x As String
Print IsFloat(i)
Print IsFloat(x)
Dim i As Float
Dim x As String
Print IsFloat(i)
Print IsFloat(x)
Dim i As Byte
Dim x As String
Print IsByte(i)
Print IsByte(x)
Dim x As Boolean
Print IsBoolean(x)
Dim i As Byte
Dim x As String
Print IsByte(i)
Print IsByte(x)
Dim x As Boolean
Print IsBoolean(x)
Dim i As Byte
Dim x As String
Print IsByte(i)
Print IsByte(x)
Dim x As Boolean
Print IsBoolean(x)
Dim i As Byte
Dim x As String
Print IsByte(i)
Print IsByte(x)
Dim x As Boolean
Print IsBoolean(x)
Dim i As Byte
Dim x As String
Print IsByte(i)
Print IsByte(x)
Dim x As Boolean
Print IsBoolean(x)
Dim i As List
Dim x As String
MsgBox(IsList(i))
MsgBox(IsList(x))
Dim o As Object
o = Null
MsgBox(IsNull(o))
Dim i As Byte
Dim x As String
Print IsByte(i)
Print IsByte(x)
Dim x As Boolean
Print IsBoolean(x)
Dim i As Float
Dim x As String
Print IsFloat(i)
Print IsFloat(x)
Dim i As Integer
Dim k As String
MsgBox(IsString(i))
MsgBox(IsString(k))
Dim src As String
src = "Mr. Big was HERE"
MsgBox(LCase(src))
' Output:
' mr. big was here
Dim x As String
x = " My house is on fire."
MsgBox(LTrim(x))
' Output:
' My house is on fire.
Dim x As String, y As String
x = "This is a string"
y = "s"
MsgBox(InStRev(x, y))
Dim src As String
src = "What a nice day"
MsgBox(Left(src, 4))
Dim x As Integer
x = 12
MsgBox(Ln(x))
CLS
Dim row, column
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"
Dim src As String
src = "Mr. Big was HERE"
MsgBox(LCase(src))
' Output:
' mr. big was here
MsgBox(44, 4)
Dim strMonatsname
strMonatsname = MonthName(1) ' January
strMonatsname = MonthName(1, True) ' Jan
MsgBox(Now())
Function test()
Return Null
End Function
MsgBox("'_" + Nz(test()) + "_'" ' --> "")
Dim s
MsgBox(Pos())
Input s
MsgBox(CSRLin())
MsgBox(s)
Randomize
Dim x, y
x = Int(Random(6)) + 1
y = Int(Random(6)) + 1
MsgBox("2 turns with one dice: turn 1 = " & x & " and turn 2 = " & y)
MsgBox("test..." & " bedazzeled " & "...test")
MsgBox("test..." & RTrim(" bedazzeled ") & "...test")
Randomize
Dim x, y
x = Int(Random(6)) + 1
y = Int(Random(6)) + 1
MsgBox("2 turns with one dice: turn 1 = " & x & " and turn 2 = " & y)
Dim s = "Das ist alles was wir brauchen. Fang nochmal von vorne an."
Dim search = "vorne"
Dim replace = "hinten"
MsgBox(Replace(s, search, replace))
MsgBox(Right("I'm living in Germany", 7))
' MsgBox(Right("I'm living in Germany", Len("Germany")))
MsgBox(Round(34.45D2))
MsgBox(Round(34.456D2))
MsgBox(Round(34.451D2))
MsgBox(Round(34.4567D2))
MsgBox(Round(34.4561D2))
MsgBox(Round(34.4517D2))
MsgBox(Round(34.4567D3))
MsgBox(Round(34.4517D3))
MsgBox(Round(34.4567D4))
MsgBox(Round(34.4561D4))
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
MsgBox("*" + Space(5) + "*")
' Output:
' * *
MsgBox(Space $(4.3 + 2))
MsgBox("*" + Space(5) + "*")
MsgBox(Sqr(25), Sqr(2)) ' results: 5 1.414214
MsgBox(Str(239.546))
Dim s = "Mondscheinsonate by Beethoven"
MsgBox(StrReverse(s)) ' --> nevohteeB yb etanosniehcsdnoM
MsgBox(Str(239.546))
Dim Time1
Time1 = TimeSerial(16, 35, 17) ' in integer format --> 16:35:17
Dim Time1
Time1 = TimeValue("4:35:17") ' return time string as datetime
Dim x As String
x = " My house is on fire. "
MsgBox("test..." & Trim(x) & "...test")
' Output:
' test...My house is on fire....test
Dim x As String
x = " My house is on fire. "
MsgBox("test..." & Trim(x) & "...test")
' Output:
' test...My house is on fire....test
Dim src As String
src = "Mr. Big was HERE"
MsgBox(UCase(src))
' Output:
' MR. BIG WAS HERE
Dim src As String
src = "Mr. Big was HERE"
MsgBox(UCase(src))
' Output:
' MR. BIG WAS HERE
MsgBox(Value("344")) ' --> 344
MsgBox(Val("21st day")) ' --> 21
MsgBox(Val("BASIC")) ' --> 0
MsgBox(Value("344")) ' --> 344
MsgBox(Val("21st day")) ' --> 21
MsgBox(Val("BASIC")) ' --> 0
Dim Date1, Day1
Date1 = DateValue("1979-02-12")
Day1 = Day(Date1) ' --> 12
Dim i As Double
Dim n As Integer
i = 4
Select Case i
Case 0
n = 0
Case 1, 2
n = 1122
Case 4 To 10
n = 441000
Case Is = 9
n = 9999
Case Else
n = 999999
End Select
Dim Name As Type
Const Name As Type
Public Name As Type
Private Name As Type
Public Const Name As Type
Private Const Name As Type
...
[ Public | Private]
Enum Name
Name As Type
...
End Enum
...
[ Public | Private]
Type Name
Name As Type
...
End Type
...
[ Public | Private]
Property Sub Name(Argument)
[Statements]
End Sub
...
[ Public | Private]
Property Function Name()
[Statements]
End Function
...
[ Public | Private]
Function Name([Arguments])[ As Type]
[Statements]
End Function
...
[ Public | Private]
Sub Name([Arguments])
[Statements]
End Sub
...
[ Public | Private]
Event Name([Arguments])
[Statements]
End Event
...
[ Public | Private]
Signal Name([Arguments])
[Statements]
End Signal
...
[ Public | Private]
Slot Name([Arguments])
[Statements]
End Slot
...
Sub Namer()
Const pi = 3.14
MsgBox(pi)
End Sub
Sub test
Dim k As Integer
k = 9 + 23
MsgBox(k)
End Sub
Const a = 123.88 * 2, bb = 6
Const k As Integer = 2
Sub test2()
Dim i As Double
i = bb
test
' a = i ' would cause a parser error
End Sub
Sub SubBefore()
Counter = 0
myNumber = 20
Do While myNumber > 10
myNumber = myNumber - 1
Counter = Counter + 1
Loop
MsgBox("Loop has been executed " & Counter & " time(s).")
End Sub
Sub SubAfter()
Counter = 0
myNumber = 9
Do
myNumber = myNumber - 1
Counter = Counter + 1
Loop While myNumber > 10
MsgBox("Loop has been executed " & Counter & " time(s).")
End Sub
Dim i As Integer
Dim n As Integer
If i 1 Then
n = 11111
Else If i = 2 * 10 Then
n = 22222
Else
n = 33333
End If
Enum Level
Mo = -1
Di = 0
Fr = 1
Sa = 1 + Fr And 2
End Enum
Enum test
Entry
Entry2
Security = Entry
End Enum
Sub test()
MsgBox(3 + Level.Mo)
MsgBox(test.Entry)
MsgBox(test.Security)
End Sub
Sub doingSomething()
MsgBox("did something")
Exit Sub
MsgBox("end of sub")
For i As Integer = 1 To 11
Exit For
MsgBox("xyz")
Next
End Sub
Function doingSomething2()
MsgBox("did something")
Exit Function
MsgBox("end of function")
End Function
Dim ctr As Integer
For ctr = 1 To 5
MsgBox("Z", i)
Next
' function example
Function divide(dividend As Float, divisor As Float) As Float
Return dividend / divisor
End Function
Sub Main()
MsgBox(divide(18, 9))
End Sub
Sub test()
Dim b As Integer
Dim n As Integer
b = 45
GoTo bernd
b = 99999
bernd :
n = 0
ok :
n = n + 1
If n < 5 Then GoTo ok
End Sub
Function testing(Test1 As Integer) As String
Return IIf(Test1 > 1000, "big", "small")
End Function
Sub Main()
MsgBox(testing(5))
MsgBox(testing(5555))
End Sub
Type book
bkname As String
isbn[1000] As Integer
End Type
Type address
books[50] As book
age As Integer
name As String
End Type
Dim j[10] As book
Sub Main()
MsgBox( LBound(j, 1))
End Sub
Sub Main()
Dim txt As String, replacement As String, originaltxt As String
replacement = "The power of Q7Basic"
originaltxt = "***********************"
Dim i As Integer
For i = 1 To Len(replacement)
Mid(originaltxt, 2, i) = replacement
MsgBox(originaltxt)
Next
End Sub
Dim Name As Type
Public Name As Type
Private Name As Type
Const Name As Type
Public Const Name As Type
Private Const Name As Type
...
[ Public | Private]
Enum Name
Name As Type
...
End Enum
...
[ Public | Private]
Type Name
Name As Type
...
End Type
...
[ Public | Private]
Function Name([Arguments])[ As Type][Throws Name,...]
[Statements]
End Function
...
[ Public | Private]
Sub Name([Arguments])[Throws Name,...]
[Statements]
End Sub
...
Dim ctr As Integer
For ctr = 1 To 5
MsgBox("Z", i)
Next
< code >
Sub Main()
Dim v As id
v = Null
End Sub
Sub Main()
Dim i[10] As Integer
i[0] = 99
i[1] = 88
i[2] = 77
i[3] = 66
i[4] = 55
i[5] = 44
ReDim Preserve i[20]
MsgBox(i[0])
End Sub
' . operator ! is direct access to dynamic properties of Qt
Dim myVar2
Property Sub Set _myVar2(ToValue)
MsgBox("Property Sub SetmyVar2(Set)")
myVar2 = ToValue
End Sub
Property Function Get _myVar2()
MsgBox("Property Function GetmyVar2()")
Return myVar2
End Function
Sub Main()
Dim i[10] As Integer
i[0] = 99
i[1] = 88
i[2] = 77
i[3] = 66
i[4] = 55
i[5] = 44
ReDim Preserve i[20]
MsgBox(i[0])
End Sub
Dim i As Double
Dim n As Integer
i = 4
Select Case i
Case 0
n = 0
Case 1, 2
n = 1122
Case 4 To 10
n = 441000
Case Is = 9
n = 9999
Case Else
n = 999999
End Select
Outlet someWidgetInUIFile As myControl Set ' myControl is a widget class, which replaces the original class used by the ui file before it gets loaded
Sub test()
Static Dim i As Integer = 0
MsgBox(i)
i = i + 1 ' this value is not lost after the sub exited
End Sub
Sub Main()
test()
test()
test()
End Sub
' sub example
Sub theMusic()
MsgBox("represents cuba")
MsgBox("your hips make a shift...")
MsgBox("I'm the one to find you in the mood...")
MsgBox("CUBA!")
MsgBox("represents cuba")
MsgBox("represents cuba")
End Sub
Sub Main()
theMusic() ' first use of sub
theMusic() ' 2nd use
theMusic() ' 3rd use
End Sub
Dim i As Integer
Dim n As Integer
If i 1 Then
n = 11111
Else If i = 2 * 10 Then
n = 22222
Else
n = 33333
End If
Dim i As Integer
Dim n As Integer
If i 1 Then
n = 11111
Else If i = 2 * 10 Then
n = 22222
Else
n = 33333
End If
Dim ctr As Integer
For ctr = 1 To 5
MsgBox("Z", i)
Next
Type book
bkname As String
isbn[1000] As Integer
End Type
Type address
books[50] As book
age As Integer
name As String
End Type
Dim j[10] As book
Sub Main()
MsgBox( LBound(j, 1))
End Sub
Type book
bkname As String
isbn[1000] As Integer
End Type
Type address
books[50] As book
age As Integer
name As String
End Type
Dim j[10] As book
Sub Main()
MsgBox( LBound(j, 1))
End Sub
Sub SubBefore()
Counter = 0
myNumber = 20
Do While myNumber > 10
myNumber = myNumber - 1
Counter = Counter + 1
Loop
MsgBox("Loop has been executed " & Counter & " time(s).")
End Sub
Sub SubAfter()
Counter = 0
myNumber = 9
Do
myNumber = myNumber - 1
Counter = Counter + 1
Loop While myNumber > 10
MsgBox("Loop has been executed " & Counter & " time(s).")
End Sub
(C)opyright KBasic Software 2009-2011. All right reserved.