Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I convert a DOS batch file into a VB Script?

Posted on 2008-06-16
4
Medium Priority
?
809 Views
Last Modified: 2010-04-21
I would like to be able convert a DOS batch file to a VB Script. This is the batch file I have:
@echo off

:BEG
cls
echo.
echo.
set /p snumber= Enter the song number:
echo.

:CONFIRMATION
set /p answer= You entered song %snumber%. Correct (Y,N)?
if /i %answer% EQU Y goto :PLAY
if /i %answer% EQU N goto :BEG
goto :CONFIRMATION

:PLAY
start C:\MP3\HA%snumber%.mp3

:END
0
Comment
Question by:giloliveira
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21801242

dim wsh, chosen
chosen=false
while not chosen
	i=InputBox("Enter the song number:", "Choose song")
	if MsgBox("You chose song " & i & vbcrlf & "Is this correct?",4,"Confirm")=6 then
		' User confirmed ok
		chosen=true
		' Play song
		set wsh = CreateObject("WScript.Shell")
		wsh.run("""c:\MP3\HA" & i & ".mp3""")
		set wsh=nothing
	end if
wend
		
	

Open in new window

0
 

Author Comment

by:giloliveira
ID: 21804916
This almost works. The problem I am finding with this script is that when the InputBox opens, if I click on the Cancel button, the scrip will continue to run instead of closing. How can I make the script to close if I select the Cancel button.
Also, is it possible to have the number entered on the first box to be shown in bold on the confirmation box?
0
 
LVL 24

Accepted Solution

by:
purplepomegranite earned 2000 total points
ID: 21805184
The attached let's you cancel from the inputbox.

It is not possible to make text bold in the standard VBS messagebox, so the number can't be emboldened.
dim wsh, chosen
chosen=false
i=1
while not chosen and (i<>"")
	i=InputBox("Enter the song number:", "Choose song")
	if (i<>"") then
		if MsgBox("You chose song " & i & vbcrlf & "Is this correct?",4,"Confirm")=6 then
			' User confirmed ok
			chosen=true
			' Play song
			set wsh = CreateObject("WScript.Shell")
			wsh.run("""c:\MP3\HA" & i & ".mp3""")
			set wsh=nothing
		end if
	end if
wend

Open in new window

0
 

Author Closing Comment

by:giloliveira
ID: 31467867
Thanks for your assistance. It works exactly as I want it to work.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question