PDA

View Full Version : variant parameter



kryton9
23-09-2007, 21:56
When calling a function having parameters of type VARIANT passes BYVAL, passed numeric values can be typed. An example can clarify.

If you have a function like:



Function MyFunction(ByVal v1 As Variant) As Long

'...

End Function



you can call it passing any value plus a type in case of numeric. For example, the following are all accepted ways:



MyFunction("Whatever string")

MyFunction(123)

MyFunction(123 As QUAD)

MyFunction(1234.678)

MyFunction(1234.678 As Single)

MyFunction(12345.67898889 As Double)



In this way,

This is really a neat feature. Can we do something similar in powerBasic? As far as I can tell we can only use variant with com objects?

ErosOlmi
23-09-2007, 22:12
Well,

PB introduced VARIANT for a specific purpose that was to be used for COM interfaces. But you can use them in many different ways as long as you know what you are doing. Many languages uses variants but they hide some of the possible problems inside the language engine.

PB has ... AS clause in assign statement so you can type something like:
DIM V1 AS VARIANT
V1 = 12345.678 AS DOUBLE
But as does not let you indicate it during function parameter passing.

One of the advantages of having a language (thinBasic) is the possibility to add the features we like :D

Ciao
Eros

kryton9
24-09-2007, 18:52
One of the advantages of having a language (thinBasic) is the possibility to add the features we like

That is the truth Eros, so glad you are making such a command and feature rich language, the way that a BASIC should be!