Ask Your Question
0

Passing Labels Cells in Calc Basic

asked 2015-04-12 12:50:16 +0100

thingsmith gravatar image

I want to pass labelled cells to a custom function. However nothing I can find seems to solve the problem.

The simplest example of my problem is

  Cell b2 is label M with a value of 1.11
 -----------------------------------------------
 My Custom Function is 
       Function Echoval(A as Single) 
                 Echoval = A
      End Function 
 ---------------------------------

=Echoval(b2) returns 1.11

=Echoval('M') crashes.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2015-04-12 13:55:55 +0100

Lupp gravatar image

updated 2015-04-12 13:57:11 +0100

I suppose you are talking about "Automatic Addressing" and thus about an automatically named range when writing "Labels Cells".

You will know that "our" BASIC always passes parameters by value. In this case, however, it won't pass a scalar value but a 2-dimensional array, indexes starting with 1 and row index first. The array may well consist of only one element. You have to access an element, however, by indexing.

If your named range actually has only one element you may use this code:

Function GetTopLeftElement(pCellContent)
GetTopLeftElement = pCellContent(1,1)
End Function
edit flag offensive delete link more

Comments

@karolus is right, of course. The example is useless. It may be enhanced, however.

Lupp gravatar imageLupp ( 2015-04-12 13:59:03 +0100 )edit
0

answered 2015-04-12 13:23:30 +0100

karolus gravatar image

updated 2015-04-12 13:35:29 +0100

Did your term labelled Cells refers from Option →Tools→Options→Calc→Calculate→[x]Automatically find Column and Rowlabels ??

yes ? - so how should your poor basic-UDF determine the relative Position of the "Calling-Cell" , much less find the right Cell relativ to some "Label" in first Row|Column?

For that Purpose you have to write an AddInn-Extension Doc or tuturial or example or another example

IHMO: this silly Label-option is somehow Errorprone, I wouldn't use it in any case.

================================================

Maybe your ECHOVAL is only for Example, but it is a bad Example, because you have to write in Calc only ='M' for the same return.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-04-12 12:50:16 +0100

Seen: 193 times

Last updated: Apr 12 '15