KDE TechBase
  • Page
  • Discussion
  • Edit
  • History
KDE TechBase is a Wiki - You can help! Please contribute! Questions?
Please ask development related questions in the KDE Community Forum.

Development/Languages/KBasic

< Development | Languages
Note
noframe
KBasic is still under development.


KBasic is a programming language, which is simply intuitive and easy to learn and is related to VB.NET™, Visual Basic®, Visual Basic for Application® and Java™. It combines the best features of those tools and comes with built-in backward support for those tools and QBasic® as it is 100% syntax compatible to VB6, VBA and QBasic®. Additionally, it comes with support for VB.NET™ syntax, functions and similar objects and classes.

The purpose of KBasic enabling BASIC developers to write desktop applications using the powerful technologies provided by Qt, KDE and related frameworks. For now the Qt API is covered.

Class Walzer
Public var As integer
End Class
 
Const globalConst = 1
Const globalConst2 As Integer = 2
 
Dim globalVar As Integer = 4
Dim globalVar2 As test
 
globalVar2 = test.Entry
 
' global scope
 
Enum test
Entry = 666
Entry2
Security = Entry
securus
secura
securum
End Enum
 
Type book
bkname As String * 100
 
isbn(1000) As Integer
End Type
 
Type address
books(50) As book
age As book
Name[9] As Integer
End Type
 
 
Sub globalSub()
Dim localVar = 99
End Sub
 
 
' module scope
 
Module module1
 
Public Type address2
age As Integer
End Type
 
Public Type module_type
element AS integer
End Type
 
Public Enum module_enum
Entry
Entry2
Security = Entry
End Enum
 
Const moduleConst = 7
 
Public publicModuleVar As Integer
Private privateModuleVar As Integer
 
 
Sub moduleExplicit()
 
Dim localVar = module1.publicModuleVar
Dim localVar2 = module1.moduleConst
 
' Dim localVar3 As module1.module_enum ' full type name not allowed after AS
Dim localVar3 As module_enum
localVar3 = module1.module_enum.Entry
'Dim localVar4 As module1.module_type ' full type name not allowed after AS
Dim localVar5 As module_type ' full type name not allowed after AS
End Sub
 
Sub moduleImplicit()
dim localVar = publicModuleVar
dim localVar2 = moduleConst
dim localVar3 as module_enum
localVar3 = module_enum.Entry
Dim localVar4 As module_type
Dim localVar5 As module_type
Dim localVar6 = module1.publicModuleVar
 
 
End Sub
 
Sub moduleSubWithDefaultArgument(ko as integer = 6)
Dim localVar = ko
End Sub
 
Sub moduleSubWithOptionalArgument(Optional ko As Integer)
If Not IsMissing(ko) Then
dim localVar = ko
End If
End Sub
 
Sub moduleSub()
Const localConst = 6
dim n = localConst
End Sub
 
Sub moduleSubWithArgument(i as integer)
dim localVar = i
End Sub
 
Sub moduleSubWithArgumentShadowing(i2 as integer)
Dim localVar = i2
Dim i2 = localVar + 99
dim i3 = i2
End Sub
 
Sub subOverloading ( )
print "sub1"
End Sub
 
Sub subOverloading ( i as integer = 1)
print "sub2"
End Sub
 
Function moduleFunction() As String
 
subOverloading()
subOverloading(88)
 
return "hello"
End function
 
function moduleFunctionRecursive(byref i as integer) as integer
if i > 6 then return 1''i
 
''i = i + 1
return moduleFunctionRecursive(1)''i)
End function
 
End Module
 
 
 
 
Class Salsa inherits Walzer
 
public Enum class_enum
Entry
Entry2
Security = Entry
End Enum
 
public type class_type
element AS integer
End Type
 
const classConst = 4
 
public publicInstanceVar as integer
Private privateInstanceVar As Integer
'Protected protectedInstanceVar As Integer
 
Static Public publicClassVar As Integer' = 8
'dim publicModuleType as module1.module_type
dim publicModuleType2 as module_type
 
' parent constructor call inside constructor
 
Sub meExplicit()
dim localVar = Me.publicInstanceVar ' it is the same with Parent
dim localVar2 = Me.publicClassVar
dim localVar3 = Salsa.publicClassVar
dim localVar4 = Salsa.classConst
Dim localVar5 = classConst
 
'Dim localVar5b = Me.classConst
' left
 
Dim localVar6 As class_enum
localVar6 = Salsa.class_enum.Entry
' Dim localVar7 As Me.class_enum ' full type name not allowed after AS
dim localVar8 as class_type
End Sub
 
Sub meImplicit()
dim localVar = publicInstanceVar
dim localVar2 = publicClassVar
dim localVar3 = classConst
Dim localVar4 As class_enum
dim localVar5 as class_type
 
End Sub
 
Sub classSub()
const localConst = 6
dim n = localConst
End Sub
 
Sub classSubWithArgument(i as integer)
dim localVar = i
End Sub
 
Function classFunction() As String
return "hello"
End Function
 
 
End Class
 
 
 
CLASS rumba
 
Public latein AS INTEGER
 
 
PUBLIC SUB dance_rumba()
Print "rumba!!!"
'print mySalsa.var
End Sub
 
' default constructor
 
Constructor rumba ()
print "constructor"
End Constructor
 
Constructor rumba ( _latein as integer)
Print "constructor2"
latein = _latein
End Constructor
 
Destructor rumba ( )
print "destructor"
End Destructor
 
Static Sub myMsgBox(ByRef m As Double)
'' m = m + 1
End Sub
 
Static Sub myMsgbox2(Optional m As Integer)
If IsMissing(m) Then
'' m = m + 1
Else
Print "do nothing"
End If
End Sub
 
Static Function monique(ByRef i As Integer, ByVal h As Double, ParamArray b() As Variant) As Integer
 
For i = LBound(b) To UBound(b)
Print b(i)
Next i
 
Return i
 
End Function
 
 
static SUB structByReference(byref m AS address)
''m.name[2] = 71
End Sub
 
END CLASS
 
 
DIM j(5 TO 10) AS address
 
 
''j(3).namer(6) = 123
''j(1).age.isbn(10) = 1000
''j[2].namer[1] = j(3).namer(6) + j(1).age.isbn(10)
 
 
 
'Dim Emp As rumba = New rumba
DIM r AS NEW rumba
 
r.dance_rumba()
 
'With r
' .dance_rumba()
'End With
 
 
Print globalVar ' accessable from everywhere
Print globalVar2 ' accessable from everywhere
Print globalConst ' accessable from everywhere
publicModuleVar = 99
module1.publicModuleVar = 99
 
'moduleFunctionRecursive(1)
' module1.moduleFunctionRecursive(1)
 
Print publicModuleVar
Salsa.publicClassVar = 111
Print Salsa.publicClassVar
print moduleConst
 
DIM m = 1 AS INTEGER

[edit] More information

  • http://www.kbasic.com/doku.php?id=kde
Retrieved from "http://techbase.kde.org/Development/Languages/KBasic"

Navigation

  • Home
  • Help
  • Recent changes

Sections

  • Getting started
  • Development
  • Schedules
  • Policies
  • Contribute
  • Projects

Toolbox

  • What links here
  • Related changes
  • Special pages
  • Printable version
  • Permanent link

Personal tools

  • 38.107.191.97
  • Talk for this IP
  • Log in / create account
  • Login with OpenID
Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal