REM ***** BASIC ***** Option Explicit Sub Main ZeigeText ZeigeDenText("Heute ist " & Format(date, "DDDD")) MsgBox FalscheFunktion(3.3) MsgBox EchteFunktion(3.3) Dim a a = 10 msgbox "Startwert von a : " & a rechnebyVal(a) msgbox "byVal, neuer Wert von a : " & a rechnebyRef(a) msgbox "byRef, neuer Wert von a : " & a rechne(3.54,8) rechne(" 87") arrayTest msgbox BSsub,0,"BSsub" msgbox BSfunction,0,"BSfunction" Status("Hallo Velo") msgbox(rueckwaerts( "Hallo","gross")) ' msgbox error$(14) Msgbox "Typ: 3 + 16 + 256 ", 3 + 16 + 256 , "Beispiel" IfBeispiel End Sub sub IfBeispiel dim Beispiel as Variant dim wert as integer for wert = 0 to 2 MsgBox "wert = " & wert,64 , "Schleifenstart" Beispiel = "1) If auf einer Zeile" ' Auf einer Zeile braucht es kein End If If wert = 0 then MsgBox "Wert ist Null",0,"Eine Zeile" : else MsgBox "Wert ist nicht Null",0,"Eine Zeile" Beispiel = "2) Iif" ' Aber da ist Iif besser MsgBox Iif(wert = 0, "Wert ist Null" , "Wert ist nicht Null") , 0,"Mit 'Iif'" Beispiel = "3) Normalfall" ' Mit If / End if gruppiert ists besser lesbar If wert = 0 then MsgBox "Wert ist Null",0,"mit 'If / End if' gruppiert" elseif wert = 1 then MsgBox "Der wert ist eins!",0,"mit 'If / End if' gruppiert" else MsgBox "Wert ist nicht Null",0,"mit 'If / End if' gruppiert" end If Next wert end sub function rueckwaerts(testo as string, Optional wie as string ) if IsMissing(wie) Then wie = "NORMAL" dim l as integer dim c as string dim t as string on error goto fehler Select case ucase(wie) case "GROSS" testo = ucase(testo) case "KLEIN" testo = lcase(testo) case "NORMAL" testo = lcase(testo) case else rueckwaerts = "Zweites Argument '" & wie & "' kann ich nicht verarbeiten" on error goto 0 exit function end Select ' msgbox "in der Funktion mit: " & Text l = len(testo) t = "" for i = l to 1 step - 1 c = mid(testo,i,1) t = t & c next rueckwaerts = t ' l & " - " & t = "" wie = "" exit function fehler: ' resume next rueckwaerts = "Fehler " & Err & ": " & Error$ & " In line : " & Erl ' & " - " & Now end function Sub Status(sText As String) On Error Resume Next ThisComponent.CurrentController.Frame.StatusBar.Message = sText On Error GoTo 0 End Sub function spielen Print "function spielen" ' wird auch wie msgbox auf der Tabelle gezeigt spielen = "Man sollte nichts merken" end function sub BSsub as string BSsub = "Rückgabewert aus der Subroutine" end sub function BSfunction 'as string BSfunction = "Rückgabewert aus der Funktion" end function sub arrayTest dim sArr() as String sArr = Array("Hallo","Velo","!") ' dim pArr(3) as string pArr(1) = "Velo" dim mArr(1 to 3 , 3) as string mArr(1,0) = "!" msgbox sArr(0) & " - " & pArr(1) & " - " & mArr(1,0) end sub sub rechne(zahl as integer, Optional ByVal freiwillig As integer ) if IsMissing(freiwillig) Then freiwillig = 2 msgbox Zahl * freiwillig end sub sub rechnebyVal(byVal zahl) ' byVal Angabe ist nötig zahl = Zahl * 2 end sub sub rechnebyRef( zahl) ' byRef kann weggelassen werden, da Standard zahl = Zahl * 2 end sub Sub ZeigeText MsgBox "Hallo!" End Sub Sub ZeigeDenText(text) MsgBox text End Sub Sub FalscheFunktion(Zahl) as string FalscheFunktion = zahl * 3 End Sub Function EchteFunktion(Zahl) EchteFunktion = zahl * 3 End Function