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.
Value, data_type = CGridView:GetVal( nCol, nRow )
Where nCol, and nRow are the coordinates of the cell to get.
On success, the Value and its data_type number are returned. See Remarks, below.
On failure, nil, nil is returned.
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 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:
|
-- attach a grid on the Mira desktop |
|
-- create a new CLsqFit object |
|
-- 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:
|
-- attach a grid on the Mira desktop |
|
-- create a new CLsqFit object |
|
-- get the type but ignore it here |
|
-- 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():
|
-- attach a grid on the Mira desktop |
|
-- create a new CLsqFit object |
|
-- GetNum returns only one value which is passed as AddPt(x,y) |
The following script returns the cell contents in (column 5, row 10):
|
-- attach a grid on the Mira desktop |
|
-- return the value and type for cell (5,10) |
|
-- if this is a string value... |
|
-- print a string |
|
-- else if this is a numeric value... |
|
-- print a number |
|
|
Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics,
Inc. All Rights Reserved.