CGridView:GetVal


The GetVal method returns the contents and data type of a grid cell. Use this method if the type of data in the cell is unknown.

Syntax

Value, data_type = CGridView:GetVal( nCol, nRow )

bullet.gif    Where nCol, and nRow are the coordinates of the cell to get.

bullet.gif    On success, the Value and its data_type number are returned. See Remarks, below.

bullet.gif    On failure, nil, nil is returned.

Remarks

The returned cell data_type is a number describing the Value returned by this method. Use this number to interpret the Value and choose the appropriate conversion.

 

Returned Data Type

Returned Value Type

1

String

2

Number

3

Boolean true or false

4

Time, as a string

5

Currency, as a string

10

Special time (hh:mm:ss.sss)

11

Special date (yyyy/mm/dd)

12

Special degrees (dd:mm:ss.sss or +dd°mm'ss.sss")

other (1)

String

Be careful using 2 return values from GetVal() in a function call

Be careful when directly passing the return of GetVal as a parameter in another function call if that function can take a variable number of parameters. Since this method returns 2 values, you need to take care that the function does not unintentionally use the second return parameter. There are not many situations where this may arise, but one of them is described below.

For example, CLsqFit:AddPt() takes either 2 or 3 values, as in AddPt(x,y) and AddPt(x,y,z). Since this method returns 2 values, placing GetVal() directly in the call to AddPt() will result in a y and z parameters being passed when you want only the y parameter. Suppose G is a CGridView object and L is a CLsqFit object, and you want to add the value from cell (5,10) at x=3.5 in a least squares fit. The following code will confuse AddPt into taking a z value when none is intended:

G = attach_gridview()

-- attach a grid on the Mira desktop

L = new_lsqfit()

-- create a new CLsqFit object

L:AddPt(3.5, G:GetVal(5,10))

-- WRONG! AddPt sees this as AddPt(3.5, y, z)

If you want to use only the first of the 2 return values, then you could assign them and pass only the first assignment, like this:

G = attach_gridview()

-- attach a grid on the Mira desktop

L = new_lsqfit()

-- create a new CLsqFit object

y, type = G:GetVal(5,10)

-- get the type but ignore it here

L:AddPt(3.5, y)

-- AddPt uses only the y value as AddPt(x,y)

Another way to workaround is to use CGridView:GetNum() and CGridView:GetStr() as they return only the cell's value as a number or string, respectively. Here is an example using GetNum():

G = attach_gridview()

-- attach a grid on the Mira desktop

L = new_lsqfit()

-- create a new CLsqFit object

L:AddPt(3.5, G:GetNum(5,10))

-- GetNum returns only one value which is passed as AddPt(x,y)

Example

The following script returns the cell contents in (column 5, row 10):

G = attach_gridview()

-- attach a grid on the Mira desktop

value, type = G:GetVal(5,10)

-- return the value and type for cell (5,10)

if type == 1 then

-- if this is a string value...

  Printf("value = %s\n", value)

-- print a string

elseif type == 2 then

-- else if this is a numeric value...

  Printf("value = %d\n", value)

-- print a number

end

 

Related Topics

CGridView class

SetVal

GetStr

GetNum

GetType


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.