[CONNECT Update 12 VBA], [V8i SELECTseries 3 VBA] VBA Function "ShowOpen" works in V8i but not in CONNECT

Hello. My first post, so please be patient!
I have problems using vba Function "ShowOpen". My vba runs fine on MicroStation V8i (SELCTseries 3), but it will not open Dialogbox for selecting file in a newer MicroSration version.
Why don't this work in a newer MicroStation?

I have created a VBA UserForm "frmGPS_indlas"
In this form I have a push-button "Browse" (name) "cmdBrowseFile"
In the code to this form I include a call to Function "ShowOpen":

Private Sub cmdBrowseFile_Click()
        Dim msg      As String
    txtGPSfile = ShowOpen("Select GPS file", "CSV filer (*.csv)" + Chr$(0) + "*.csv", "All files (*.*)" + Chr$(0) + "*.*", "")
    If (Len(txtGPSfile) > 0) Then
          msg = "GPS fil '" & txtGPSfile & "'"
    Else
          msg = "No GPS file selected (Cancel)"
    End If
    ShowMessage msg, msg, msdMessageCenterPriorityInfo
    End Sub

And here we have "ShowOpen":

    Public Function ShowOpen( _
        strTitle As String, _
        Optional strFilterDescr As String = "All files (*.*)", _
        Optional strFilterSpec As String = "*.*", _
        Optional strInitDir As String = vbNullString) As String
        On Error GoTo Proc_Error

        Dim OFName          As OPENFILENAME
        Dim strFileFilter   As String, strFileSelected As String

        strFileFilter = strFilterDescr & Chr$(0) & strFilterSpec & Chr$(0)
        With OFName
            .lStructSize = Len(OFName)
            .hWndOwner = 0&
            .hInstance = 0& 'App.hInstance
            'Select a filter
            .lpstrFilter = strFileFilter ' "Text Files (*.txt)" & Chr$(0) &"*.txt" & Chr$(0) & "All Files (*.*)" & Chr$(0) & "*.*" & Chr$(0)
            .lpstrFile = Space$(254)
            .nMaxFile = 255
            .lpstrFileTitle = Space$(254)
            .nMaxFileTitle = 255
            If (vbNullString <> strInitDir) Then _
                .lpstrInitialDir = strInitDir
            .lpstrTitle = strTitle ' "Select File"
            .flags = OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST
        End With
        If GetOpenFileName(OFName) Then
            strFileSelected = Trim$(OFName.lpstrFile)
            If (InStr(strFileSelected, Chr(0)) > 0) Then
                strFileSelected = Left(strFileSelected, InStr(strFileSelected, Chr(0)) - 1)
            End If
            ShowOpen = Trim$(strFileSelected)
        Else
            ShowOpen = vbNullString
        End If

    Proc_Exit:
        Exit Function
    Proc_Error:
        ShowOpen = vbNullString
        MsgBox Err.Description
        Resume Proc_Exit
    End Function

  • Hi Erling,

    In the code to this form I include a call to Function "ShowOpen":

    From the posted snippet, it's not clear where GetOpenFileName method comes from.

    Because you work with properties like .hWndOwner etc, it seems you call Win32 API directly?

    In fact it's not MicroStation VBA question at all, but when you call native API, it's better to ask "how to do the same in 64bit environment" and I assume general VBA forums (like StackOverflow or similar) are better places where to ask.

    Why don't this work in a newer MicroStation?

    Because MicroStation V8i is 32bit application and MicroStation CE is 64bit application, all external resource used in your code have to be revisited and often modified or rewritten:

    • Referenced OCX and other libraries
    • Calls of native API

    With regards,

      Jan

  • I have problems using vba Function "ShowOpen". My vba runs fine on MicroStation V8i (SELCTseries 3), but it will not open Dialogbox for selecting file in a newer MicroSration version.

    As Jan says, 64-bit VBA is not 32-bit VBA, and Microsoft changed things! 

    Read this article about the Microsoft Common Dialogs.

     
    Regards, Jon Summers
    LA Solutions

  • Thanks a lot Jan.

    I also thought 64bit could be a problem. And yes I use Windows Win32 API.

    But the code contains the following calls depending on whether I am running 32 or 64 bits:

    Option Explicit
    ' ---------------------------------------------------------------------
    '   Win32 API declarations so that VBA can call
    '   Windows functions directly
    ' ---------------------------------------------------------------------
    #If VBA7 Then
       Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
       Private Declare PtrSafe Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
    #Else
       Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
       Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
    #End If
    

    I I thought this was sufficient, but do I need more?