Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Saturday, April 20, 2024 
 
How to Use Common Dialogs in SalesLogix  
Description:  There are many scenarios when doing SalesLogix customizations where you might need to make use of a common dialog, such as the "Open File" or "Save File" dialogs. There are a few different options when it comes to using common dialogs in a SalesLogix environment, some better than others. The purpose of this article is to examine each option and discuss the pros and cons of each.

Category:  Architect How To Articles
Author:  Ryan Farley
Submitted:  5/18/2005
   
Stats: 
Article has been read 25020 times

Rating: - 5.0 out of 5 by 5 users
 

fiogf49gjkf0d
How to Use Common Dialogs in SalesLogix

There are many scenarios when doing SalesLogix customizations where you might need to make use of a common dialog, such as the "Open File" or "Save File" dialogs. There are a few different options when it comes to using common dialogs in a SalesLogix environment, some better than others. The purpose of this article is to examine each option and discuss the pros and cons of each.

Microsoft Common Dialog Control

The Microsoft Common Dialog Control, found in COMDLG32.OCX, contains the common dialogs used in Windows applications. You will find there the dialogs used for Open File, Save File, Select Printer, Select Font, and Select Color. These dialogs can easily be used to prompt the user while using the same familiar dialogs they see every day. While this option does allow for the greatest flexibility, there are some huge limitations with this option when used in a SalesLogix environment.

Sample

' demo using the common dialog found in comdlg32.ocx
Dim dlg

    Set dlg = CreateObject("MSComDlg.CommonDialog")
    With dlg
        .DialogTitle = "Select a file..."

        'optional file type filter
        .Filter = "Word Documents (*.doc)|*.doc|Excel Spreadsheets (*.xls)|*.xls"
        .FilterIndex = 0

        .ShowOpen
        If .FileName <> "" Then
            MsgBox "File selected was: " & .FileName
        End If
    End With    

Pros
  1. Provides the most flexibility with available properties.
  2. Allows for display of Open, Save, Printer, Font, etc dialogs.
Cons
  1. You cannot guarantee that the COMDLG32.OCX control will be found on every machine.
  2. The control requires a license, that limits it's use unless you have an installed development environment such as Visual Studio.
  3. There are occasional issues that can, and likely will, arise in a scripting environment. A common problem is an error indicating that there is insufficient memory to display the dialog.

Windows XP User Accounts Applet

The Windows XP User Accounts control panel applet wraps the Open File dialog and it exposes it via COM for anyone to use. The control panel applet, NUSRMGR.CPL, exposes the dialog via the UserAccounts.CommonDialog object. The only dialog available is the Open File dialog, but it is easy to use.

Sample

' demo using the common dialog wrapped in nusrmgr.cpl
Dim dlg

    Set dlg = CreateObject("UserAccounts.CommonDialog")
    With dlg
        'optional file type filter
        .Filter = "Word Documents (*.doc)|*.doc|Excel Spreadsheets (*.xls)|*.xls"
        .FilterIndex = 0

        If .ShowOpen Then
            MsgBox "File selected was: " & .FileName
        End If
    End With

Pros
  1. Easy to use.
  2. No license required.
Cons
  1. Only available on Windows XP.
  2. Only the Open File dialog is available, it does not contain any other dialogs.

Wrapping the Dialogs in a Distributable Control

For those not afraid of distributing external components to their end users, the option of wrapping the dialogs allows for the greatest ability to use the dialogs without any license or other "cons" mentioned previously. You basically just create a COM DLL that wraps the dialogs using the COMDLG32.OCX and then distribute the DLL to end users via an install (which includes the COMDLG32.OCX which would now be properly licensed). You could then instantiate the class in the DLL that wraps the appropriate dialog easily from a SalesLogix script. Alternatively, instead of using the COMDLG32.OCX you could wrap the direct API calls to display the dialogs without the need for the COMDLG32.OCX component.

Pros
  1. Greatest flexibility. You control how the dialogs work since you're using your own wrapper for them.
  2. You can expose any or all dialogs.
  3. No licensing issues.
Cons
  1. Need to distribute to all end users.

Using the SalesLogix LookupEdit Control

You can use the SalesLogix LookupEdit control to display the Open File dialog. This is the least flexible option, but the only one that will work on every machine, every time - without the use of anything external. You can hide a LookupEdit control on a form, set it's LookupMode property to "lmFile". Then to use it you just call LookupEdit1.Popup to display the Open File dialog and then get the selected file via the Text property. The biggest limitation here is that you cannot specify the allowable file types for the user to select so you have to do your own validation after the fact.

Sample

' uses a LookupEdit control named "LookupEdit1"
' with its LookupMode set to "lmFile" and 
' hidden on a form.

    With LookupEdit1
        'first clear the text to start blank
        .Text = ""

        'pop the lookup, this will display the Open File dialog
        .Popup

        'get the selected file name from the control
        If .Text <> "" Then
            'validate selected file type
            If (Right(UCase(.Text), 3) = "DOC") Or (Right(UCase(.Text), 3) = "XLS") Then
                MsgBox "File selected was: " & .Text
            Else
                MsgBox "Only Word Documents (*.doc) or Excel Spreadsheets (*.xls) are allowed. Try again."
            End If
        End If
    End With

Pros
  1. Works on any machine, every time.
  2. Minimal programming.
Cons
  1. Requires a hidden control on the form.
  2. Only the Open File dialog is available.
  3. Does not allow for specifying a file type (allows user to select any file) so validation is required after the fact.

Wrapping it up

My hope is that this article quickly becomes obsolete. I would love to see SalesLogix build in wrappers for the common dialogs. I'd love to be able to access the Open File dialog available via Application.BasicFunction.OpenFileDialog(Title As String, Filter As String) As String or something along those lines. But until then, you can consider the options discussed in this article.

Until next time, happy coding.
-Ryan

 

About the Author

  Ryan Farley
(SalesLogix Business Partner)
Customer FX Corporation

fiogf49gjkf0d

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix since 2001 and believes in sharing with the community. He loves C#, Javascript, Python, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

View Ryan's SalesLogix Mobile Seveloper Series
View Ryan's SalesLogix SData Developer Series
View Ryan's Git for the SalesLogix Developer series



View online profile for Ryan Farley
 

[ back to top] [ send to a friend]  

Rate This Article you must log-in to rate articles. [login here] 
 
Please log in to rate article.
 

Comments & Discussion you must log-in to add comments. [login here] 
 
Article does not have any comments. Be the first to comment by clicking the 'add comment' link above!  

       Visit the slxdeveloper.com Community Forums!
Not finding the information you need here? Try the forums! Get help from others in the community, share your expertise, get what you need from the slxdeveloper.com community. Go to the forums...
 



 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 4/20/2024 2:07:21 AM