usnistgov / REFPROP-wrappers

Wrappers around NIST REFPROP for languages such as Python, MATLAB, etc.
193 stars 127 forks source link

Coding GETENUMdll in VBA for Excel #504

Closed ThomasB2021 closed 1 year ago

ThomasB2021 commented 1 year ago

Description

Hello everybody, I tried to code the GETENUMdll subroutine in the VBA development environment of an Excel spreadsheet. Thank you for your help.

Steps to Reproduce

Expected behavior: As I set the hEnum variable to a string with the indication of the units system (such as "SI"), and run it through the GETENUMdll subroutine, I expect the output variable iEnum to give back the correspondent number. The code I'm using is posted below, in the additional information section.

Actual behavior: When the subroutine is called, Excel crashes

Versions

REFPROP Version: [REFPROP10]
Operating System and Version: [Windows10]
Access Method: [VBA Excel in MS Office 2019]

Additional Information

==========================VBA CODE=================== Public Declare Sub GETENUMdll Lib "REFPROP.DLL" (iFlag As Long, hEnum As String, iEnum As Long, ierr As Long, herr As String, hEnum_length As Long, herr_length As Long)

Public herr As String * 255 Public hEnum As String, ierr As Long, iEnum As Long

Function get_units()

hEnum = "SI" iEnum = 0 Call GETENUMdll(1, hEnum, iEnum, ierr, herr, 255, 255) MsgBox (iEnum)

End Function

ianhbell commented 1 year ago

You also need to expand the size of the buffer for hEnum to 255, you have currently passed in a three character string (two characters plus the NULL character)