ShowOpenFileDialog – Show a Open File common dialog

ShowOpenFileDialog – Show a Open File common dialog

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _    "GetOpenFileNameA" (pOpenfilename As OpenFilename) As LongPrivate Type OpenFilename    lStructSize As Long    hwndOwner As Long    hInstance As Long    lpstrFilter As String    lpstrCustomFilter As String    nMaxCustFilter As Long    iFilterIndex As Long    lpstrFile As String    nMaxFile As Long    lpstrFileTitle As String    nMaxFileTitle As Long    lpstrInitialDir As String    lpstrTitle As String    flags As Long    nFileOffset As Integer    nFileExtension As Integer    lpstrDefExt As String    lCustData As Long    lpfnHook As Long    lpTemplateName As StringEnd TypePrivate Enum OFNFlagsEnum    OFN_ALLOWMULTISELECT = &H200    OFN_CREATEPROMPT = &H2000    OFN_ENABLEHOOK = &H20    OFN_ENABLETEMPLATE = &H40    OFN_ENABLETEMPLATEHANDLE = &H80    OFN_EXPLORER = &H80000    OFN_EXTENSIONDIFFERENT = &H400    OFN_FILEMUSTEXIST = &H1000    OFN_HIDEREADONLY = &H4    OFN_LONGNAMES = &H200000    OFN_NOCHANGEDIR = &H8    OFN_NODEREFERENCELINKS = &H100000    OFN_NOLONGNAMES = &H40000    OFN_NONETWORKBUTTON = &H20000    OFN_NOREADONLYRETURN = &H8000    OFN_NOTESTFILECREATE = &H10000    OFN_NOVALIDATE = &H100    OFN_OVERWRITEPROMPT = &H2    OFN_PATHMUSTEXIST = &H800    OFN_READONLY = &H1    OFN_SHAREAWARE = &H4000    OFN_SHAREFALLTHROUGH = 2    OFN_SHARENOWARN = 1    OFN_SHAREWARN = 0    OFN_SHOWHELP = &H10End Enum' Show the common dialog to select a file to open. Returns the path of the' selected file or a null string if the dialog is canceled' Parameters:'  - sFilter is used to specify what type(s) of files will be shown'  - sDefExt is the default extension associated to a file name if no one is ' specified by the user'  - sInitDir is the directory that will be open when the dialog is shown'  - lFlag is a combination of Flags for the dialog. Look at the Common ' Dialogs' Help for more informations'  - hParent is the handle of the parent form' Example:'    Dim sFilter As String'    'set the filter: show text files and all the files'    sFilter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"'    'let the user select a file, ensuring that it exists'    MsgBox "File selected: " & ShowOpenFileDialog(sFilter, "txt",'  "C:Documents", OFN_FILEMUSTEXIST)Function ShowOpenFileDialog(ByVal sFilter As String, Optional ByVal sDefExt As _    String, Optional ByVal sInitDir As String, Optional ByVal lFlags As Long, _    Optional ByVal hParent As Long) As String    Dim OFN As OpenFilename    On Error Resume Next        ' set the values for the OpenFileName struct    With OFN        .lStructSize = Len(OFN)        .hwndOwner = hParent        .lpstrFilter = Replace(sFilter, "|", vbNullChar) & vbNullChar        .lpstrFile = Space$(255) & vbNullChar & vbNullChar        .nMaxFile = Len(.lpstrFile)        .flags = lFlags        .lpstrInitialDir = sInitDir        .lpstrDefExt = sDefExt    End With        ' show the dialog, non-zero means success    If GetOpenFileName(OFN) Then        ' extract the selected file (including the path)        ShowOpenFileDialog = Left$(OFN.lpstrFile, InStr(OFN.lpstrFile, _            vbNullChar) - 1)    End IfEnd Function

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes