Questions about programming - Forum

Forum Navigation
You need to log in to create posts and topics.

Questions about programming

1 When we use return in a subroutine we must give a return value. How can we get this value after the call ?

2 when I use neoPhpExecSql for example for a count , I receive the value inside the subroutine, but my subroutine is not executed immediately so if I need a test depending of the result value for the following instruction it could be wrong because the value is not yet intialized !

Is there any other solution than putting waits in front of each instruction ?

---------example----------

neoPhpExecSql "dbMT" "selAvec" "[nID]::[aJ(0)]::[aJ(1)]" "Result"

IfEx [n2] == 2 and [OK] == true
neoPhpExecSql "dbMT" "selAvec" "[nID]::[aJ(0)]::[aJ(2)]" "Result"

endif

subroutine Result

CreateEmptyObject [MyResult]
SetVar [MyResult] [resp]
If [MyResult(0).nbAvec] > 0
SetVar [OK] false
Else
SetVar [OK] true
Endif
Return [OK]

 

Hi @phil78

When we use return in a subroutine we must give a return value. How can we get this value after the call?

No. You can use return command to exit the subroutine. You can assign any value to a global variable or to a VarRef variable parameter sent to the subroutine.

when I use neoPhpExecSql for example for a count , I receive the value inside the subroutine, but my subroutine is not executed immediately so if I need a test depending of the result value for the following instruction it could be wrong because the value is not yet intialized!

Getting information from the database is an asynchronous task. You need to do the test inside the subroutine, once you have processed the information from the database. You can also call a speficfic subroutine from the parseData subroutine ("Result" in your example).

I hope it helps.

Regards.

javadrajabihakami has reacted to this post.
javadrajabihakami

Thank you @luishp

It's going to be very complicated because I'm doing 5 tests in cascade!
Is there a possibility to force in synchronous ?
I noticed that even the wait instruction did not interrupt the execution.

Best regards.

@phil78 I think you can solve partially the problem using more complex SQL queries.
Although a synchronous call is possible today, it's deprecated because of its detrimental effects to the end user's experience and will probably stop working in the near future.
Please take a look here to understand why it's not a good idea:
What can go wrong if you make synchronous Ajax calls using jQuery: Understanding event loop in Javascript

Regards.