Byte, Short, Integer, Long | -1, 2, -44, 4453 |
Single | 21.32, 0.344, -435.235421.21 |
Double | 212.23 |
String | Is simply text, but it must start with a " and end with a " so that Objective-Basic can recognize it as string. Strings uses the same escape codes as Objective-C strings. Important escape codes are: \" = Double quotation mark, \\ = Backslash |
Boolean | Yes, No |
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(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
' 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 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 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 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, 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))
Dim src As String
src = "Mr. Big was HERE"
MsgBox(LCase(src))
' Output:
' mr. big was here
MsgBox(44, 4)
Function test()
Return Null
End Function
MsgBox("'_" + Nz(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)
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
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
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
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
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
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 ctr As Integer
For ctr = 1 To 5
MsgBox("Z", i)
Next
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
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
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.