|
Post by alexfish on Jan 4, 2015 17:36:43 GMT 1
Hi Peter
Got a problem with va_args :: re NULL
this does not work , but a straight c will
any Ideas
BR Alex
SUB MY_VARS(int ID,...) PRINT "Vars" PROTO va_list , va_start, va_end
DECLARE var_args TYPE va_list DECLARE *first_property TYPE char DECLARE *second_property TYPE char DECLARE myval TYPE int
va_start (var_args, ID)
WHILE (first_property != NULL) DO
first_property = va_arg (var_args, char*)
IF EQUAL("val",first_property) THEN myval = va_arg (var_args, int) PRINT STR$(myval) END IF
IF EQUAL("text",first_property) THEN second_property = va_arg (var_args, char*) PRINT second_property END IF
WEND
va_end (var_args)
END SUB
REM main ------------------------- REM test bits
MyWidget=12
MY_VARS(MyWidget,"val",NULL,"text","That","val",1,"text","more text",NULL) PRINT "----------------------------------" MY_VARS(MyWidget,"val",7,"text","That","val",1,"text","more text","text","And So On !",NULL)
PRINT "----------------------------------"
|
|
|
Post by Pjot on Jan 4, 2015 18:51:39 GMT 1
Hi Alex,
This does not work because your WHILE loop is wrong.
Instead, you better use REPEAT/UNTIL. See the modified code below.
BR Peter
SUB MY_VARS(int ID, ...)
PRINT "Vars"
PROTO va_list , va_start, va_end
DECLARE var_args TYPE va_list DECLARE first_property TYPE char* DECLARE second_property TYPE char* DECLARE myval TYPE int
va_start (var_args, ID)
REPEAT
first_property = va_arg (var_args, char*)
IF first_property = "val" THEN myval = va_arg (var_args, int) PRINT STR$(myval) END IF
IF first_property = "text" THEN second_property = va_arg (var_args, char*) PRINT second_property END IF
UNTIL first_property = NULL
va_end (var_args) END SUB
REM main ------------------------- REM test bits
MyWidget=12
MY_VARS(MyWidget,"val",NULL,"text","That","val",1,"text","more text",NULL) PRINT "----------------------------------"
MY_VARS(MyWidget,"val",7,"text","That","val",1,"text","more text","text","And So On !",NULL) PRINT "----------------------------------"
|
|
|
Post by vovchik on Jan 4, 2015 19:04:32 GMT 1
Dear Alex and Peter, Very nice and useful...I was just playing with this and I am glad Peter had the solution. With kind regards, vovchik
|
|
|
Post by alexfish on Jan 4, 2015 19:07:30 GMT 1
Thanks Peter looking good Vars 0 That 1 more text ---------------------------------- Vars 7 That 1 more text And So On ! ----------------------------------
BR Alex
|
|
|
Post by alexfish on Jan 5, 2015 21:33:37 GMT 1
Oops Wrong thead
|
|