Jump to content

Recommended Posts

Posted

First of all, my best wishes to you all this festive season.

 

I have a question on how to perform a line feed/carriage return for a vbs inputbox.

I have tried just about every combination of vbCr vbLf etc plus other suggested "code" but all to no avail.

Googling information on the inputbox parameters it says that the vbxx command should be used.

 

I have managed to create the menu satisfactorily by merely spacing the text out (which I don't think shows up here) so this is not a desperate situation, merely a question as to why the "vbxx" codes don't work,

 

For your info, machine running Vista SP2 and original code sample obtained via Google ... I did not know how to go about it myself.

 

Code is:

 

@echo off

SETLOCAL

 

SET _prompt=%1

 

::Create the VBS script with an echo statement:

ECHO Wscript.Echo Inputbox("Please select 1. Email backup 2. Document backup 3. Offsite backup 4. System File check %_prompt%","Utilities Menu")>%TEMP%\~input.vbs

 

:s_GetInput

:: Run the vbScript and save the output

FOR /f "delims=/" %%G IN ('cscript //nologo %TEMP%\~input.vbs') DO set _string=%%G

 

:: Delete the VBS file

DEL %TEMP%\~input.vbs

 

if '%_string%'=='1' goto 1

if '%_string%'=='2' goto 2

if '%_string%'=='3' goto 3

if '%_string%'=='4' goto 4

if '%_string%'=='' goto end

:1

start "" "E:\My Documents\Downloaded\Programs\Securityemail.exe"

goto end

:2

start "" "E:\My Documents\Downloaded\Programs\securitycopy.exe"

goto end

:3

start "" "E:\My Documents\Downloaded\Programs\SecureOffsite.exe"

goto end

:4

start "" "E:\My Documents\Downloaded\Programs\SFCProc.exe"

goto end

:end

 

You will see where the new line code would be tidier !!

 

However output using the line spacing produces the required result.

 

menu.jpg

 

It would be interesting to know how to code these line feeds in this situation.

 

Kind regards

menu.jpg

  • 1 month later...
Posted (edited)

This is due to mixing BAT commands and VBS, the ECHO command on your line 7 (Which creates the VBS script) gets broken as soon as it sees the quotation marks which makes & vbCrLF break. using the ^ character before every quotation and & escapes the character allowing the ECHO command to pipe it into the VBS file correctly.

The below is what you are looking for.

 

@echo off

SETLOCAL

SET _prompt=%1

::Create the VBS script with an echo statement:

ECHO Wscript.Echo Inputbox(^"Please select^" ^& vbCrLf ^& ^"1. Email backup^"^& vbCrLf ^& ^"2. Document backup^"^& vbCrLf ^& ^"3. Offsite backup^"^& vbCrLf ^& ^"4. System File check %_prompt%^",^"Utilities Menu^")>%TEMP%\~input.vbs

:s_GetInput

:: Run the vbScript and save the output

FOR /f "delims=/" %%G IN ('cscript //nologo %TEMP%\~input.vbs') DO set _string=%%G

:: Delete the VBS file

DEL %TEMP%\~input.vbs

if '%_string%'=='1' goto 1

if '%_string%'=='2' goto 2

if '%_string%'=='3' goto 3

if '%_string%'=='4' goto 4

if '%_string%'=='' goto end

:1

start "" "E:\My Documents\Downloaded\Programs\Securityemail.exe"

goto end

:2

start "" "E:\My Documents\Downloaded\Programs\securitycopy.exe"

goto end

:3

start "" "E:\My Documents\Downloaded\Programs\SecureOffsite.exe"

goto end

:4

start "" "E:\My Documents\Downloaded\Programs\SFCProc.exe"

goto end

 

:end

 

 

 

 

Let me know if this helps

Thanks

Edited by pfl
  • Thanks 1
Posted

Good morning and many thanks for your resolution, it works very well and certainly cleans up the source code.

Also I can now see where I was struggling.

I have 3 such menus so can now roll out the amendment easily.

As you may have seen, I have been attempting to rebuild these in GUI Powershell, which I have never looked at until now, but unfortunately have met with possible compatitbility problems between the tutorial examples found on the net and my version of Powershell V.1 ... runs in ISE but fails in Powershell.

Anyway that is another story and so for now, with your help, will continue using VBS.

 

Many thanks again and have a good day.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...