Need help with vbscript dialog (Text field + buttons)

Hi,

I can't get the following button to work as it should.

This is how I want it to behave :

  • IF there's something in the text field, then do a specific action
  • IF the textfield is not filled and a button is clicked, then do the specific button action.

For some reason the If...Then....Else function does not see if there was something in the textfield or not.

Anyone can give me a helping hand on why it doesn't work please ? (Or a working script that does the trick ?)

Here's the script for the button :

'@script vbscript 
' Create a Dialog object. You can also obtain dialog objects from the Lister, Tab, Func and Command objects.
Set dlg = DOpus.Dlg
 
' Initialise the object to display a simple message with three buttons.
dlg.message = "Select Stream Link to Play."
dlg.Window = DOpus.Listers(0)
dlg.title = "Dialog Title"
dlg.max = 128  ' enable the text field
dlg.buttons = "1 = realkraftyy (Twitch)|2 = Sacriel (Twitch)|3 = JackFrags (Twitch)|4 = Valientthor89 (Twitch)|5 = boogie2988 (Twitch)|6 = Vikkstar123 (Youtube)|7 = WeAreChange (Youtube)|8 = The Joy of Coding (Twitch)|9 = The Thinkery (Youtube)|10 = Bob Ross (Twitch)|Cancel"
dlg.defid = 0
ret = dlg.Show

Dim shell

' Show the dialog and print the result to the script log
If dlg.input <> Null Then
 Set shell = CreateObject("WScript.Shell")
 shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" <contents of input field here> best"
DOpus.Output "The string you entered was " & dlg.input
Else
DOpus.Output "Text field remained empty"
DOpus.Output "Dialog.Show returned " & ret

' realkraftyy (Twitch)
If ret = "1" Then
' Dim shell
 Set shell = CreateObject("WScript.Shell")
 shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" twitch.tv/realkraftyy best"
End If

' Sacriel (Twitch)
If ret = "2" Then
' Dim shell
 Set shell = CreateObject("WScript.Shell")
 shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" twitch.tv/Sacriel best"
End If

' JackFrags (Twitch)
If ret = "3" Then
' Dim shell
 Set shell = CreateObject("WScript.Shell")
 shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" twitch.tv/jackfrags best"
End If

' Valientthor89 (Twitch)
If ret = "4" Then
' Dim shell
 Set shell = CreateObject("Wscript.Shell")
 shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" twitch.tv/valientthorr89 best"
End If

' boogie2988 (Twitch)
If ret = "5" Then
' Dim shell
 Set shell = CreateObject("Wscript.Shell")
 shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" twitch.tv/boogie2988 best"
End If

' Vikkstar123 (Youtube)
If ret = "6" Then
' Dim shell
 Set shell = CreateObject("Wscript.Shell")
 shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" youtube.com/channel/UCvwgF_0NOZe2vN4Q3g1bY-A best"
End If

' WeAreChange (Youtube) 
If ret = "7" Then
' Dim shell
 Set shell = CreateObject("Wscript.Shell")
 shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" youtube.com/channel/UChwwoeOZ3EJPobW83dgQfAg best"
End If

' The Joy of Coding (Twitch)
If ret = "8" Then
' Dim shell
 Set shell = CreateObject("WScript.Shell")
shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" twitch.tv/mikeconley_dot_ca best"
End If

' The Thinkery (Youtube)
If ret = "9" Then
' Dim shell
 Set shell = CreateObject("WScript.Shell")
 shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" youtube.com/channel/UCpiCH7qvGVlzMOqy3dncA5Q best"
End If

' The Thinkery (Youtube)
If ret = "10" Then
' Dim shell
 Set shell = CreateObject("WScript.Shell")
 shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" twitch.tv/bobross best"
End If
End If

Place ret = dlg.Show before the If-Then-Else.

I just did lxp, the result is the same.
If I enter something in the textfield and finish off with an ENTER, I only get "Dialog.Show returned 0" in the Output window and the dialog closes, taking it as a button 0 has been pressed, it just doesn't care if there's something in the input field or not.

Your dialog needs an 'OK' button. Entering a string and hitting Return will be the same as clicking the 'Cancel' button. If you place it before 'Cancel', set dlg.defid = 11.

The If condition is probably better like this:

If dlg.input <> "" Then

Thank you so much lxp, at least I could get it to work (close to) how I wanted.
The last problem I have is properly constructing the shell.run line, I'm able to construct a working pure static line, like this works perfect :

shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" twitch.tv/boogie2988 best"

The problem I keep having is properly "glueing together" the run argument with the contents from dlg.input field, like this one doesn't work at all :

Shell.run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" & dlg.Input & "" best"""

Streamlink is properly started but the window closes too rapidly in order to see what the error is, again after parsing the instruction, so I'm unable to see the argument is being passed on.

Should be like:

shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" <DIALOG INPUT HERE> "" best"""

That's the line I have, but it doesn't seem to parse the dlg.input correctly.

shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe"" & dlg.Input & "" best"""

Oh yeah, those pesky quotes...

This would be my attempt:

shell.Run """C:\Program Files (x86)\Streamlink\Releases\Streamlink.exe""" & " " & dlg.Input & " " &  """ best"""

Tip: Use CHR(34) instead of fiddling with the quoted quotes, like so:

DOpus.Output CHR(34) & "Test" & CHR(34)

to get "Test".

BINGO!

Thank you so much for helping me all the way through, lxp ! :slight_smile: