User Tools

Site Tools


objects

OBJECTS

String

The Qt documentation in C++ of this class (QString) can be read here: http://doc.trolltech.com/4.4/qstring.html

Unicode support is implemented since V1.69i.

KBasic comes with two string types.

  • String (Unicode support, internally it is a native QString from Qt. UTF-8 is used to store the data)
  • CString (Local 8 Bit support ASCII, this is a native C string used as in C/C++)

You need to have installed Unicode support (e.g. Asian language and character sets) for Windows for this feature.

If a function accepts several string expressions and the first string expression is of type String (Unicode), all other expressions of type CString are converted to unicode using the local 8 bit character set automatically.

Reading and writing strings. If you use the String data type, the string data is encoded as UTF8 (like the KBasic's source codes within KBasic's IDE). But if you use CString, the data is treated as local 8 bit ASCII, which is useful for compatibility reasons to make old code working.

It is possible to use UTF16 for Windows API calls. To do so, use a CString and the function UTF16 to convert from String to CString.

If a Framework class method uses a String datatype it is actually internally Unicode QString, not a 8 Byte CString.

The 'String' class is a special class, so you do not need to instantiate it with 'New', because it is automatically done for you by KBasic.

Methods are

  • Function Len() As Integer ' returns the length of a string.
  • Function InStr([Start As Integer ,] Sub As String, CaseSensitive As Boolean = True) As Integer ' finds one string inside another.
  • Function InStRev([Start As Integer ,] Sub As String, CaseSensitive As Boolean = True) As Integer ' finds one string inside another (reversed).
  • Function Val() As Double ' returns the numerical value of the string.
  • Function Asc() As Integer ' returns the ASCII code or Unicode for a character.
  • Function Left(howMany As Integer) As String ' returns a string containing the first characters of a string.
  • Function Right(howMany As Integer) As String ' returns the remaining string after truncating the source string's length according to the desired length and returns the truncated string.
  • Function LCase() As String ' returns a new string. It contains the source string converted to all lower case.
  • Function UCase() As String ' returns a new string. It contains the source string converted to all upper case.
  • Function Trim() As String ' removes the source string's leading and trailing spaces.
  • Function RTrim() As String ' function removes the source string's last spaces.
  • Function LTrim() As String ' removes the source string's trailing spaces, from the end of the source string.
  • Function Mid(start As Integer [, length As Integer]) As String ' get the part of a string
  • Function StrComp(string [, compare]) As Integer' compares to strings
  • Function Replace(pattern As String, replace As String, CaseSensitive As Boolean = True) As String ' replaces string occurances with another string
  • Function StrReverse() As String ' returns a given string reversed

Implemented since KBasic V1.6 (l):

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

Implemented since KBasic V1.77:

  • Sub Peek(UDF, Length As Integer)

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

  • Sub Poke(UDF, Length As Integer)

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))

Implemented since KBasic V1.77

  • Function Length() As Integer ' returns the length of a string.
  • Function IndexOf(Sub As String, Start As Integer = 1, CaseSensitive As Boolean = True) As Integer ' finds one string inside another.
  • Function LastIndexOf(Sub As String, Start As Integer = -1, CaseSensitive As Boolean = True) As Integer ' finds one string inside another (reversed).
  • Function Value() As Double ' returns the numerical value of the string.
  • Function Lower() As String ' returns a new string. It contains the source string converted to all lower case.
  • Function Upper() As String ' returns a new string. It contains the source string converted to all upper case.
  • Function Append(String) As String' Appends the string str onto the end of this string and returns it.
  • Function Compare(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.
  • Function Contains(String, CaseSensitive As Boolean = True) As Boolean ' Returns true if this string contains an occurrence of the string str; otherwise returns false.
  • Function Count(String, CaseSensitive As Boolean = True) As Integer' Returns the number of (potentially overlapping) occurrences of the string str in this string.
  • Function EndsWith(String, CaseSensitive As Boolean = True) As Boolean ' Returns true if the string ends with s; otherwise returns false.
  • Function StartsWith(String, CaseSensitive As Boolean = True) As Boolean ' Returns true if the string starts with s; otherwise returns false.
  • Function Fill(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.
  • Function Insert(String, Position As Integer) As String ' Inserts the string str at the given index position and returns it.
  • Function LeftJustified(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.
  • Function Prepend(String) As String' Prepends the string str to the beginning of this string and returns it.
  • Function Remove(Position As Integer, Length As Integer) As String ' Removes n characters from the string, starting at the given position index and returns it.
  • Function RightJustified(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.
  • Function Section(Separator As String, Start As Integer, End As Integer = -1, SectionFlags = “SectionDefault”) As String ' This function returns a section of the string.

Possible values for SectionFlags

SectionDefaultEmpty fields are counted, leading and trailing separators are not included, and the separator is compared case sensitively.
SectionSkipEmptyTreat empty fields as if they don't exist, i.e. they are not considered as far as start and end are concerned.
SectionIncludeLeadingSepInclude the leading separator (if any) in the result string.
SectionIncludeTrailingSepInclude the trailing separator (if any) in the result string.
SectionCaseInsensitiveSepsCompare the separator case-insensitively.
  • Function Simplified() 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.
  • Function Trimmed() As String' Returns a string that has whitespace removed from the start and the end.
  • Function Truncate(Position As Integer) As String ' Truncates the string at the given position index and returns it.
  • Function Unicode(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.
  • Function Reversed() As String ' returns a given string reversed

Implemented since KBasic V1.78

  • Function ReadBinary(…) As String Throws Exception ' Reads a type from a binary string
  • Sub WriteBinary(…) Throws Exception ' Writes a type into a binary string
  • Function SeekBinary(…) As Integer Throws Exception ' Seeks the current position of a binary

Implemented since KBasic V1.79

  • Function Encode(String) As String ' Returns a string that is conform to sql statements
  • Function Decode(String) As String

Not implemented yet:

Print Escape(“this %1 is a miracle of %2\n”, “2333”, “erewr”)

\n werden erstetzt mit “CR”


Strings

The Qt documentation in C++ of this class (QStringList) can be read here: http://doc.trolltech.com/4.4/qstringlist.html

Implemented since KBasic V1.6 (l).

Methods are

  • Function Length() As Integer ' returns the count of string elements
  • Function Join(Separator As String) As String
  • Sub Append(String)
  • Sub SetString(Index As Integer, String)
  • Function String(Index As Integer) As String

Array

  • {Index As Integer} As String

Implemented since KBasic V1.78.

  • Sub Sort()
  • Sub RemoveAll()
  • Sub Remove(Index As Integer)
  • Sub Prepend(String)
  • Sub Insert(Index As Integer, String)
  • Sub Replace(Index As Integer, String)
  • Function Contains(String, CaseSensitive As Boolean = True) As Boolean
  • Function IndexOf(String, Position As Integer = 1) As Integer
  • Function LastIndexOf(String, Position As Integer = -1) As Integer

Example

Dim k As New Strings

k{1} = "Hello"
k{2} = "World"

For Each s As String In k
  Print s
Next

MsgBox k{1}

Not implemented yet:

  • Sub WriteBinary(String)
  • Function ReadBinary() As String

Dictionary

The Qt documentation in C++ of this class (QMap) can be read here: http://doc.trolltech.com/4.4/qmap.html

Implemented since KBasic V1.78.

Methods are

  • Function Length() As Integer
  • Sub Append(Key As String, Value As String)
  • Sub SetString(Key As String, Value As String)
  • Function String(Key As String) As String

Array

  • {Key As String} As String
  • Sub RemoveAll()
  • Sub Remove(Key As String)
  • Sub Insert(Key As String, Value As String)
  • Sub Replace(Key As String, Value As String)
  • Function Contains(Key As String) As Boolean
  • Function Keys() As Strings
  • Function Values() As Strings
  • Function Key() As String

Returns the current key. Only use it in a For Each Next loop.

  • Function Value() As String

Returns the current value. Only use it in a For Each Next loop.

Not implemented yet:

  • Sub WriteBinary(String)
  • Function ReadBinary() As String

Binary

The keyword 'Binary' is reserved for future versions of KBasic.

See String for an overview how to deal with binary data.

It enables you to read and write binary data in memory, storing and loading results from the file system.


Array

The Qt documentation in C++ of this class (QMap) can be read here: http://doc.trolltech.com/4.4/qmap.html

Implemented since KBasic V1.78.

KEY means

Key As Variant = ””, Key2 As Variant = ””, Key3 As Variant = ””, Key4 As Variant = ””, Key5 As Variant = ””, Key6 As Variant = ””, Key7 As Variant = ””, Key8 As Variant = ””

Array

  • {KEY} As Variant

Example

Dim t As Array = New Array()
  
t{"Name"} = "Julie Hepp"
Print t{"Name"}

t{"a", "Person", 123} = "Bernd Noetscher"
Print t{"a", "Person", 123}

Not implemented yet:

Methods are

  • Sub Set(KEY, Value As Variant)
  • Function Get(KEY) As Variant
  • Function Length(KEY) As Integer
  • Sub RemoveAll(KEY)
  • Sub Remove(KEY)
  • Sub Insert(KEY, Value As Variant)
  • Sub Replace(KEY, Value As Variant)
  • Function Contains(KEY) As Boolean
  • Function Keys(KEY) As Strings
  • Function Values(KEY) As Variants
  • Function Key() As String

Returns the current key. Only use it in a For Each Next loop.

  • Function Value() As Variant

Returns the current value. Only use it in a For Each Next loop.

  • Sub WriteBinary(String)
  • Function ReadBinary() As String

Bits

The Qt documentation in C++ of this class (QBitArray) can be read here: http://doc.trolltech.com/4.4/qbitarray.html

Implemented since KBasic V1.78.

  • Sub SetBit(Integer, Boolean)
  • Function Bit(Integer) As Boolean
  • Function TestBit(Integer) As Boolean
  • Sub ToggleBit(Integer)
  • Sub SetByte(Byte)
  • Sub SetShort(Short)
  • Sub SetInteger(Integer)
  • Function Byte() As Byte
  • Function Short() As Short
  • Function Integer() As Integer

Remember Byte is 8 bit, Short is 16 bit and Integer is 32 bit.

Not implemented yet:

  • Sub SetLong(Long)
  • Function Long() As Long

DateTime

Implemented since KBasic V1.78

The 'DateTime' class is a special class, so you do not need to instantiate it with 'New', because it is automatically done for you by KBasic.

Methods are


Err

Properties are

  • Property Number As Integer
  • Property Source As String
  • Property Description As String

Methods are

  • Sub Clear()
  • Sub Raise(Number As Integer)
  • Sub Raise(Number As Integer, Source As String)
  • Sub Raise(Number As Integer, Source As String, Description As String)

Not implemented yet:

LastDllError


Event

Declare this class in class file myEvent. It is used to receive several special events.

If you set a form to be automatically started on runtime in project properties, the events will not dispatched.

Class myEvent Inherits Event
    
  ' the following event handlers are possible

  Sub Forms_OnFormGotFocus(FormName As String)    
    Print "Forms_OnFormGotFocus! " & FormName    
  End Sub 
  
  
End Class 

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