Matrix.ConvertDataType
----------------------

Converts the data types.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Matrix](component_Matrix.md) | [12.5](newinversion125.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Matrix.ConvertDataType"; MatrixRef; DataType { ; FirstRow; LastRow; firstCol; lastCol } ) 

**MBS**( **"Matrix.ConvertDataType";** /\* Converts the data types. \*/  
**$MatrixRef**; /\* The matrix reference number.e.g. $matrix \*/   
**$DataType**; /\* The new data type.  
Can be Number, Container, Date, Time, TimeStamp or Text.e.g. "Text" \*/   
**$FirstRow**; /\* Optional; The index of first row.  
Default is 0.e.g. 0 \*/   
**$LastRow**; /\* Optional; The index of last row.  
Default is [Matrix.Height](MatrixHeight.md)-1.e.g. 5 \*/   
**$firstCol**; /\* Optional; The index of first column.  
Default is 0.e.g. 0 \*/   
**$lastCol**) /\* Optional; The index of last column.  
Default is [Matrix.Width](MatrixWidth.md)-1.e.g. 6 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| MatrixRef | The matrix reference number. | $matrix |  |
| DataType | The new data type.   Can be Number, Container, Date, Time, TimeStamp or Text. | "Text" |  |
| FirstRow | The index of first row.   Default is 0. | 0 | Optional |
| LastRow | The index of last row.   Default is [Matrix.Height](MatrixHeight.md)-1. | 5 | Optional |
| firstCol | The index of first column.   Default is 0. | 0 | Optional |
| lastCol | The index of last column.   Default is [Matrix.Width](MatrixWidth.md)-1. | 6 | Optional |

### Result

Returns OK or error.

### Description

Converts the data types.  
We loop over all rows in all columns for the range and convert the value to the given type.  
  
If you get data from [FM.SQL.Execute](FMSQLExecute.md), we have no FM.SQL.ConvertDataType as the rows are readonly. So please convert to matrix first and use [FM.SQL.ToMatrix](FMSQLToMatrix.md) first and then use Matrix.ConvertDataType.  
### Examples

Try this function:

 Set Variable \[ $matrix ; Value: MBS ( "[Matrix.New](MatrixNew.md)"; 3; 3 ) \]   
Set Variable \[ $r ; Value: MBS ( "[Matrix.SetColumn](MatrixSetColumn.md)"; $matrix ; 0;"15¶07¶92" ) \]   
\# get value   
Set Variable \[ $v1 ; Value: MBS ( "[Matrix.GetValue](MatrixGetValue.md)"; $matrix ; 0; 0 ) \]   
Set Variable \[ $d1 ; Value: MBS ( "[FM.DataType](FMDataType.md)"; $v1 ) \]   
Set Variable \[ $r ; Value: MBS ( "Matrix.ConvertDataType"; $matrix ; "number"; 0; 2; 0; 2) \]   
\# get value   
Set Variable \[ $v2 ; Value: MBS ( "[Matrix.GetValue](MatrixGetValue.md)"; $matrix ; 0; 0 ) \]   
Set Variable \[ $d2 ; Value: MBS ( "[FM.DataType](FMDataType.md)"; $v2 ) \]   
\# stop here to read in debugger   
\# $d1 shows text and $d2 shows number as type   
Set Variable \[ $v2 ; Value: MBS ( "[Matrix.Release](MatrixRelease.md)"; $matrix ) \]  
### See also

- [FM.DataType](FMDataType.md)
- [FM.SQL.Execute](FMSQLExecute.md)
- [FM.SQL.ToMatrix](FMSQLToMatrix.md)
- [Matrix.GetValue](MatrixGetValue.md)
- [Matrix.Height](MatrixHeight.md)
- [Matrix.New](MatrixNew.md)
- [Matrix.Release](MatrixRelease.md)
- [Matrix.SetColumn](MatrixSetColumn.md)
- [Matrix.Width](MatrixWidth.md)
- [SQL.Execute](SQLExecute.md)

### Release notes

- **Version 12.5**
    - Added [Matrix.ConvertDataType](https://www.mbsplugins.eu/MatrixConvertDataType.shtml) function.

### Blog Entries

- [New in MBS FileMaker Plugin 14.0](https://www.mbsplugins.de/archive/2024-01-23/New_in_MBS_FileMaker_Plugin_14/monkeybreadsoftware_blog_filemaker)
- [Top 10 from the MBS Plugin in 2022](https://www.mbsplugins.de/archive/2022-12-29/Top_10_from_the_MBS_Plugin_in_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 12.5 News](https://www.mbsplugins.de/archive/2022-11-17/MBS_FileMaker_Plugin_125_News/monkeybreadsoftware_blog_filemaker)
- [Neues MBS Plugin 12.5 für Claris FileMaker](https://www.mbsplugins.de/archive/2022-11-08/Neues_MBS_Plugin_125_für_Clar/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin 12.5 for Claris FileMaker - More than 6800 Functions In One Plugin](https://www.mbsplugins.de/archive/2022-11-08/MBS_Plugin_125_for_Claris_File/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 12.5pr3](https://www.mbsplugins.de/archive/2022-10-14/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [CSV in FileMaker with MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2022-10-11/CSV_in_FileMaker_with_MBS_File/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 9th October 2022 , last changed 20th December 2025

  
[Matrix.Clone](MatrixClone.md) - [Matrix.CopyColumn](MatrixCopyColumn.md)

[HTML Version](MatrixConvertDataType.shtml)