give function multiple outputs by using array.

give function multiple outputs by using array.

stefanveurink68AXD
Advocate Advocate
1,254 Views
2 Replies
Message 1 of 3

give function multiple outputs by using array.

stefanveurink68AXD
Advocate
Advocate

So, i've got some pretty big code which has to be done all the time, so i wanted to make a function of it. 

Now, I've learned how to create functions, but the problem is, the function definition looks like this: 

Function middelpunttussendwarslijnen(nlba As AcadLWPolyline, dlba1, dlba2 As AcadLine, sn1, sn2 As Integer) As Variant

I want 3 outputs, for your information: the x & y value of a certain coordinate, and the nr. of the coordinate. 

 

So, I was hoping, by using the positions (0, 1, 2) in the variant, 0 & 1 could be x & y, and 2 the nr.. But, when definining the 0,1,2, by 

middelpunttussendwarslijnen(0) = nieuweindpunt(0)
middelpunttussendwarslijnen(1) = nieuweindpunt(1)
middelpunttussendwarslijnen(2) = sn1 + x - 2 

it gives me a type mismatch. 

 

It would be an really awful solution to just do all the code twice in 2 different functions, 1 for the coordinate and 1 for the nr., so i was hoping there exists a more elegant solution. 

 

anybody got any ideas? thanks. 

 

 

0 Likes
Accepted solutions (1)
1,255 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

The function should look like:

 

Function middelpunttussendwarslijnen(nlba As AcadLWPolyline, dlba1, dlba2 As AcadLine, sn1, sn2 As Integer) As Variant
Dim returnValues(0 to 2) As Double ''You need to declare the array element's type
... ...
returnValues(0)=nieueindpunt(0)
returnValues(1)=nieueindpunt(1)
returnValues(2)=sn1 + x -2 '' the assigned Integer value will be converted to Double implicitly here
middelpunttussendwarslijnen = returnValues
End Function

HTH

 

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3

stefanveurink68AXD
Advocate
Advocate

genius! thanks a lot!

0 Likes