VBS down menu pass to Batch?

Hewlett-packard / Sd2100
March 2, 2010 at 20:26:57
Specs: Windows 7, 1024
I have a question is it possible to pass selection to a batch CMD windows with this code below?

i want to use it as a menu seletion in one of my batchs and have my batch call the .VBS drop menu and pass it back to the menu to move to the selected choice.

Thank you all ive been messing with this but now need help.

Option Explicit
Dim aOpt(4)
aOpt(0) = "Option 1"
aOpt(1) = "Option 2"
aOpt(2) = "Option 3"
aOpt(3) = "Option 4"
aOpt(4) = "Option 5"
wsh.echo "You selected:", SelectBox("Select an option", aOpt)

Function SelectBox(sTitle, aOptions)
Dim oIE, s, item
set oIE = CreateObject("InternetExplorer.Application")
With oIE
.ToolBar = False : .RegisterAsDropTarget = False
.StatusBar = False : .Navigate("about:blank")
While .Busy : WScript.Sleep 100 : Wend
With .document
With .parentWindow
if Instr(.navigator.appVersion, "MSIE 6") > 0 Then
oIE.FullScreen = True
End if
oIE.width = 400 : oIE.height = 150
oIE.left = .screen.width \ 2 - 200
oIE.top = .screen.height\ 2 - 75
End With ' ParentWindow
s = "<html><head><title>" & sTitle & " " & String(80, ".") _
& "</title></head><script language=vbs>bWait=true</script>" _
& "<body bgColor=Silver><center>" & sTitle & "

" _
& "<select id=entries size=1 style='width:250px'>" _
& " <option selected>" & sTitle & "</option>"
For each item in aOptions
s = s & " <option>" & item & "</option>"
Next
s = s & " </select>

" _
& "<button id=but0 onclick='bWait=false'>OK</button>" _
& "</center></body></html>"
.WriteLn(s)
With .body
.scroll="no"
.style.borderStyle = "outset"
.style.borderWidth = "3px"
End With ' Body
.all.entries.focus
oIE.Visible = True
On Error Resume Next
While .ParentWindow.bWait
WScript.Sleep 100
if oIE.Visible Then SelectBox = "Aborted"
if Err Then Exit Function
Wend ' Wait
On Error Goto 0
With .ParentWindow.entries
SelectBox = .options(.selectedIndex).text
End With
End With ' document
.Visible = False
End With ' IE
End Function


See More: VBS down menu pass to Batch?

Report •


#1
March 2, 2010 at 20:47:37
WScript.Quit SelectBox("Select an option", aOpt)

Then you can test the results by looking at the script's %ErrorLevel%

Report •

#2
March 2, 2010 at 21:27:08

im having issues creating the code in a VBS, it fails. can you help me out by creating it.

i know

set vbs=drop.vbs

then echo {code} >%vbs%

but it fails.


Report •

#3
March 3, 2010 at 00:23:04
can someone take a look at this and see where i went wrong? because it fails to start. not sure why. my first post the the original code what it looks like.

thank you all


set vbs=drop.vbs


echo Option Explicit >%vbs%
echo Dim aOpt(4) >>%vbs%
echo aOpt(0) = "Option 1" >>%vbs%
echo aOpt(1) = "Option 2" >>%vbs%
echo aOpt(2) = "Option 3" >>%vbs%
echo aOpt(3) = "Option 4" >>%vbs%
echo aOpt(4) = "Option 5" >>%vbs%
echo wsh.echo "You selected:", SelectBox("Select an option", aOpt) >>%vbs%

echo Function SelectBox(sTitle, aOptions) >>%vbs%
echo Dim oIE, s, item >>%vbs%
echo set oIE = CreateObject("InternetExplorer.Application") >>%vbs%
echo With oIE >>%vbs%
echo .ToolBar = False : .RegisterAsDropTarget = False >>%vbs%
echo .StatusBar = False : .Navigate("about:blank") >>%vbs%
echo While .Busy : WScript.Sleep 100 : Wend >>%vbs%
echo With .document >>%vbs%
echo With .parentWindow >>%vbs%
echo if Instr(.navigator.appVersion, "MSIE 6") > 0 Then >>%vbs%
echo oIE.FullScreen = True >>%vbs%
echo End if >>%vbs%
echo oIE.width = 400 : oIE.height = 150 >>%vbs%
echo oIE.left = .screen.width \ 2 - 200 >>%vbs%
echo oIE.top = .screen.height\ 2 - 75 >>%vbs%
echo End With ' ParentWindow >>%vbs%
echo s = "<html><head><title>" ^& sTitle ^& " " ^& String(80, ".") _ >>%vbs%
echo ^& "</title></head><script language=vbs>bWait=true</script>" _ >>%vbs%
echo ^& "<body bgColor=Silver><center>" ^& sTitle ^& " >>%vbs%

echo "_ >>%vbs%
echo ^& "<select id=entries size=1 style='width:250px'>" _ >>%vbs%
echo ^& " <option selected>" ^& sTitle ^& "</option>" >>%vbs%
echo For each item in aOptions >>%vbs%
echo s = s ^& " <option>" ^& item ^& "</option>" >>%vbs%
echo Next >>%vbs%
echo s = s ^& " </select> >>%vbs%

echo "_ >>%vbs%
echo ^& "<button id=but0 onclick='bWait=false'>OK</button>" _ >>%vbs%
echo ^& "</center></body></html>" >>%vbs%
echo .WriteLn(s) >>%vbs%
echo With .body >>%vbs%
echo .scroll="no" >>%vbs%
echo .style.borderStyle = "outset" >>%vbs%
echo .style.borderWidth = "3px" >>%vbs%
echo End With ' Body >>%vbs%
echo .all.entries.focus >>%vbs%
echo oIE.Visible = True >>%vbs%
echo On Error Resume Next >>%vbs%
echo While .ParentWindow.bWait >>%vbs%
echo WScript.Sleep 100 >>%vbs%
echo if oIE.Visible Then SelectBox = "Aborted" >>%vbs%
echo if Err Then Exit Function >>%vbs%
echo Wend ' Wait >>%vbs%
echo On Error Goto 0 >>%vbs%
echo With .ParentWindow.entries >>%vbs%
echo SelectBox = .options(.selectedIndex).text >>%vbs%
echo End With >>%vbs%
echo End With ' document >>%vbs%

echo .Visible = False >>%vbs%
echo End With ' IE >>%vbs%
echo End Function >>%vbs%


Report •

Related Solutions

#4
March 3, 2010 at 05:50:22
Every < symbol should be prefixed with ^. Every > symbol not a part of the >> %vbs% should be prefixed with ^.

Report •

#5
March 3, 2010 at 08:57:44
right i did try that but still no go. im not sure why there is an issue

Report •

#6
March 3, 2010 at 09:04:20
i add the ^< but when the VBS is created it shows the ^ in the code, maybe that is the issue.

Report •

#7
March 3, 2010 at 12:23:42
any ideas guys? thank you !

Report •

#8
March 3, 2010 at 15:19:54
ok i figured it out.


now i need help understanding this

quoted from Razor

WScript.Quit SelectBox("Select an option", aOpt)


Then you can test the results by looking at the script's %ErrorLevel%

i call the vbs and do a test but the command line says its not a internal command. am i do something wrong here?

i want to pass the selection from drop menu back to the batch from which it was called.


Report •

#9
March 3, 2010 at 15:33:36
You know, at this point, it'd probably be easier to just pick a scripting language and stick with it, instead of trying to hack them together.
cscript //nologo yourScript.vbs
echo %errorlevel%


Report •

#10
March 3, 2010 at 22:16:41
@brockey01: In future if your going to pm me for help, please
just pm me with the url of the thread. I generally take a dim
view of pm help requests that are verbatim of threads.

@ECHO OFF
set vbs=menu.vbs 
(
    echo.Option Explicit
    echo.Dim aOpt^(4^)
    echo.aOpt^(0^) = "Option 1"
    echo.aOpt^(1^) = "Option 2"
    echo.aOpt^(2^) = "Option 3"
    echo.aOpt^(3^) = "Option 4"
    echo.aOpt^(4^) = "Option 5"
    echo.wsh.echo "You selected:", SelectBox^("Select an option", aOpt^)
    echo.
    echo.
    echo.Function SelectBox^(sTitle, aOptions^)
    echo.Dim oIE, s, item
    echo.set oIE = CreateObject^("InternetExplorer.Application"^)
    echo.With oIE
    echo..ToolBar = False : .RegisterAsDropTarget = False
    echo..StatusBar = False : .Navigate^("about:blank"^)
    echo.While .Busy : WScript.Sleep 100 : Wend
    echo.With .document
    echo.With .parentWindow
    echo.if Instr^(.navigator.appVersion, "MSIE 6"^) ^> 0 Then
    echo.oIE.FullScreen = True
    echo.End if
    echo.oIE.width = 400 : oIE.height = 200
    echo.oIE.left = .screen.width \ 2 - 200
    echo.oIE.top = .screen.height\ 2 - 100
    echo.End With ' ParentWindow
    echo.s = "" ^& sTitle ^& " " ^& String^(80, "."^) _
    echo.^& "bWait=true" _
    echo.^& "" ^& sTitle ^& "" _
    echo.^& "" _
    echo.^& " " ^& sTitle ^& ""
    echo.For each item in aOptions
    echo.s = s ^& " " ^& item ^& ""
    echo.Next
    echo.s = s ^& " " _
    echo.^& "OK" _
    echo.^& ""
    echo..WriteLn^(s^)
    echo.With .body
    echo..scroll="no"
    echo..style.borderStyle = "outset"
    echo..style.borderWidth = "3px"
    echo.End With ' Body
    echo..all.entries.focus
    echo.oIE.Visible = True
    echo.On Error Resume Next
    echo.While .ParentWindow.bWait
    echo.WScript.Sleep 100
    echo.if oIE.Visible Then SelectBox = "Aborted"
    echo.if Err Then Exit Function
    echo.Wend ' Wait
    echo.On Error Goto 0
    echo.With .ParentWindow.entries
    echo.SelectBox = .options^(.selectedIndex^).text
    echo.End With
    echo.End With ' document
    echo..Visible = False
    echo.End With ' IE
    echo.End Function
) > %vbs%

The output from script itself fc'd the same as you send
me be the vbs hit an error, vbs isn't my strong point, so
I'll just leave it where it is.

Just for your reference all I did was replace:

"(" with "^("
")" with "^)"
"&" with "^&"
">" with "^>"
"<" with "^<"
"|" with "^|"
"^" with "^^"
"%" with "%%"
(some of the chars weren't present).
add "echo." before each line
and put inside a code block(I also indented - optional).
Redirect the output to file.


Report •

#11
March 3, 2010 at 22:49:00
Thank you !, that chart you shown/gave me will work out nice.

again Thank you


Report •


Ask Question