wish: Val(string)

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
I don't think that returning 0 for a bad formatted string is a good idea.
Throwing an exception is much safer.

I guess that Microsoft disagrees, since VAL("") and VAL("a") both return 0 in Visual Basic. Meanwhile, division by zero causes an error in Visual Basic while it doesn't in B4A. In fact, instead of throwing an exception, division by zero in B4A returns a result of "2147483647". How is that reasonable and VAL("a")=0 is not when the latter result is actually correct?

If you do need such a function you can always implement it as a sub.

I was always told that calling a sub takes more processing time, especially when it involves several lines of code compared to an internal function.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Meanwhile, division by zero causes an error in Visual Basic while it doesn't in B4A. In fact, instead of throwing an exception, division by zero in B4A returns a result of "2147483647". How is that reasonable and VAL("a")=0 is not when the latter result is actually correct?
Actually it was better if Basic4android threw an error for division by zero as well. However this is not possible without adding a check for each division which will hurt the performance.

I was always told that calling a sub takes more processing time, especially when it involves several lines of code compared to an internal function.
There is no difference between calling an internal keyword and calling a Sub. Both are Java methods. The JVM can inline simple methods which again is relevant for both internal keywords and Subs.
 
Top