11/24/2024 9:21:45 PM
slxdeveloper.com
Now Live!
|
|
|
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 25360 times
|
Rating:
- 5.0 out of 5 by 5 users |
|
|
|
fiogf49gjkf0d
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.
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
- Provides the most flexibility with available properties.
- Allows for display of Open, Save, Printer, Font, etc dialogs.
Cons
- You cannot guarantee that the COMDLG32.OCX control will be found on every machine.
- The control requires a license, that limits it's use unless you have an installed development environment such as Visual Studio.
- 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.
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
- Easy to use.
- No license required.
Cons
- Only available on Windows XP.
- Only the Open File dialog is available, it does not contain any other dialogs.
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
- Greatest flexibility. You control how the dialogs work since you're using your own wrapper for them.
- You can expose any or all dialogs.
- No licensing issues.
Cons
- Need to distribute to all end users.
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
- Works on any machine, every time.
- Minimal programming.
Cons
- Requires a hidden control on the form.
- Only the Open File dialog is available.
- Does not allow for specifying a file type (allows user to select any file) so validation is required after the fact.
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
|
|
|
|
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]
|
|
|
- subject is missing.
- comment text is missing.
|
|
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...
|
|
|
|
|
|