Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
  #1  
Old 07-28-2007, 02:20 PM
jvbright jvbright is offline
Registered User
 
Join Date: Jul 2007
Posts: 8
Question Dialog Box Help

I would like to create a dialog box with multiple inputs Using Secure CRT 6.0 Beta scripting.
Can anyone help...???
Reply With Quote
  #2  
Old 07-30-2007, 10:54 AM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Jvbright,

Creating a multiple input dialog box from SecureCRT's script objects is currently not possible.

This is something that we have received requests for previously and it will be under consideration for possible inclusion in a future release of SecureCRT.

I have added this forum post to this request so that a post can be made here if this scripting option is added.

If you would prefer to be contacted via email, please send me a message and reference this forum thread (2403).
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #3  
Old 08-04-2007, 07:28 AM
jvbright jvbright is offline
Registered User
 
Join Date: Jul 2007
Posts: 8
I am trying to use IE

I found a script that will allow the use of values from a web page. The forum says that it works, but I cannot seem to get the syntax correct.

#$language = "VBScript"
#$interface = "1.0"

Dim IE
dim namedit

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = 0
IE.navigate "C:\Program Files\VanDyke Software\SecureCRT6\Scripts\form.html"
Do While (IE.Busy)
crt.Sleep (10)
Loop

namedit = IE.document.getElementById("fName").value
MsgBox namedit

This is the form.html page:

<html>
<body bgcolor="silver" scroll="no">
Username: <input name="fName" id="fName" type="TEXT" size="5"><br>
Password: <input name="fAge" id="fAge" type="TEXT" size="3"><br>
Root Pass: <input name="rpw" id="rpw" type="TEXT" size="3">
</body>
</html>

The response is a failure on line 15..... The attached imaged is the failure.
Attached Images
File Type: bmp CRT.bmp (209.5 KB, 913 views)
Reply With Quote
  #4  
Old 08-04-2007, 11:09 AM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Jvbright,

The document.getElementById object is not a SecureCRT scripting object.

The error itself is coming from the Microsoft VBScript engine. There is more information on use this VBScript object at this link:

http://msdn2.microsoft.com/en-us/library/ms536437.aspx

Were was this script found?
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #5  
Old 08-14-2007, 01:39 PM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Jvbright,

The script that you mentioned is similar to a sample script that we posted in thread 2398.

We also have a sample script that is now available that shows how to accomplish a custom dialog box using Microsoft's InternetExplorer.Application object.

I have attached this sample script to this thread. The script is just a simple example of how a custom dialog could be created. Feel free to modify it to fit your specific needs.
Attached Files
File Type: txt UseIEAsCustomDialog.txt (14.5 KB, 1380 views)
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #6  
Old 06-24-2008, 03:39 PM
quark-man quark-man is offline
Registered User
 
Join Date: May 2005
Posts: 16
Quote:
Originally Posted by tnygren
Hi Jvbright,

The script that you mentioned is similar to a sample script that we posted in thread 2398.

We also have a sample script that is now available that shows how to accomplish a custom dialog box using Microsoft's InternetExplorer.Application object.

I have attached this sample script to this thread. The script is just a simple example of how a custom dialog could be created. Feel free to modify it to fit your specific needs.
the custom dialog IE script is excellent
thanks for that tnygren.
i just have a tiny question regarding it.

since i see it uses the 'buttonhandler' to tie the IE object with SecureCRT input, and the radio buttons are <input type="radio">...
i was wondering how to make those radio options as part of a drop-down list, i.e. like a 'select' statement??
any ideas?

thanks, SecureCRT is gets more awesome each version.
Reply With Quote
  #7  
Old 06-24-2008, 04:21 PM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi quark-man,

You will need to edit the HTML code to use a select instead of a radio input type, and use the 'onchange' method to set the ButtonHandler variable to the corresponding value, as with any other input. For example:

Code:
"<td  VALIGN='top'  COLSPAN='2' ALIGN=left>" & _
"<SELECT NAME='MyDropDown' ACCESSKEY='d' onchange=document.all('ButtonHandler').value='MyDropDownChange'>" & _
"<OPTION VALUE='Option1'>Option 1</OPTION>" & _
"<OPTION VALUE='Option2'>Option 2</OPTION>" & _
"<OPTION VALUE='Option3'>Option 3</OPTION>" & _
"<OPTION VALUE='Option4'>Option 4</OPTION>" & _
"</SELECT>" & _
"</td>" & _
The Select Case inside the constant loop that monitors the ButtonHandler variable value will then need to be modified to accept the new value, 'MyDropDownChange', for example.

Is this information helpful?
Reply With Quote
  #8  
Old 06-26-2008, 12:58 PM
quark-man quark-man is offline
Registered User
 
Join Date: May 2005
Posts: 16
Quote:
Originally Posted by kbarnette
Hi quark-man,

You will need to edit the HTML code to use a select instead of a radio input type, and use the 'onchange' method to set the ButtonHandler variable to the corresponding value, as with any other input. For example:

Code:
"<td  VALIGN='top'  COLSPAN='2' ALIGN=left>" & _
"<SELECT NAME='MyDropDown' ACCESSKEY='d' onchange=document.all('ButtonHandler').value='MyDropDownChange'>" & _
"<OPTION VALUE='Option1'>Option 1</OPTION>" & _
"<OPTION VALUE='Option2'>Option 2</OPTION>" & _
"<OPTION VALUE='Option3'>Option 3</OPTION>" & _
"<OPTION VALUE='Option4'>Option 4</OPTION>" & _
"</SELECT>" & _
"</td>" & _
The Select Case inside the constant loop that monitors the ButtonHandler variable value will then need to be modified to accept the new value, 'MyDropDownChange', for example.

Is this information helpful?

that looks and sounds good, kbarnette.

i wasn't thinking of the "onchange=" action nor the 'different' variables (i.e. MyDropDown & MyDropDownChange)

i'll have to script a test one up and check it out, but was it something like this?


Selection = g_objIE.Document.All("MyDropDown").Checked


then this


Case "MyDropDownChange"
g_objIE.Document.All("ButtonHandler").value = ""

if g_objIE.Document.All("MyDropDown").Checked then
g_objIE.Document.All("MyDropDown")(0).Disabled = False
g_objIE.Document.All("MyDropDown")(1).Disabled = False
g_objIE.Document.All("MyDropDown")(2).Disabled = False
g_objIE.Document.All("MyDropDown")(3).Disabled = False
g_objIE.Document.All("MyDropDown")(4).Disabled = False
else
g_objIE.Document.All("MyDropDown")(0).Disabled = True
g_objIE.Document.All("MyDropDown")(1).Disabled = True
g_objIE.Document.All("MyDropDown")(2).Disabled = True
g_objIE.Document.All("MyDropDown")(3).Disabled = True
g_objIE.Document.All("MyDropDown")(4).Disabled = True
end if



won't i need to worry about the 'index' positions of the select values??

for nIndex = 0 to g_objIE.Document.All("MyDropDownChange").Length - 1
if g_objIE.Document.All("MyDropDownChange")(nIndex).Checked then
MyMenuClick = g_objIE.Document.All("MyDropDownChange")(nIndex).Value
exit for
end If
Next

Last edited by quark-man; 06-26-2008 at 01:01 PM.
Reply With Quote
  #9  
Old 06-26-2008, 03:29 PM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi quark-man,

The drop down works differently than the radio selection. The onchange method is most handy when you want something to happen when the drop down is changed. You may be able to find more information about these HTML and vbscript questions from a search on the web, however the example code below may be helpful:

Code:
' DropDownIEExample.vbs

szHTMLBody = "<font color='red'><b><u>E</u>nable or disable the text field below: </b></font>" & _
        "<SELECT NAME='DropDown' onChange=document.all('ButtonHandler').value='DropDown'; AccessKey='e'>" & _
        "<OPTION VALUE='Enable'>Enable</OPTION>" & _
        "<OPTION VALUE='Disable'>Disable</OPTION>" & _
        "</SELECT><br>" & _
        "<b><u>T</u>ext:</b>" & _
        "<input name='TextField' size='40' maxlength='512' value='Here is my pre-populated text' AccessKey='t'>" & _
        "<hr>" & _
        "<button name='OK' AccessKey='O' Onclick=document.all('ButtonHandler').value='OK';><u>O</u>K </button>" & _
        "&nbsp;&nbsp;&nbsp;&nbsp;"  & _
        "<button name='Cancel' AccessKey='c' Onclick=document.all('ButtonHandler').value='Cancel';><u>C</u>ancel</button>"& _
        "<input name='ButtonHandler' type='hidden' value='Nothing Clicked Yet'>"


Dim g_objIE

    ' First step, set up the dialog (InternetExplorer)
    Set g_objIE = CreateObject("InternetExplorer.Application")
    g_objIE.Offline = True
    g_objIE.navigate "about:blank"
   
    ' This loop is required to allow the IE object to finish loading...
    Do
        Wscript.sleep 100
    Loop While g_objIE.Busy
    
    ' Make the custom dialog font to look more like standard Windows dialogs
    g_objIE.Document.body.Style.FontFamily = "Sans-Serif"
    
    ' Here's where we "create" the elements of our dialog box.  We basically
    ' throw HTML into the document, and IE loads it in real-time for us.
    ' 
    ' The hidden "ButtonHandler" input is used to tie IE and
    ' SecureCRT together such that SecureCRT can know when a
    ' button is pressed, etc.
    g_objIE.Document.Body.innerHTML = szHTMLBody
    
    ' Prevent the MenuBar, StatusBar, AddressBar, and Toolbar from being
    ' displayed as part of the IE window
    g_objIE.MenuBar = False
    g_objIE.StatusBar = False
    g_objIE.AddressBar = False
    g_objIE.Toolbar = False

    ' Set the initial size of the IE Window
    g_objIE.height = 150
    g_objIE.width = 450

    g_objIE.document.Title = "Authentication Credentials Prompt"
    g_objIE.Visible = True

    ' This loop is required to allow the IE window to fully display.
    Do
        Wscript.sleep 100
    Loop While g_objIE.Busy

    ' This code brings the IE window to the foreground.
    Set objShell = CreateObject("WScript.Shell")
    objShell.AppActivate g_objIE.document.Title

Do
    ' If the user closes the IE window by Alt+F4 or clicking on the 'X'
    ' button, we'll detect that here, and exit the script if necessary.
    On Error Resume Next
        Err.Clear
        szNothing = g_objIE.Document.All("ButtonHandler").Value
        if Err.Number <> 0 then exit do
    On Error Goto 0
        
    ' Check to see which buttons have been clicked, and address each one
    ' as it's clicked.
    Select Case g_objIE.Document.All("ButtonHandler").Value
        Case "Cancel"
            ' The user clicked Cancel. Exit the loop
            g_objIE.quit
            Exit Do
        Case "DropDown"
            ' The user changed the dropdown menu
            If g_objIE.Document.All("DropDown").Value = "Enable" then
                g_objIE.Document.All("TextField").Disabled = False
            Else
                g_objIE.Document.All("TextField").Disabled = True
            End If
            
        Case "OK"
            ' The user clicked OK. Act on the information in the
            ' Username and Password fields
            ' Capture data from each field in the dialog...
            MsgBox "The dropdown is set to " & g_objIE.Document.All("DropDown").Value
            g_objIE.Document.All("ButtonHandler").Value = ""
    End Select

    ' Wait for user interaction with the dialog...
    Wscript.sleep 200
Loop

Does this information help to clarify?
Reply With Quote
  #10  
Old 06-27-2008, 02:53 PM
quark-man quark-man is offline
Registered User
 
Join Date: May 2005
Posts: 16
Cool

Quote:
Originally Posted by kbarnette
Hi quark-man,

The drop down works differently than the radio selection. The onchange method is most handy when you want something to happen when the drop down is changed. You may be able to find more information about these HTML and vbscript questions from a search on the web, however the example code below may be helpful:

---<code snipped>---

Does this information help to clarify?
i see now what you mean by "onchange".
e.g. selecting one drop-down selection, can trigger/select a particular related value in another drop-down or even radio selection, right?

but that's something else.

i got confused by the variable of the select name being different from the onchange value name, i.e. MyDropDown and MyDropDownChange.

"<SELECT NAME='MyDropDown' ACCESSKEY='d' onchange=document.all('ButtonHandler').value='MyDropDownChange'>"

i wondered why they were different but did not want to ask if it was a typo error (and look stupid!)

anyway, i will give this "select" option a trial soon...but so far, SecureCRT v6.0 is fantastic because it supports the IE object...and more APIs.
Reply With Quote
  #11  
Old 06-27-2008, 03:00 PM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi quark-man,

You are correct in that the onchange() method can be used to execute some sort of code whenever the dropdown value is changed.

In any event, feel free to post the results of your efforts.
Reply With Quote
  #12  
Old 07-02-2008, 08:37 AM
quark-man quark-man is offline
Registered User
 
Join Date: May 2005
Posts: 16
Quote:
Originally Posted by kbarnette
Hi quark-man,

You are correct in that the onchange() method can be used to execute some sort of code whenever the dropdown value is changed.

In any event, feel free to post the results of your efforts.
tried the 'select' statement and it worked very neatly...giving me ideas for another implementation of mine.

basically, i replaced these

"<input type=radio name='LogMode' value='Append' AccessKey='A' checked><u>A</u>ppend<br>" & _
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;" & _
"<input type=radio name='LogMode' value='Overwrite' Accesskey='w' >Over<u>w</u>rite<br>" & _


with this -


"<SELECT NAME='LogMode' onChange=document.all('ButtonHandler').value='LogMode'; AccessKey='S'>" & _
"<OPTION VALUE='Append'>Append</OPTION>" & _
"<OPTION VALUE='Overwrite'>Overwrite</OPTION>" & _
"</SELECT><br>" & _



assigned the value of it to the variable,

szAppendOrOverwrite = g_objIE.Document.All("LogMode").Value


and also ensured that the element would be de-selected, if the LogOutput checkbox was not ticked


Case "LogOutput"
' Reset the button handler value. We don't do this in the
' case of "Cancel" and "OK" handling since the dialog is
' going away...
g_objIE.Document.All("ButtonHandler").value = ""

' Handle the check in real-time...
if g_objIE.Document.All("LogOutput").Checked then
' Enable the other elements of the dialog dealing with
' logging
g_objIE.Document.All("LogFilename").Disabled = False
g_objIE.Document.All("LogMode").Disabled = False
else
' Disable the other elements of the dialog dealing with
' logging
g_objIE.Document.All("LogFilename").Disabled = True
g_objIE.Document.All("LogMode").Disabled = True
end if



thanks again kbarnette.

i'm looking at other ways to spruce up this HTML dialog box, as the possibilities grow each time i look at it.
now, i just have to figure out where to look for HTML DOM attribtues/values, e.g. if i had selected the radio button for "Append", i want the button or the name itself to become "red" or "blue", etc.

i'm trying to put the radio labels in a table, with "element" or "name"...want them to become 'red' or 'blue' whenever it's selected, just so that it stands out.

anyway, this may be beyond the scope of what this Forums are for...so dont' worry too much about it.


i'll post if i come up with something.
Reply With Quote
  #13  
Old 09-04-2008, 10:26 PM
phillip phillip is offline
Registered User
 
Join Date: Aug 2008
Posts: 3
Custom Dialogue Box

Hi,

I have created a custom dialogue box using the example given by the Van Dyke support staff member.
This dialogue box has a listbox and one "OK" button. The script runs
but does not wait for the "OK" button to be clicked. Can anyone spot what is wrong?

=========================================================
# $language = "VBScript"
# $interface = "1.0"
' Listbox example
Option Explicit
Dim aOpt
Dim s
Dim sel
aOpt = Array("\\mail\HP 4100 - Clinical - Clare", _
"\\mail\HP 4000 - Admissions", _
"\\medical\HP LaserJet 4000 - Medical", _
"\\mail\HP 4000 - Front Desk", _
"\\mail\HP 4000 - Business Office", _
"\\mail\HP 4100 - Clinical - HRC", _
"\\mail\HP 4100 - Business Office", _
"\\victoria\HP 4500" _
)

sel=split(SelectBox("Select a default printer", aOpt),",")
For s = LBound(sel) to UBound(sel)
msgbox "You selected:" & sel(s)
next

Function SelectBox(sTitle, aOptions)
Dim oIE, s, item, i, dummy
set oIE = CreateObject("InternetExplorer.Application")
With oIE
.FullScreen = True ' remove if using IE 7+
.ToolBar = False : .RegisterAsDropTarget = False
.StatusBar = False : .Navigate("about:blank")
While .Busy : WScript.Sleep 100 : Wend
.width= 400 : .height=175
With .document
with .parentWindow.screen
oIE.left = (.availWidth-oIE.width)\2
oIE.top = (.availheight-oIE.height)\2
End With ' ParentWindow
s = "<html><head><title>" & sTitle _
& "</title></head>" _
& "<body bgColor=ghostwhite><center><b>" & sTitle & "<b><p>" _
& "<select id=entries style='width:325px' multiple size='4'>" _
& " <option selected>" & sTitle & "</option>"
For each item in aOptions
s = s & " <option>" & item & "</option>"
Next
s = s & " </select><p>" _
& "<button id='OK' onclick=document.all('ButtonHandler').value='OK';>OK</button>" _
& "<input name='ButtonHandler'type='hidden' value='Nothing Clicked Yet'>" _
& "</center></body></html>"
.open
.WriteLn(s)
.close
Do until .ReadyState ="complete" : Wscript.Sleep 50 : Loop
With .body
.scroll="no"
.style.borderStyle = "outset"
.style.borderWidth = "3px"
End With ' Body
.all.entries.focus
oIE.Visible = True

CreateObject("Wscript.Shell").AppActivate sTitle

' Wait for user to click OK
Do
' Case when user closes IE using the "X" icon
On Error Resume Next
Err.clear
dummy=.All("ButtonHandler").value
if Err.Number<>0 Then Exit Function
' Has he clicked the OK button?
msgbox "Button=" & .All("ButtonHandler").value
if .All("ButtonHandler").value="OK" Then
Exit Do
end if
' Wait for something that will never occur - time for user interaction
screen.WaitForString "1342;l1@#$! This will never appear",1
Loop

On Error Goto 0
selectBox=""
With .ParentWindow.entries
For i = 0 to .length - 1
If .options(i).selected=true Then
If SelectBox="" Then
selectBox=.options(i).text
Else
selectBox=selectBox & "," & .options(i).text
End If
End If
Next
' SelectBox = .options(.selectedIndex).text
End With
End With ' document
.Visible = False
End With ' IE
End Function
==========================================================
Quote:
Originally Posted by tnygren
Hi Jvbright,

The script that you mentioned is similar to a sample script that we posted in thread 2398.

We also have a sample script that is now available that shows how to accomplish a custom dialog box using Microsoft's InternetExplorer.Application object.

I have attached this sample script to this thread. The script is just a simple example of how a custom dialog could be created. Feel free to modify it to fit your specific needs.
Reply With Quote
  #14  
Old 09-05-2008, 03:04 PM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi Phillip,

I have a suggestion to help us determine where the problem with the script lies.

Code:
Do
' Case when user closes IE using the "X" icon
On Error Resume Next
Err.clear
dummy=.All("ButtonHandler").value
if Err.Number<>0 Then Exit Function
' Has he clicked the OK button?
msgbox "Button=" & .All("ButtonHandler").value
if .All("ButtonHandler").value="OK" Then
Exit Do
end if
' Wait for something that will never occur - time for user interaction
screen.WaitForString "1342;l1@#$! This will never appear",1
Loop
In the code above, please comment out the following lines:

Code:
On Error Resume Next
Err.clear
Are you seeing an error message by commenting out the previous lines of code?
If so, what line does the error occur on and what is the error message?
Also, how are you launching the script?
For example, are you launching the script from within SecureCRT?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 07:51 AM.