1.4.5 Controlling Column Data Types

Origin support all the basic numeric data types.

In this example, you will see how to setup a worksheet with columns of signed and unsigned 1 byte, 2 byte, 4 byte integers, 4 byte and 8 byte floating points, as well as 16 bytes complex data type.

Strings can also put passed into Origin Columns, if a column is of the type Text or Text & Numeric.

VB Example to Set All Columns to Y and Float Data Type

 Private Sub CommandButton1_Click()
   Dim app As Origin.ApplicationSI
    Dim wks As Origin.Worksheet
    Dim col As Origin.Column
    Dim ii As Integer
    Set app = New Origin.ApplicationSI
    Set wks = app.FindWorksheet("")
    For ii = 0 To wks.Cols - 1
        Set col = wks.Columns(ii)
        col.DataFormat = DF_FLOAT
        col.Type = COLTYPE_Y
    Next
End Sub

Excel VBA

Option Explicit
 
Const NUMPTS = 100

Public Sub CreateOPJ()

    Dim org As Origin.Application
    Dim wksName As String
    Dim orgWks As Origin.Worksheet
    Dim rng As Origin.DataRange
    Dim ii As Long
    Dim strPathName As Variant
    Dim s1(1 To NUMPTS) As Double
    Dim s2(1 To NUMPTS) As Double
    Dim s3(1 To NUMPTS) As Double
    Dim s4(1 To NUMPTS) As Double
    Dim s5(1 To NUMPTS) As Double
    Dim s6(1 To NUMPTS) As Double
    Dim s7(1 To NUMPTS) As Double
    Dim s8(1 To NUMPTS, 1 To 2) As Double
 
    '------------------------------------------------------------
    On Error GoTo error
 
    ' Create the origin COM object:
    Set org = New Origin.Application
    org.Visible = MAINWND_SHOW
    
    ' Initialize new project:
    org.NewProject
 
    ' The sheets:
    wksName = org.CreatePage(2)
    Set orgWks = org.FindWorksheet(wksName)
 
    ' Make sure WorkSheet has eight columns:
    Do While orgWks.Columns.Count < 8
        orgWks.Columns.Add
    Loop
 
    ' Set Long Names, Units, and Comment to the four columns:
    orgWks.Columns(0).DataFormat = DF_BYTE              'set DataFormat as unsigned 8-bit integer, DF_BYTE = 38
    orgWks.Columns(0).Name = "Ch1"
    orgWks.Columns(0).LongName = "Byte"
 
    orgWks.Columns(1).DataFormat = DF_SHORT             'set DataFormat as signed 16-bit integer, DF_SHORT = 33
    orgWks.Columns(1).Name = "Ch2"
    orgWks.Columns(1).LongName = "Short"
 
    orgWks.Columns(2).DataFormat = DF_USHORT            'set DataFormat as unsigned 16-bit integer, DF_USHORT = 39
    orgWks.Columns(2).Name = "Ch3"
    orgWks.Columns(2).LongName = "uShort"
 
    orgWks.Columns(3).DataFormat = DF_LONG              'set DataFormat as signed 32-bit integer, DF_LONG = 34
    orgWks.Columns(3).Name = "Ch4"
    orgWks.Columns(3).LongName = "Long"
 
    orgWks.Columns(4).DataFormat = DF_ULONG             'set DataFormat as unsigned 32-bit integer, DF_ULONG = 40
    orgWks.Columns(4).Name = "Ch5"
    orgWks.Columns(4).LongName = "uLong"
 
    orgWks.Columns(5).DataFormat = DF_FLOAT             'set DataFormat as 32-bit floating point, DF_FLOAT = 32
    orgWks.Columns(5).Name = "Ch6"
    orgWks.Columns(5).LongName = "Float"
 
    orgWks.Columns(6).DataFormat = DF_DOUBLE            'set DataFormat as 64-bit floating point, DF_DOUBLE = 0
    orgWks.Columns(6).Name = "Ch7"
    orgWks.Columns(6).LongName = "Double"
 
    orgWks.Columns(7).DataFormat = DF_COMPLEX           'set DataFormat as Complex, DF_COMPLEX = 41
    orgWks.Columns(7).Name = "Ch8"
    orgWks.Columns(7).LongName = "Complex"
 
    ' Set data to the arrays
    For ii = 1 To NUMPTS
        s1(ii) = Rnd(9)
        s2(ii) = ii
        s3(ii) = ii * 2
        s4(ii) = ii * 4
        s5(ii) = ii * 8
        s6(ii) = ii * 0.1
        s7(ii) = ii / 13.4
        s8(ii, 1) = ii / 3.14
        s8(ii, 2) = ii * 0.2
    Next
 
  'Create a single column data range in the workSheet
    Set rng = orgWks.NewDataRange(0, 0) ' col (1)
    ii = rng.SetData(s1)
    Set rng = orgWks.NewDataRange(0, 1) ' col (2)
    ii = rng.SetData(s2)
    Set rng = orgWks.NewDataRange(0, 2) ' col (3)
    ii = rng.SetData(s3)
    Set rng = orgWks.NewDataRange(0, 3) ' col (4)
    ii = rng.SetData(s4)
    Set rng = orgWks.NewDataRange(0, 4) ' col (5)
    ii = rng.SetData(s5)
    Set rng = orgWks.NewDataRange(0, 5) ' col (6)
    ii = rng.SetData(s6)
    Set rng = orgWks.NewDataRange(0, 6) ' col (7)
    ii = rng.SetData(s7)
    orgWks.Columns(7).SetData (s8)
 
    '------------------------------------------------------------
 
    ' Get the pathname for saving the OPJ:
    strPathName = Application.GetSaveAsFilename("My Project Name", "Project files (*.OPJ),*.OPJ", 0)
    If strPathName = False Then
        Exit Sub
    End If
 
    ' Save:
    If org.Save(strPathName) = False Then
        MsgBox "Failed to save the project into " & strPathName
    Else
        MsgBox "Saved into " & strPathName
    End If
 
    Exit Sub
 
error:
    MsgBox ("ERROR")
    Resume Next
 
End Sub

C# Codes to Show Problems

long and ulong does not work in C#

        public void TestDataFormat()
        {
            long NUMPTS = 50;
            Origin.Worksheet orgWks;
            Origin.COLDATAFORMAT DF = OrgLab8.COLDATAFORMAT.DF_BYTE;
            int nn = 0;
            string DF1 = "";


            long[] s7 = new long[NUMPTS];
            ulong[] s8 = new ulong[NUMPTS];

            Origin.Application org = new OrgLab8.Application();
            org.NewProject();
            Origin.WorksheetPage orgWkBk = org.WorksheetPages.Add(System.Type.Missing, System.Type.Missing);
            orgWks = (Origin.Worksheet)orgWkBk.Layers[0];

            do
            {
                orgWks.Columns.Add(System.Type.Missing);
            } while (orgWks.Columns.Count < 2);
            for (nn = 0; nn < 10; nn++)
            {
                switch (nn)
                {
                    case 0:
                        DF = OrgLab8.COLDATAFORMAT.DF_BYTE;
                        DF1 = "BYTE";
                        break;
                    case 1:
                        DF = OrgLab8.COLDATAFORMAT.DF_SHORT;
                        DF1 = "SHORT";
                        break;
                    case 2:
                        DF = OrgLab8.COLDATAFORMAT.DF_USHORT;
                        DF1 = "USHORT";
                        break;
                    case 3:
                        DF = OrgLab8.COLDATAFORMAT.DF_LONG;
                        DF1 = "LONG";
                        break;
                    case 4:
                        DF = OrgLab8.COLDATAFORMAT.DF_ULONG;
                        DF1 = "ULONG";
                        break;
                    case 5:
                        DF = OrgLab8.COLDATAFORMAT.DF_FLOAT;
                        DF1 = "FLOAT";
                        break;
                    case 6:
                        DF = OrgLab8.COLDATAFORMAT.DF_DOUBLE;
                        DF1 = "DOUBLE";
                        break;
                    case 7:
                        DF = OrgLab8.COLDATAFORMAT.DF_COMPLEX;
                        DF1 = "COMPLEX";
                        break;
                    case 8:
                        DF = OrgLab8.COLDATAFORMAT.DF_TEXT;
                        DF1 = "TEXT";
                        break;
                    case 9:
                        DF = OrgLab8.COLDATAFORMAT.DF_TEXT_NUMERIC;
                        DF1 = "TEXT_NUMERIC";
                        break;
                }
                for (int ii = 0; ii < 10; ii++)
                {
                    orgWks.Columns[ii].DataFormat = DF;
                }
                for (int ii = 0; ii < NUMPTS; ii++)
                {
                    s7[ii] = ii * 100;   //long
                    s8[ii] = (ulong)(ii * 200);   //ulong
                }

                    try
                    { orgWks.Columns[6].SetData(s7, System.Type.Missing); }
                    catch (Exception ex)
                    { 
                      MessageBox.Show("long-->" + DF1); 
                      MessageBox.Show(ex.ToString());
                    }
                    try
                    { orgWks.Columns[7].SetData(s8, System.Type.Missing); }
                    catch(Exception ex)
                    { 
                      MessageBox.Show("ulong-->" + DF1); 
                      MessageBox.Show(ex.ToString());
                    }
              
            }
        }

long does not work in VB.NET

    Public Sub CreateOPJ()
        Dim strPathName As Object
        Dim org As OrgLab8.Application
        Dim orgWkBk As OrgLab8.WorksheetPage
        Dim orgWks As OrgLab8.Worksheet
        Dim nn As Integer = 0
        Dim ii As Integer = 0
        Dim DF As Integer = 0
        Dim DF1 As String = ""

        Dim s(NUMPTS) As Long

        '------------------------------------------------------------
        org = New OrgLab8.Application
        org.NewProject()
        orgWkBk = org.WorksheetPages.Add
        orgWks = orgWkBk.Layers(0)

        Do While orgWks.Columns.Count < 9
            orgWks.Columns.Add()
        Loop

        For nn = 0 To 9
            Select Case nn
                Case 0
                    DF = OrgLab8.COLDATAFORMAT.DF_BYTE
                    DF1 = "BYTE"
                Case 1
                    DF = OrgLab8.COLDATAFORMAT.DF_SHORT
                    DF1 = "SHORT"
                Case 2
                    DF = OrgLab8.COLDATAFORMAT.DF_USHORT
                    DF1 = "USHORT"
                Case 3
                    DF = OrgLab8.COLDATAFORMAT.DF_LONG
                    DF1 = "LONG"
                Case 4
                    DF = OrgLab8.COLDATAFORMAT.DF_ULONG
                    DF1 = "ULONG"
                Case 5
                    DF = OrgLab8.COLDATAFORMAT.DF_FLOAT
                    DF1 = "FLOAT"
                Case 6
                    DF = OrgLab8.COLDATAFORMAT.DF_DOUBLE
                    DF1 = "DOUBLE"
                Case 7
                    DF = OrgLab8.COLDATAFORMAT.DF_COMPLEX
                    DF1 = "COMPLEX"
                Case 8
                    DF = OrgLab8.COLDATAFORMAT.DF_TEXT
                    DF1 = "TEXT"
                Case 9
                    DF = OrgLab8.COLDATAFORMAT.DF_TEXT_NUMERIC
                    DF1 = "TEXT_NUMERIC"
            End Select

            '-----Set Columns-----
            ii = 0
            For ii = 0 To 8
                orgWks.Columns(ii).DataFormat = DF
            Next ii

            '-----------Set Array------------
            For ii = 1 To NUMPTS
                s(ii) = ii * 10  'Long
            Next

            '---------SetData---------------
            Try
                orgWks.Columns(3).SetData(s)
            Catch ex As Exception
                MsgBox("Long-->" & DF1)
                MsgBox(ex.ToString())
            End Try

        Next nn

    End Sub