Some useful macros ?

Share your advanced PureBasic knowledge/code with the community.
technicorn
Enthusiast
Enthusiast
Posts: 105
Joined: Wed Jan 18, 2006 7:40 pm
Location: Hamburg

Some useful macros ?

Post by technicorn »

Code updated For 5.20+

Here are some Macros I made since PB4 is out

Code: Select all

#STD_WinFlags = #PB_Window_TitleBar|#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget
#STD_WinFlagsFixedSize = #PB_Window_TitleBar|#PB_Window_SystemMenu

#STD_BufferSize = 4096


Macro mHASH
  #
EndMacro

Macro mDQUOTE
  "
EndMacro

Macro EnumNextBit
  (#PB_Compiler_EnumerationValue & (((#PB_Compiler_EnumerationValue & 1) = 0) * -1)) | (((#PB_Compiler_EnumerationValue >> 1) << 2) & (((#PB_Compiler_EnumerationValue & 1) = 1) * -1)) | (#PB_Compiler_EnumerationValue < 2)
EndMacro

Macro Ubound(array)
  (PeekL(@array - 8) - 1)
EndMacro

Macro ArrayType(array)
  PeekL(@array - 4)
EndMacro

Macro Inc(v)
  v = (v) + 1
EndMacro

Macro Dec(v)
  v = (v) - 1
EndMacro

Macro ReturnZeroIfFalse(test)
  If Not (test): ProcedureReturn 0: EndIf
EndMacro

Macro GetStartTime(v)
  v = ElapsedMilliseconds(): While v = ElapsedMilliseconds(): Wend: v = ElapsedMilliseconds()
EndMacro

Macro SetEnumValue(a)
  Enumeration a
  EndEnumeration
EndMacro

Macro IncEnumValue()
  Enumeration #PB_Compiler_EnumerationValue + 1
  EndEnumeration
EndMacro

Macro DecEnumValue()
  Enumeration #PB_Compiler_EnumerationValue - 1
  EndEnumeration
EndMacro

Macro SetConstantToEnumValue(c)
  Enumeration #PB_Compiler_EnumerationValue
    c
  EndEnumeration
EndMacro

Macro DebugVarUB(v,lvl=0)
  Debug mDQUOTE#v#mDQUOTE + " = " + StrU(v, 0), lvl
EndMacro

Macro DebugVarUW(v, lvl=0)
  Debug mDQUOTE#v#mDQUOTE + " = " + StrU(v, 1), lvl
EndMacro

Macro DebugVarUL(v, lvl=0)
  Debug mDQUOTE#v#mDQUOTE + " = " + StrU(v, 2), lvl
EndMacro

Macro DebugVarUQ(v, lvl=0)
  Debug mDQUOTE#v#mDQUOTE + " = " + StrU(v, 4), lvl
EndMacro

Macro DebugVarB(v, lvl=0)
  Debug mDQUOTE#v#mDQUOTE + " = " + Str(v), lvl
EndMacro

Macro DebugVarW(v, lvl=0)
  Debug mDQUOTE#v#mDQUOTE + " = " + Str(v), lvl
EndMacro

Macro DebugVarL(v, lvl=0)
  Debug mDQUOTE#v#mDQUOTE + " = " + Str(v), lvl
EndMacro

Macro DebugVarQ(v, lvl=0)
  Debug mDQUOTE#v#mDQUOTE + " = " + StrQ(v), lvl
EndMacro

Macro DebugVarF(v, lvl=0, d=-1)
  CompilerIf d = -1
  Debug mDQUOTE#v#mDQUOTE + " = " + StrF(v), lvl
  CompilerElse
  Debug mDQUOTE#v#mDQUOTE + " = " + StrF(v, d), lvl
  CompilerEndIf
EndMacro

Macro DebugVarD(v, lvl=0, d=-1)
  CompilerIf d = -1
  Debug mDQUOTE#v#mDQUOTE + " = " + StrD(v), lvl
  CompilerElse
  Debug mDQUOTE#v#mDQUOTE + " = " + StrD(v, d), lvl
  CompilerEndIf
EndMacro

Macro DebugVarS(v, lvl=0)
  Debug mDQUOTE#v#mDQUOTE + " = " + v, lvl
EndMacro

Macro DebugVarSDQT(v, lvl=0)
  Debug mDQUOTE#v#mDQUOTE + " = " + #DQUOTE$ + v + #DQUOTE$, lvl
EndMacro

Macro DebugVarSSQT(v, lvl=0)
  Debug mDQUOTE#v#mDQUOTE + " = " + "'" + v + "'", lvl
EndMacro

Structure CHAR
  c.c
EndStructure

Structure CHARARRAY
  c.c[0]
EndStructure

Structure BYTEARRAY
  b.b[0]
EndStructure

Structure WORDARRAY
  w.w[0]
EndStructure

Structure LONGARRAY
  l.l[0]
EndStructure

Structure QUADARRAY
  q.q[0]
EndStructure

Structure FLOATARRAY
  f.f[0]
EndStructure

Structure DOUBLEARRAY
  d.d[0]
EndStructure

Structure STRINGARRAY
  s.s[0]
EndStructure

Structure ADDRARRAY
  a.l[0]  ; We might get quad memory addresses with PB5 ?! ;)
EndStructure

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    ; Macro PathSlash$
      ; "/"
    ; EndMacro
    #PathSlash$ = "/"
    #PathSlash = '/'
    #FilenamesCaseSensitive = -1
  CompilerCase #PB_OS_Windows
    ; Macro PathSlash$
      ; "\"
    ; EndMacro
    #PathSlash$ = "\"
    #PathSlash = '\'
    #FilenamesCaseSensitive = 0
    CompilerCase #PB_OS_MacOS
    ; I don't know Mac
CompilerEndSelect
And here a program that shows how to use them
(and to prove they are working :wink: )

Code: Select all

;IncludePath #STD_IncludePath
XIncludeFile "standard.pbi"

DebugLevel 5

Structure ZTESTSTRUC
  l.l
  s.s
EndStructure

Procedure ShowStrings(*pSA.STRINGARRAY)
  Protected i
  
  For i = 0 To PeekL(*pSA - 8) - 1
    Debug *pSA\s[i]
  Next i
EndProcedure

Dim vb.b(10)
Dim vw.w(11)
Dim vl.l(12)
Dim vq.q(13)
Dim vf.f(14)
Dim vd.d(15)
Dim vs.s(16)
Dim vs$(17)
Dim vzts.ZTESTSTRUC(18)
Dim vmd.d(2,3,4)

Debug "Ubound() and ArrayType()"
Debug ""
Debug "Ubount(vb())      : " + Str(Ubound(vb()))
Debug "ArrayType(vb())   : " + Str(ArrayType(vb()))

Debug ""
Debug "Ubount(vw())      : " + Str(Ubound(vw()))
Debug "ArrayType(vw())   : " + Str(ArrayType(vw()))

Debug ""
Debug "Ubount(vl())      : " + Str(Ubound(vl()))
Debug "ArrayType(vl())   : " + Str(ArrayType(vl()))

Debug ""
Debug "Ubount(vq())      : " + Str(Ubound(vq()))
Debug "ArrayType(vq())   : " + Str(ArrayType(vq()))

Debug ""
Debug "Ubount(vf())      : " + Str(Ubound(vf()))
Debug "ArrayType(vf())   : " + Str(ArrayType(vf()))

Debug ""
Debug "Ubount(vd())      : " + Str(Ubound(vd()))
Debug "ArrayType(vd())   : " + Str(ArrayType(vd()))

Debug ""
Debug "Ubount(vs())      : " + Str(Ubound(vs()))
Debug "ArrayType(vs())   : " + Str(ArrayType(vs()))

Debug ""
Debug "Ubount(vs$())     : " + Str(Ubound(vs$()))
Debug "ArrayType(vs$())  : " + Str(ArrayType(vs$()))

Debug ""
Debug "Ubount(vzts())    : " + Str(Ubound(vzts()))
Debug "ArrayType(vzts()) : " + Str(ArrayType(vzts()))

Debug ""
Debug "Ubount(vmd())     : " + Str(Ubound(vmd()))
Debug "ArrayType(vmd())  : " + Str(ArrayType(vmd()))


byteVar.b = $FF
wordVar.w = $FFFF
longVar.l = $FFFFFFFF
quadVar.q = $FFFFFFFFFFFFFFFF
floatVar.f = 1.234567891234
doubleVar.d = 1.234567891234
stringVar$ = "This is a string with $"
stringVar.s = "This is a string without $"

Debug ""
Debug ""
Debug "DebugVarx()"
DebugVarUB(byteVar)
DebugVarB(byteVar)
DebugVarUW(wordVar)
DebugVarW(wordVar)
DebugVarUL(longVar)
DebugVarL(longVar)
DebugVarUQ(quadVar)
DebugVarQ(quadVar)
DebugVarF(floatVar)
DebugVarF(floatVar,0,3)  ; Show only three decimals
DebugVarD(doubleVar)
DebugVarD(doubleVar,0,3)  ; Show only three decimals
DebugVarS(stringVar$)
DebugVarSDQT(stringVar$)
DebugVarSSQT(stringVar$)
DebugVarS(stringVar)
DebugVarSDQT(stringVar)
DebugVarSSQT(stringVar)

Debug ""
Debug ""
Debug "DebugVarx() now with DebugLevel, will show or not"
DebugVarUB(byteVar, 5)
DebugVarB(byteVar, 5)
DebugVarUW(wordVar, 5)
DebugVarW(wordVar, 5)
DebugVarUL(longVar, 5)
DebugVarL(longVar, 5)
DebugVarUQ(quadVar, 5)
DebugVarQ(quadVar, 5)
DebugVarF(floatVar, 5)
DebugVarF(floatVar,5, 3)  ; Show only three decimals
DebugVarD(doubleVar, 5)
DebugVarD(doubleVar, 5, 3)  ; Show only three decimals
DebugVarS(stringVar$, 5)
DebugVarSDQT(stringVar$, 5)
DebugVarSSQT(stringVar$, 5)
DebugVarS(stringVar, 5)
DebugVarSDQT(stringVar, 5)
DebugVarSSQT(stringVar, 5)

Debug ""
Debug ""
Debug "Enum bit masks"

Enumeration   ; Startvalue must be 0,1 or any 2^x and will give consecutive bit masks
  #FlagBit1 = EnumNextBit
  #FlagBit2 = EnumNextBit
  #FlagBit3 = EnumNextBit
  #FlagBit4 = EnumNextBit
  #FlagBit5 = EnumNextBit
EndEnumeration

DebugVarL(#FlagBit1)
DebugVarL(#FlagBit2)
DebugVarL(#FlagBit3)
DebugVarL(#FlagBit4)
DebugVarL(#FlagBit5)

Debug ""
Debug ""
Debug "Use of the ARRAY structures"
For i = 0 To Ubound(vs$())
  vs$(i) = "String" + Str(i)
Next i
*pStrArray.STRINGARRAY = @vs$()
Debug "Show strings direct"
For i = 0 To Ubound(vs$())
  Debug *pStrArray\s[i]
Next i
Debug ""
Debug "Show strings with procedure"
ShowStrings(*pStrArray)

Debug ""
Debug ""
Debug "Inc(c), Dec(v)"
x1.l = 0
Debug "Before Inc(): " + Str(x1)
Inc(x1)
Debug "After Inc(): " + Str(x1)
Dec(x1): Dec(x1)
Debug "After 2 * Dec(): " + Str(x1)

Debug ""
Debug #LF$ + "Done"
Make whatever you like with them
technicorn
Enthusiast
Enthusiast
Posts: 105
Joined: Wed Jan 18, 2006 7:40 pm
Location: Hamburg

Post by technicorn »

Ok, here is a second version
It uses a DQtMe() Macro to quote variable names.
I think it looks better now

A new macro DebugMVarL() can now show up to four variables values
in one debug line.

There is also a new Macro DebugIf()
You can use it to only show debugmessages it a condition is true
and it expands to nothing, if the debuggíng is turned off.

If you would use:

Code: Select all

If var > 123: Debug var: Endif
then the "If var > 123: Endif" would still be in the final code.

If you now use:

Code: Select all

DebugIf( var > 123: Debug var)
then the code will completely removed when not in debug mode.

So here is the new version:

Code: Select all

#STD_WinFlags = #PB_Window_TitleBar|#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget
#STD_WinFlagsFixedSize = #PB_Window_TitleBar|#PB_Window_SystemMenu

#STD_BufferSize = 4096


Macro mHASH
  #
EndMacro

Macro mDQUOTE
  "
EndMacro

Macro mSQUOTE
  '
EndMacro

Macro EnumNextBit
  (#PB_Compiler_EnumerationValue & (((#PB_Compiler_EnumerationValue & 1) = 0) * -1)) | (((#PB_Compiler_EnumerationValue >> 1) << 2) & (((#PB_Compiler_EnumerationValue & 1) = 1) * -1)) | (#PB_Compiler_EnumerationValue < 2)
EndMacro

Macro Ubound(array)
  (PeekL(@array - 8) - 1)
EndMacro

Macro ArrayType(array)
  PeekL(@array - 4)
EndMacro

Macro Inc(v)
  v = (v) + 1
EndMacro

Macro Dec(v)
  v = (v) - 1
EndMacro

Macro ReturnZeroIfFalse(test)
  If Not (test): ProcedureReturn 0: EndIf
EndMacro

Macro GetStartTime(v)
  v = ElapsedMilliseconds(): While v = ElapsedMilliseconds(): Wend: v = ElapsedMilliseconds()
EndMacro

Macro SetEnumValue(a)
  Enumeration a
  EndEnumeration
EndMacro

Macro IncEnumValue()
  Enumeration #PB_Compiler_EnumerationValue + 1
  EndEnumeration
EndMacro

Macro DecEnumValue()
  Enumeration #PB_Compiler_EnumerationValue - 1
  EndEnumeration
EndMacro

Macro SetConstantToEnumValue(c)
  Enumeration #PB_Compiler_EnumerationValue
    c
  EndEnumeration
EndMacro

Macro DQtMe(v)
  mDQUOTE#v#mDQUOTE
EndMacro

Macro SQtMe(v)
  mSQUOTE#v#mSQUOTE
EndMacro

CompilerIf #PB_Compiler_Debugger
Macro DebugIf(v)
  If v: EndIf
EndMacro
CompilerElse
Macro DebugIf(v)
EndMacro
CompilerEndIf

Macro DebugMVarL(v1, v2=xzy3267, v3=xzy3267, v4=xzy3267)
  CompilerIf Defined(v2, #PB_Variable)
  CompilerIf Defined(v3, #PB_Variable)
  CompilerIf Defined(v4, #PB_Variable)
  Debug DQtMe(v1) + " = " +Str(v1) + ",  " + DQtMe(v2) + " = " + Str(v2) + ",  " + DQtMe(v3) + " = " + Str(v3) + ",  " + DQtMe(v4) + " = " + Str(v4)
  CompilerElse
  Debug DQtMe(v1) + " = " +Str(v1) + ",  " + DQtMe(v2) + " = " + Str(v2) + ",  " + DQtMe(v3) + " = " + Str(v3)
  CompilerEndIf
  CompilerElse
  Debug DQtMe(v1) + " = " +Str(v1) + ",  " + DQtMe(v2) + " = " + Str(v2)
  CompilerEndIf
  CompilerElse
  Debug DQtMe(v1) + " = " +Str(v1)
  CompilerEndIf
EndMacro

Macro DebugVarUB(v,lvl=0)
  Debug DQtMe(v) + " = " + StrU(v, 0), lvl
EndMacro

Macro DebugVarUW(v, lvl=0)
  Debug DQtMe(v) + " = " + StrU(v, 1), lvl
EndMacro

Macro DebugVarUL(v, lvl=0)
  Debug DQtMe(v) + " = " + StrU(v, 2), lvl
EndMacro

Macro DebugVarUQ(v, lvl=0)
  Debug DQtMe(v) + " = " + StrU(v, 4), lvl
EndMacro

Macro DebugVarB(v, lvl=0)
  Debug DQtMe(v) + " = " + Str(v), lvl
EndMacro

Macro DebugVarW(v, lvl=0)
  Debug DQtMe(v) + " = " + Str(v), lvl
EndMacro

Macro DebugVarL(v, lvl=0)
  Debug DQtMe(v) + " = " + Str(v), lvl
EndMacro

Macro DebugVarQ(v, lvl=0)
  Debug DQtMe(v) + " = " + StrQ(v), lvl
EndMacro

Macro DebugVarF(v, lvl=0, d=-1)
  CompilerIf d = -1
  Debug DQtMe(v) + " = " + StrF(v), lvl
  CompilerElse
  Debug DQtMe(v) + " = " + StrF(v, d), lvl
  CompilerEndIf
EndMacro

Macro DebugVarD(v, lvl=0, d=-1)
  CompilerIf d = -1
  Debug DQtMe(v) + " = " + StrD(v), lvl
  CompilerElse
  Debug DQtMe(v) + " = " + StrD(v, d), lvl
  CompilerEndIf
EndMacro

Macro DebugVarS(v, lvl=0)
  Debug DQtMe(v) + " = " + v, lvl
EndMacro

Macro DebugVarSDQT(v, lvl=0)
  Debug DQtMe(v) + " = " + #DQUOTE$ + v + #DQUOTE$, lvl
EndMacro

Macro DebugVarSSQT(v, lvl=0)
  Debug DQtMe(v) + " = " + "'" + v + "'", lvl
EndMacro

Structure CHAR
  c.c
EndStructure

Structure CHARARRAY
  c.c[0]
EndStructure

Structure BYTEARRAY
  b.b[0]
EndStructure

Structure WORDARRAY
  w.w[0]
EndStructure

Structure LONGARRAY
  l.l[0]
EndStructure

Structure QUADARRAY
  q.q[0]
EndStructure

Structure FLOATARRAY
  f.f[0]
EndStructure

Structure DOUBLEARRAY
  d.d[0]
EndStructure

Structure STRINGARRAY
  s.s[0]
EndStructure

Structure ADDRARRAY
  a.l[0]  ; We might get quad memory addresses with PB5 ?! ;)
EndStructure

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    ; Macro PathSlash$
      ; "/"
    ; EndMacro
    #PathSlash$ = "/"
    #PathSlash = '/'
    #FilenamesCaseSensitive = -1
  CompilerCase #PB_OS_Windows
    ; Macro PathSlash$
      ; "\"
    ; EndMacro
    #PathSlash$ = "\"
    #PathSlash = '\'
    #FilenamesCaseSensitive = 0
    CompilerCase #PB_OS_MacOS
    ; I don't know Mac
CompilerEndSelect
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Some usefull? Macros

Post by fsw »

technicorn wrote:Here are some Macros I made since PB4 is out

Code: Select all

Macro Ubound(array)
  (PeekL(@array - 8) - 1)
EndMacro
Make whatever you like with them
Thanks, this works fine.

Can somebody from the PB dev team tell me if this is the right approach and will it always work?
And if this command will be native in the future.

Also (didn't read anything that talks about it) if macros can only be used in pb source code and not in RES files?

BTW Here another macro (more consistent with the Linked List command):

Code: Select all

Macro NewArray
  Dim
EndMacro
:lol:
Fred
Administrator
Administrator
Posts: 18252
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Macros can be put in resident files ;).
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Thanks Fred.
8)

PS: Still don't know if Ubound will be a PB command in the future, but it's a start :wink:
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Fred wrote:Macros can be put in resident files ;).
Good!! That was what i was thinking about... how to use them without need to include them each time. Greate!
ARGENTINA WORLD CHAMPION
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Post by helpy »

Die(expression,msg):

Code: Select all

Macro Die(expression,msg)
  If (expression)
    MessageRequester("Program aborted!", msg, #MB_ICONERROR)
    End
  EndIf
EndMacro

Enumeration ;Windows
  #win_Main
EndEnumeration

Die(Not OpenWindow(#win_Main,x,y,width,height,"Window Title"),"Window could not be opened!")
Die(Not CreateGadgetList(WindowID(#win_Main)), "Window controls could not be created!")
ColorRGB(r,g,b) useful for creating color constants, because if I use RGB(r,g,b) to assign it to a constant the compiler returns "A constant can't be composed by a variable or a function". This works:

Code: Select all

Macro ColorRGB(r,g,b)
  ( (r & $FF) + ((g & $FF) << 8) + ((b & $FF) << 16) )
EndMacro

#Color_White = ColorRGB(255,255,255)
#Color_Red   = ColorRGB(255,0,0)
#Color_Green = ColorRGB(0,255,0) 
cu, helpy
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Post by helpy »

Fred wrote:Macros can be put in resident files ;).
Hi Fred,

If there are Compiler statements (CompilerIf ...) inside Macros. Will they still work, if compiled to a resident file?

cu, helpy
Fred
Administrator
Administrator
Posts: 18252
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Yes, as a macro code isn't parsed until it the macro get called.
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Post by Guimauve »

Use Macro to access different structure

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Macro Access different structure
; File : Macro exemple 
; File Version : 1.0.0
; Programmation : Experimental code
; Programmed by : Guimauve
; Date : 02-04-2006
; Last Update : 02-04-2006
; Coded for PureBasic V4.00
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Structure Vector3D
   
   Coords.f[3] ;  i.f, j.f, k.f
   
EndStructure

Structure Point3D
   
   Coords.f[3] ;  x.f, y.f, z.f
   
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The Mutator Macro >>>>>

Macro SetCoords3D(ObjetA, Index, Coord_00)
   
   ObjetA\Coords[Index] = Coord_00
   
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The Observator Macro >>>>>

Macro GetCoords3D(ObjetA, Index)
   
   ObjetA\Coords[Index]
   
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The Update Operator Macro >>>>>

Macro UpdateCoords3D(ObjetA, Coord_00, Coord_01, Coord_02)
   
   SetCoords3D(ObjetA, 0, Coord_00)
   SetCoords3D(ObjetA, 1, Coord_01)
   SetCoords3D(ObjetA, 2, Coord_02)
   
EndMacro 

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The Debug Operator Macro >>>>>

Macro DebugCoords3D(ObjetA)
   
   CompilerIf #PB_Compiler_Debugger ;>
      Debug GetCoords3D(ObjetA, 0)
      Debug GetCoords3D(ObjetA, 1)
      Debug GetCoords3D(ObjetA, 2)
   CompilerEndIf ;<
   
EndMacro 

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Maths Plus Operator Macro >>>>>

Macro PlusCoords3D(ObjetA, ObjetB, Result)
   
   For Index = 0 To 2
      SetCoords3D(Result, Index, GetCoords3D(ObjetA, Index) + GetCoords3D(ObjetB, Index))
   Next 
   
EndMacro 

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

UpdateCoords3D(Alpha.Point3D, 1.25, 2.5, 3.125)

UpdateCoords3D(Beta.Vector3D, 6.5, 10.5, 8.125)

Debug "Alpha : Point 3D"
DebugCoords3D(Alpha)

Debug "Beta : Vecteur 3D"
DebugCoords3D(Beta)

Debug "Alpha + Beta = Resultat"
PlusCoords3D(Alpha, Beta, Result.Vector3D)
DebugCoords3D(Result)

Dim Path3D.Point3D(10)

For Index = 0 To 9
   UpdateCoords3D(Path3D(Index), 6.5 + Pow(Index,2), 10.5 + Index, 8.125 * Index)
Next 

Debug "The 3D path point list"

For Index = 0 To 10
   Debug "Point no. " + Str(Index)
   DebugCoords3D(Path3D(Index))
Next 

NewList TangentList.Vector3D()

For Index = 0 To 9
   AddElement(TangentList())
   UpdateCoords3D(TangentList(), 6.75 + Pow(Index,3), 12.25 + Index,1.5 * Index)
Next 

Debug "Tangente list"

ForEach TangentList()
   
   Debug "Index no. " + Str(counter)
   DebugCoords3D(TangentList())
   counter + 1
   
Next 

; <<<<<<<<<<<<<<<<<<<<<
; <<<< END OF FILE <<<<
; <<<<<<<<<<<<<<<<<<<<<
Regards
Guimauve
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Post by Guimauve »

Two more macros

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Looping and Scrolling
; File : Macro - Looping and Scrolling.pb
; File Version : 1.0.0
; Programmation : OK
; Programmed by : Guimauve
; Date : 02-04-2006
; Last Update : 02-04-2006
; Coded for PureBasic V4.00
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Macro Looping(Number, Minimum, Maximum, Increment)
   
   Number + Increment
   
   If Number > Maximum
      
      Number = Minimum
      
   ElseIf Number < Minimum
      
      Number = Maximum
      
   EndIf
   
EndMacro

Macro Scrolling(Number, Minimum, Maximum, Increment)
   
   Number + Increment
   
   If Number > Maximum
      
      Number = Maximum
      
   ElseIf Number < Minimum
      
      Number = Minimum
      
   EndIf
   
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Exemple of use <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<

Debug "Looping forward"

For Counter = 0 To 8
   
   Loop.f = Looping(Loop, 0,15, 2.25)
   
   Debug Loop
   
Next 

Debug "Looping back"

For Counter = 0 To 8
   
   Loop2 = Looping(Loop2, 0,5, -1)
   
   Debug Loop2
   
Next 

Debug "Scrolling"

For Counter = 0 To 8
   
   Scroll = Scrolling(Scroll, 0,6, 1)
   
   Debug Scroll
   
Next 

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Regards
Guimauve
raygr
User
User
Posts: 32
Joined: Fri Mar 17, 2006 8:05 am

Post by raygr »

Fred wrote:Macros can be put in resident files ;).
How exactly do I do this? (I'm a PB newbie...)
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

raygr wrote:
Fred wrote:Macros can be put in resident files ;).
How exactly do I do this? (I'm a PB newbie...)
See help file under "Using the command line compiler"
If it's not enough the PB-team should add more info's into the help file :wink:


BTW
Would be nice if a resident could be compiled from the ide under:
Compiler Options/Executable Format/Resident.

The only thing to take care of is the "/IGNORERESIDENT" compiler parameter, which could be done with and additional CheckboxGadget in the "Compiler Options" window.
raygr
User
User
Posts: 32
Joined: Fri Mar 17, 2006 8:05 am

Post by raygr »

Thanks fsw, I'll give it a go.
Amundo
Enthusiast
Enthusiast
Posts: 200
Joined: Thu Feb 16, 2006 1:41 am
Location: New Zealand

Post by Amundo »

technicorn, thanks very much for your macros and example code, they are very instructive and helpful.

Guimauve, ditto.

Everyone else, thanks, I've learned about resident files!
Post Reply