Welcome
Collapse Getting StartedGetting Started
Overview
Expand Types of SolidWorks API ApplicationsTypes of SolidWorks API Applications
Expand SolidWorks API Object Model and Class HierarchySolidWorks API Object Model and Class Hierarchy
Collapse Programming with the SolidWorks APIProgramming with the SolidWorks API
Expand Add-insAdd-ins
API Dependent on SolidWorks Being Visible
Arrays
Attributes Imported from ACIS SAT Files
Bitmasks
Block Definitions and Block Instances
Bodies in Body Folders
BOOL and VARIANT_BOOL
Bounding Box and Note Text
COM vs. Dispatch
CommandManager and CommandGroups
Components, Configurations, and Suppression States
Compound Note
ComVisibleAttribute in VSTA macros
Controls, Visual Basic 6.0, and Windows XP
Collapse Double Arrays and Integer PairsDouble Arrays and Integer Pairs
Drawing Views and Model Entities
Early and Late Binding
Expand EventsEvents
Features of Components
Helper Functions
Hole Wizard Features and Objects
IDispatch Object Arrays as Input in .NET
Implementation Guidelines
Import and Export File Options
In-process Methods
Instantiate ActiveX Controls as Tabs
Interface Pointers
Keystrokes and Accelerator Keys
Library Features and Objects
Lightweight Components
Line Attributes for View::GetPolyLinesAndCurves
Line Weights
Long vs. Integer
Expand Macro FeaturesMacro Features
Manipulators
Mass Properties
Expand Multibody PartsMultibody Parts
Option Explicit Statement
Partition Rollback and API Handles
Persistent Reference IDs
Presentation Transforms
Expand PropertyManager PagesPropertyManager Pages
.NET Interop Assemblies
Quick Tips and Bubble ToolTips
Return Values
Expand SafeArraysSafeArrays
Selection Criteria
Selection Lists
Selections that Define Features
Setup Project to Distribute SolidWorks Add-in
Smart Pointers
SolidWorks Objects
Sorting Tables
SQLite
STL Container Classes and Smart Pointers
Suspend Automatic Rebuilds
System Options and Document Properties
Tessellation and Edges
Tracking IDs
Expand Type LibrariesType Libraries
Units
Unmanaged C++ and C++/CLI Code
VBA and SolidWorks x64
Examples and Projects
Expand SolidWorks API HelpSolidWorks API Help
Expand FeatureWorks API HelpFeatureWorks API Help
Expand SolidWorks Costing API HelpSolidWorks Costing API Help
Expand SolidWorks Document Manager API HelpSolidWorks Document Manager API Help
Expand SolidWorks Routing API HelpSolidWorks Routing API Help
Expand SolidWorks Simulation API HelpSolidWorks Simulation API Help
Expand SolidWorks Sustainability API HelpSolidWorks Sustainability API Help
Expand SolidWorks Toolbox API HelpSolidWorks Toolbox API Help
Expand SolidWorks Utilities API HelpSolidWorks Utilities API Help
Expand SolidWorks Workgroup PDM API HelpSolidWorks Workgroup PDM API Help
Expand eDrawings API HelpeDrawings API Help
Hide Table of Contents

Unpacking Double Arrays into Integer Pairs in Visual Basic .NET and Visual Basic

Some of the arguments passed from (and to) SolidWorks using the API contain arrays of doubles. In some functions, elements in these arrays contain two integers packed into a double array element. You can unpack the data from a double to two integers as follows:

Visual Basic .NET

Imports System.Runtime.InteropServices

Module Module1

    Sub Main()

        Dim iValueIn1 As Integer = 65535

        Dim iValueIn2 As Integer = 345

        Dim dValueOut As Double

        Dim iValueOut1 As Integer

        Dim iValueOut2 As Integer

        DoubleIntConv.Pack(iValueIn1, iValueIn2, dValueOut)

        DoubleIntConv.Unpack(dValueOut, iValueOut1, iValueOut2)

    End Sub

    <System.Runtime.InteropServices.StructLayout(LayoutKind.Explicit)> _

 Public Class DoubleIntConv

        ' An 8-byte double contains 2 4-byte ints.

        <System.Runtime.InteropServices.FieldOffset(0)> Private m_Int1 As Integer

        <System.Runtime.InteropServices.FieldOffset(4)> Private m_Int2 As Integer

        <System.Runtime.InteropServices.FieldOffset(0)> Private m_Double As Double

        Private Sub New(ByVal dValue As Double)

            'VB wants these initialized in the constructor.

            m_Int1 = 0

            m_Int2 = 0

            m_Double = dValue

        End Sub

        Private Sub New(ByVal iValue1 As Integer, ByVal iValue2 As Integer)

            'VB wants this one initialized in the constructor.

            m_Double = 0.0

            m_Int1 = iValue1

            m_Int2 = iValue2

        End Sub

        ' Use  out parameters, so client code can pass in uninitialize variable.

        Public Shared Sub Unpack(ByVal dIn As Double, ByRef iOut1 As Integer, ByRef iOut2 As Integer)

            Dim cv As DoubleIntConv

            cv = New DoubleIntConv(dIn)

            iOut1 = cv.m_Int1

            iOut2 = cv.m_Int2

        End Sub

        ' Use an out parameter, so client code can pass in uninitialize variable.

        Public Shared Sub Pack(ByVal iIn1 As Integer, ByVal iIn2 As Integer, ByRef dOut As Double)

            Dim cv As DoubleIntConv

            cv = New DoubleIntConv(iIn1, iIn2)

            dOut = cv.m_Double

        End Sub

    End Class

End Module

 

Back to top

Visual Basic for Applications (VBA)

' Define two types

Type DoubleRec

dValue As Double 

End Type

 

Type Int2Rec

iLower As Long ' assuming that a C int has 4 bytes 

iUpper As Long 

End Type

 

' Extract two integer values out of a single double value,

' by assigning a DoubleRec to the double value then

' copying the value over an Int2Rec and

' extracting the integer values.

Function ExtractFields(dValue As Double, iLower As Integer, iUpper As Integer)

 

Dim dr As DoubleRec, i2r As Int2Rec

 

' Set the double value

dr.dValue = dValue

 

' Copy the values

LSet i2r = dr

 

' Extract the values

iLower = i2r.iLower

iUpper = i2r.iUpper

 

End Function

 

 

Private Sub main()

Dim Params As Variant

Dim dElement As Double

Dim SplineDim As Integer

Dim SplineOrder As Integer

Dim SplineNCtrls As Integer

Dim SplinePeriodic As Integer

 

Set swApp = CreateObject("SldWorks.Application")

Set Part = swApp.ActiveDoc()

Set Sketch = Part.GetActiveSketch()

 

Params = Sketch.GetSplineParams

 

dElement = Params(0)

ExtractFields dElement, SplineDim, SplineOrder

dElement = Params(1)

ExtractFields dElement, SplineNCtrls, SplinePeriodic

 

End Sub

 

Back to top

 

 



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Unpacking Double Arrays into Integer Pairs in Visual Basic .NET and Visual Basic
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2013 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.