Using the Windows CommonDialog Control
Does anyone have some good resources for the scripting features in CRT. I've reviewed the example scripts and FAQ's available. However, I still can't find what I need. I need to run a script that will open the Windows CommonDialog box to let the user browse for and select a file.
I've tried something like this : ---------------------------------------------------- Set objDialog = CreateObject("Test.CommonDialog") objDialog.Filter = "STP Scripts|*.txt|All Files|*.*" objDialog.Flags = &H0200 objDialog.FilterIndex = 1 objDialog.InitialDir = "C:\" intResult = objDialog.ShowOpen If intResult = 0 Then Wscript.Quit Else Wscript.Echo objDialog.FileName End If ---------------------------------------------------- Unfortunately, all I get is an error "Microsoft VBScript runtime error : Error : ActiveX component can't create object 'Test.CommonDialog' " Do I have to have Windows Scripting Host activated? If so, I am out of luck because our company does not allow this. Any ideas on this? Also, I am trying to use CRT to replace ProComm. In ProComm, I could create custom dialog boxes with text fields, radio buttons, command buttons, etc. Is this possible with CRT? |
I am pretty sure you cannot access CommonDialog or anything of the sort using vbscripting.
|
Quote:
CRT doesn't currently provide a way to create cusom dialogs within a script, but I've added a feature request and we'll consider adding it to a future version. Can you provide me with an example of how you would create a custom dialog with radio buttons, buttons, etc. within your procomm script? What kind of dialog box are you tring to create, and how will it be used? Once the dialog is dismissed by the user, how do you envision retrieving the values from the dialog's components? |
1 Attachment(s)
Jake,
"Test.CommonDialog" was simply a mistake on my part. I was thinking that "test" was the window title for the CommonDialog control. However, I think you can only acces the CommonDialog control in the action VisualBasic program used to create DLL's and executables. ProComm uses a language called "Windows Aspect Scripting" (more info : http://www.aspectscripting.com/index.shtml) that allows me to define a dialog box such as : ; DISPLAY DIALOG TO GET CAPTURE FILE NAME dialogbox 0 28 20 200 91 2 "Capture Control" text 1 9 10 64 11 "Capture File Name:" right editbox 2 75 9 100 11 Cname pushbutton 3 96 48 39 12 "Cancel" pushbutton 4 136 48 39 12 "OK" checkbox 5 12 44 69 8 "Do Not Capture" captureMe checkbox 6 12 55 69 8 "Overwrite capture ?" clobberMe text 7 12 72 103 11 "Rejected Commands logged to:" right text 8 118 72 73 11 "C:\temp\Cmd_Err.txt" right checkbox 9 12 32 69 8 "Log Errors ?" logerror enddialog I've attached a Word Doc with the screen prints for how some of these look. I would use the code below to acces the different fields and options defined above. Also the last word on each line (except right, left, etc) are the variable names for these fields. So for example, to reference whether or not the checkbox was selected, I just use the "logerror" variable. ; PROCESS DIALOG EVENT while 1 dlgevent 0 event switch event case 3 halt endcase case 4 exitwhile endcase endswitch endwhile dlgdestroy 0 CANCEL I would love to be able to do something like this in CRT. I was hoping that CRT supported the VisualBasic scripting that allows dialog boxes, etc, but it does not seem to. The code sample I showed in the original post is a sample from a web page. |
Thanks for the additional information. I'll forward it on to the product manager for consideration.
Quote:
|
Using the Windows CommonDialog Control
Jake,
Actually, it seems you may already have a dialog box for accessing files. The box that is used for the "Transfer" "Send ASCII" ,etc boxes would work just fine. Can y'all create a box like these that we can access in VB and Javascript? Thanks justbn |
Bind to a Folder Using the Browse for Folder Dialog Box
Found the following information ealier today when researching my own script challenges. This should answer your question. You can also browse around here for more info. http://www.microsoft.com/technet/scr...r/default.mspx
----Start Const WINDOW_HANDLE = 0 Const NO_OPTIONS = 0 Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.BrowseForFolder _ (WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "C:\Scripts") Set objFolderItem = objFolder.Self objPath = objFolderItem.Path objPath = Replace(objPath, "\", "\\") strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2") Set colFiles = objWMIService.ExecQuery _ ("Select * from Win32_Directory where name = '" & objPath & "'") For Each objFile in colFiles Wscript.Echo "Readable: " & objFile.Readable Next END <-------- |
Bind to a Folder Using the Browse for Folder Dialog Box
jdurrett,
Thanks for the response. Unfortunately, I can't get it to work for me. It works fine when I run it outside of CRT. However, when I run it in CRT, I get "Object Required : Wscript". I read something else on this forum about that. From this post below - it appears that CRT really can't deal with this or that I simply can't figure it out. ------------------------------------------------------------------------- ------------------------------------------------------------------------- ------------------------------------------------------------------------- jdev 12-03-2004, 03:12 PM One of the limitations of an application hosting ActiveX scripting is the inability to gain access to functions that are not true objects within the script engine itself. When running a vbscript outside of CRT/SecureCRT (where CScript.exe or WScript.exe are hosting the script code), you can make calls to things like: WScript.Arguments WScript.Path WScript.Quit WScript.Sleep ... However, when CRT/SecureCRT is hosting the script (instead of WScript.exe or CScript.exe), the WScript object itself isn't there; and unless you can call "CreateObject" to instantiate objects provided by WScript, they can't be used within a CRT/SecureCRT script. In the past, we've made things like "Sleep" and "Arguments" available by providing an API within the CRT object that can be used for making these types of calls (e.g. crt.sleep; crt.arguments). We can consider adding something like a crt.ScriptFullName to resolve this problem for you. There might be another way to accomplish what you need. Can you provide more information about the script you are writing and the need to know the full path to the script being run? --Jake ------------------------------------------------------------------------- ------------------------------------------------------------------------- ------------------------------------------------------------------------- |
Bind to a Folder Using the Browse for Folder Dialog Box
Try this statement instead of the Wscript.Echo
crt.Dialog.MessageBox ("Readable: " & objFile.Readable) crt.Dialog.MessageBox ("Readable: " & objFile.Name) Will produce two message boxes. One says readable, the other gives the path. I have been unable to find a suitable script for browsing and selecting file(s). cheers |
Recent Discovery related to use of CommonDialog in a VBScript
> Thanks for the response. Unfortunately, I can't get it to
> work for me. It works fine when I run it outside of CRT. > However, when I run it in CRT, I get "Object Required : > Wscript". Yes. Any direct function/property like Sleep or Arguments available through WScript.* isn't available within a CRT script. If a messagebox is all you're looking for, the MsgBox() vbscript built-in works well too: Code:
For Each objFile in colFiles With respect to browsing for a file, I've done some web searching and have located two different methods of accomplishing this via vbscript and have provided an example script comparing the two methods. The BrowseWithCommonDialog method is similar to the first script that was posted to this thread, and it will only work on Windows XP. The BrowseWithIE method will work on just about any OS with IE 5+ installed, but the interface is more cumbersome. Do either of the options within the example script below work for you? Code:
#$language = "VBScript" |
Using the Windows CommonDialog Control
Looking at your script below to open a file...well how can I echo JUST the FILENAME instead of the entire path? eg. if objDialog.Filename = C:\Program Files\Test.txt then I would just like to wscript.echo Test (no file extension neither file path)
Please help as i stuck with writing an oracle script. Really need this to work. :confused: Set objDialog = CreateObject("UserAccounts.CommonDialog") objDialog.Filter = "Select Oracle Backup file|*.dat|All Files|*.*" objDialog.FilterIndex = 1 objDialog.InitialDir = "C:\" intResult = objDialog.ShowOpen If intResult = 0 Then Wscript.Quit Else Wscript.Echo objDialog.FileName End If |
> how can I echo JUST the FILENAME instead of the entire
> path? Have you considered using the GetFileName() method available with vbscripts FileSystemObject? Code:
Dim fso |
Quote:
We now have a sample script that shows how this can be done using the Internet Explorer object in VBScript. This sample script is attached on the following forum post: http://forums.vandyke.com/showthread.php?t=2403 This script is not a complete solution but may give you another option for the creation of a custom dialog. |
Dialogs using CRT.
1 Attachment(s)
Below is a script I wrote that uses the BrowseForFolder method from the "Shell.Application" and it runs fine in CRT. You just have to work around the WSH script stuff. CRT only supports VBS scripting. The problem with the one on this post was the "Wscript.echo" at the end. That was why you got the error.
There is also a free activeX component out there called "GooeyScript" that lets you build really nice dialogs, it works really well with CRT, the only problem I have found with it is this is you can't use the "button" function because it uses the WSH version of "CreateObject" to pull in a variable to use for the event handler. I worked around that buy using the "OptionButton" function and a "do until" statement instead. In the GooeyScript documentation the examples show "Wscript.CreateObject" , just change this to "CreateObject" for it to work in CRT. I have attached a ZIP file with the GooeyScript component and all the documentation. There is also a "crt_demo.vbs" in there also that you can run to see how it works. Hope this helps.. Chase. ============================================= Dim filesys, Wshshell Const WINDOW_HANDLE = 0 Const NO_OPTIONS = 0 Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 Set Wshshell = CreateObject("WScript.Shell") Set filesys = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Shell.Application") '------------------------------------------------------------------------------------- '---- Sets up a regExp pattern for the parse search '------------------------------------------------------------------------------------- Dim regExp1 : Set regExp1 = New RegExp regExp1.Global = False regExp1.Pattern = "^\|[0-9]+\|.*$" regExp1.IgnoreCase = True Dim regExp2 : Set regExp2 = New RegExp regExp2.Global = False regExp2.Pattern = "^[0-9]+;.*$" regExp2.IgnoreCase = True '------------------------------------------------------------------------------------- '---- Launch Folder browser and get capture directory to be parsed. '------------------------------------------------------------------------------------- objFolder = False Set objFolder = objShell.BrowseForFolder (WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "") If objFolder Is Nothing Then MsgBox ("No folder selected,, Exiting script !!") Wscript.Quit End If Set objFolderItem = objFolder.Self objPath = objFolderItem.Path '------------------------------------------------------------------------------------- '---- Parse the file in the capture directory. '------------------------------------------------------------------------------------- Set objFolder = filesys.GetFolder(objPath) For Each objfile in objFolder.Files Set testFile = filesys.OpenTextFile(objFile.path, ForReading) Report="" 'the idea to be proper requires reset to empty' Do Until testFile.AtEndOfStream varLine = testFile.ReadLine Do While Instr(varLine, " ") varLine = Replace(varLine, " ", "") Loop If (regExp1.Test(varLine)) Or (regExp2.Test(varLine)) Then If (Left(varLine,1) = "|") Then Report = Report & Mid(Trim(varLine),2) & vbCrLf Else Report = Report & Trim(varLine) & vbCrLf' End If End If Loop 'Change delimiter Report = Replace(Report, "|", ";") ''''''''''Write the changed text back to the file Set testFile = filesys.OpenTextFile(objFile.path, ForWriting) testFile.Write Report testFile.Close For K = 1 To 1000000 'put this in so you can see the file names in the Processbar Next Next MsgBox (" ***** Parsing of the PPK files complete !!! *****") |
Quote:
just what i was looking for. now, i just have to figure out why i'm not able to do the following ------------------ crt.screen.Send <value from the dialog-box text field> ------------------ thanks areotree |
All times are GMT -6. The time now is 05:50 AM. |