Page 1 of 1

Functions with Optional Argument

Posted: Sun Jun 27, 2004 4:24 pm
by einander
Code updated for 5.20+. PureBasic now have optional procedure arguments built-in.

;In response To viewtopic.php?t=8142

Code: Select all

;You can define a Structure with different types, and pass the Structure Adress to your procedure.
; Inside the procedure, you can use the needed fields as arguments

Structure Arguments ; Here you can define more types if needed
    Byte1.b             ; each field is a possible type
    Byte2.b
    Long1.l 
    Long2.l 
    String1.s 
    String2.s 
EndStructure 

Procedure Test(*P.Arguments)   ; here you can assign values to some fields
    *P\Byte1 = 11                             
    *P\Byte2 = 22 
    *P\Long1 = 333333 
    *P\Long2 = 444444 
    *P\String1="This is String 1"
    *P\String2="This is String 2"
EndProcedure 
;________________

Test(@P.Arguments ) 
Debug P\Byte1     ; and get the returned values
Debug P\Byte2
Debug P\Long1 
Debug P\Long2
Debug P\String1
Debug P\String2 

Best regards
Einander