'USE for testing FBDEBUGGER / NEED testinc.bas dim cpt As Integer,byt as byte #inclib "mylib" 'test lib #Inclib "mylib2" 'test DLL Enum eenum tenumneg=-1 tenum2=2 tenum3 tenum4 tenum99=99 End Enum Union pointers pbyte As Byte Ptr pinteger As Integer Ptr pany As Any ptr End Union Namespace Testnames dim As Integer xx End Namespace declare sub test() declare sub testparamref(ByRef As String,ByRef As ZString ptr,ByRef As integer) declare sub testparamval(Byval As String,Byval As ZString Ptr,ByVal As integer) declare sub test2() declare function test3(As byte) as String Declare Function Add2( ByVal x As Integer, ByVal y As Integer ) As Integer Declare Function sub2( Byref x As Integer, ByRef y As Integer ) As Integer Declare Sub testarray(ByRef As Integer,array() As Integer,As Integer=-1) #Include "testinc.bas" Type incl in1 As Byte in2 As ULongInt End Type type udt var1 as integer var2 as double psub as sub ptr test2 as sub () in(5) As incl end Type Type Tcd value As ZString * 32 Declare Constructor ( init_value As String ) Declare Destructor () End Type type tbitfield flag_0 : 1 as byte flag_1 : 1 as integer flag_2 : 1 as integer flag_3 : 1 as integer flag_4 : 1 as integer flag_5 : 1 as integer flag_6 : 1 as integer flag_7 : 1 as integer flag_8 : 1 as integer flag_9 : 1 as integer inter as integer flag_A : 3 as byte end Type type ttype aaa as integer bbb as ulongint end Type type udt2 a2(5) as ttype b2 as eenum c2 as integer Ptr d2 As eenum Ptr end type type udt1 a as integer b as udt2 c as ushort end type Dim Shared _ZTS7VEHICLE As Integer Dim Shared venum As eenum venum=tenumneg dim vudt1 as udt1 dim shared pudt1 as udt1 ptr pudt1=@vudt1 vudt1.a=1798585 vudt1.b.b2=tenum99 vudt1.c=45 vudt1.b.a2(0).aaa=987654 vudt1.b.c2=@vudt1.a vudt1.b.d2=@venum Constructor Tcd ( init_value As String ) value = init_value Print "Creating: "; value End Constructor Destructor Tcd () Print "Destroying: "; value End Destructor Sub MySub Dim x As Tcd = ("A.x") End Sub Type Vector2D As Single x, y Declare Operator Cast() As String Declare Property Length() As Single Declare Property Length( ByVal new_length As Single ) Declare Operator += ( ByRef rhs As Vector2D ) declare operator let (ByRef rhs As Vector2D ) declare sub testvec(as integer, as ushort,as ttype) End Type sub Vector2D.testvec( inte as integer, ush as ushort, typ as ttype) print Str(This.x) + Str(This.y) +Str(inte) end Sub 'Declare Operator + (ByRef v1 As Vector2D,ByRef v2 As Vector2D) As Vector2D Operator + (ByRef v1 As Vector2D,ByRef v2 As Vector2D) As Vector2D Return Type (v1.x+v2.x,v1.y+v2.y) End Operator Operator + (ByRef x As integer,ByRef v2 As Vector2D) As Vector2D Return Type (x/2+v2.x,x/2+v2.y) End Operator operator Vector2D.let (ByRef rhs As Vector2D ) this.x = rhs.x this.y = rhs.y end operator Operator Vector2D.+= (ByRef rhs As Vector2D ) this.x += rhs.x this.y += rhs.y End Operator Operator Vector2D.cast () As String Return "(" + Str(x) + ", " + Str(y) + ")" End Operator Property Vector2D.Length() As Single Length = Sqr( x * x + y * y ) End Property Property Vector2D.Length( ByVal new_length As Single ) Dim m As Single = Length If m <> 0 Then '' new vector = old / length * new_length x *= new_length / m y *= new_length / m End If End Property /' Test comments on multi line '/ dim a as integer=&h80000000 Dim sstring As String Dim zzstring as zstring * 17 =>"AAAAAAAAAAAAAAAA" Dim ffstring as string *40=>"Str fixe90123456789012345678901234567890" sstring="StRiNg" dim shared sng as single =>123,lgt as longint =>999999999999,dbl As Double dim b as byte =-125,ub as ubyte =8,sh as short=-31000,wstrg as wstring *30=>"TEST WSTRING" dim us as ushort=10,ui as uinteger =11,ul as ulongint =&hFFFFFFFFFFFFFF dim pbyte as byte ptr = @b,pulongint as ulongint ptr = @ul, pany as any Ptr, ppul As ULongInt Ptr Ptr Dim unionptr As pointers unionptr.pany=pbyte Print "B and pbyte ";b,pbyte,*pbyte,unionptr.pbyte,*unionptr.pbyte dim pstring as string ptr=VarPtr(sstring),arr(5) as udt Dim Shared sarr(7,9) As Integer ReDim Shared sarrb(1,3) As ULongInt Dim sarrt(2,5) As sub () reDim sarrq(9,11,13) As udt Print "adr sarrq ";@sarrq(0,0,0) Dim arrptr(2) As String Ptr ptr testnames.xx=10 Dim psub As Sub()=@test,ppsub As Sub() Ptr Dim pfunc As Function() As udt,ppfunc As Function() As Integer Ptr Dim vbf As tbitfield vbf.flag_1=1:vbf.flag_9=1:vbf.inter=12345:vbf.flag_A=5 'Common Shared As Integer tcommonredim() 'ReDim As Integer tcommonredim(2) 'tcommonredim(2)=999 'Common As Integer tcommon() 'ReDim As integer tcommon(2) 'tcommon(2)=19 Common As Byte tbcom tbcom=17 Print Add2(1,a) Print sub2(9,a) print "adr a= ";@a;" adr t=";@sstring;"adr zzstring";@zzstring print "adr strptr";strptr(sstring) print "adr lgt";@lgt for ii As Integer =1 to 5 ' change the value of ii to reduce the loop a+=1 print "running" :sstring=str(a)+ _ "ok" print "running again" Next 'just to see speed for ii As Integer =1 to 5000 a+=1 Next 'for testing byref param dim/redim array Dim array(5 To 9) As Integer,index As Integer ReDim array3() As Integer index=1 array(index)=12 Print @array(0) testarray(index,array()) Print array(index) index=11 testarray(index,array3(),15) Print @array3(0),array3(index) 'end of test dbl=-1.797693134862310E+308 sarr(1,1)=12 sarrb(1,1)=19 '==== testparamref("try literal","try literal",12) testparamref(sstring,zzstring,a) testparamval("try literal","try literal",12) testparamval(sstring,zzstring,a) test() a=99 :sstring="finish" print "adr:a";a,@a,"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" Dim x As Tcd = ("main.x") Scope Dim x As Tcd = ("main.scope.x") End Scope MySub Dim aop As Vector2D = ( 3, 4 ) Print "aop = "; aop Print "aop.length = "; aop.length Print aop.length = 10 Print "aop = "; aop Print "aop.length = "; aop.length Dim bvec As Vector2D = type( 8.9, 6.7 ) Print "b = "; bvec Print "aop + bvec = "; aop + bvec aop+=bvec print "after aop+=bvec aop = ";aop print "Next instruction end of the program ...." Sleep sub testparamref(ByRef tststring As String,ByRef tstzstring As ZString Ptr,ByRef tinteger As integer) Print tststring;" ";*tstzstring;" ";tinteger End Sub Sub testparamval(Byval vtststring As String,Byval vtstzstring As ZString Ptr,ByVal vtinteger As integer) Print vtststring;" ";*vtstzstring;" ";vtinteger End Sub '================= Sub testarray (ByRef index2 As Integer,arraybis() As Integer,predim As Integer=-1) If predim>=0 Then ReDim arraybis(predim,predim) Print @arraybis(0),uBound(arraybis) arraybis(index2)=123 End Sub sub test() dim testa as integer =>222 dim udt as udt Print "CRASH" 'Dim overstack(9999999) As Integer 'for exception stack overflow Print "Line with crash":Poke testa,10 'for access violation Print "all is right" static As Integer vstatic =123456 vstatic+=1 print "inside test #1" testa=999 :udt.var2=345.678 test2 print "Changed udt" end sub '====================== sub test2() dim testa as integer =>222 dim udt as udt static As Integer vstatic = 123457 vstatic+=10000 print "inside test #2" testa=999 :udt.var2=345.678 if testa=222 then exit sub sng=78999 print "Changed udt" print "try step out ";test3(13) end sub Type Rational As Integer numerator, denominator End Type Scope ' Create and initialize a Rational, and store it's address. Dim p As Rational Ptr = New Rational(3, 4) Print p->numerator & "/" & p->denominator ' Destroy the rational and give its memory back to the system. Delete p End Scope Scope ' Allocate memory for 100 integers, store the address of the first one. Dim p As Integer Ptr = New Integer[100] ' Assign some values to the integers in the array. For i As Integer = 0 To 99 p[i] = i Next ' Free the entire integer array. Delete[] p End Scope 'objects Type Vehicle extends object As String Name End Type Type Car extends Vehicle End Type Type Cabriolet extends Car End Type Type Bike extends Vehicle End Type Type tparent Dim As Integer prop End Type Type tchild extends tparent End Type Dim As car mycar mycar.name="big car" Dim As object Ptr p p=@mycar Dim As object obj obj=mycar Dim As tchild child child=type(123) If obj Is car Then Print "ok is a car" If (*p Is car) Then Print "ok is a car" Dim As car secondcar secondcar.name="bad one" Dim As Cabriolet porsche porsche.name = "Porsche" Dim As Bike mountainbike mountainbike.name = "Mountain Bike" Dim As Vehicle v v.name = "some unknown vehicle" '================ 'testbugs (unwanted data) Dim Shared As Integer bugarray(100) erase(bugarray) ReDim Shared As Integer arraybis(99) Dim As Integer kk,LT_0008 For r As Integer =1 To kk Next 'Select Case As Const implicit var: dim i as integer select case as const( i ) case 1 end select 'Select Case implicit var: dim jj as integer select case( jj + 1 ) case 1 end select 'With implicit var: type bugUDT i as integer end type dim bugx as bugUDT dim bugp as bugUDT ptr = @bugx with( *bugp ) print .i end With