Click here to Skip to main content
15,888,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<pre lang="vb"><pre>
#I am using below code in bat file, but not able to understand the logic in below code since has never worked on vb. Please help me on understanding the below lines of code

:YesNoBox
REM returns 6 = Yes, 7 = No. Type=4 = Yes/No
set YesNo=
set MsgType=4
set heading=%~2
set message=%~1
echo wscript.echo msgbox(WScript.Arguments(0),%MsgType%,WScript.Arguments(1)) >"%temp%\input.vbs"
for /f "tokens=* delims=" %%a in ('cscript //nologo "%temp%\input.vbs" "%message%" "%heading%"') do set YesNo=%%a
exit /b

:MessageBox
set heading=%~2
set message=%~1
echo msgbox WScript.Arguments(0),0,WScript.Arguments(1) >"%temp%\input.vbs"
cscript //nologo "%temp%\input.vbs" "%message%" "%heading%"
exit /b


What I have tried:

Gone through so many links on google, But not able to find the clear answers
Red about wscript and cscript but confused with variable's like

mostly confused with
REM returns 6 = Yes, 7 = No. Type=4 = Yes/No
set YesNo=
set MsgType=4
set heading=%~2
set message=%~1
echo wscript.echo msgbox(WScript.Arguments(0),%MsgType%,WScript.Arguments(1)) >"%temp%\input.vbs


and

:MessageBox
set heading=%~2
set message=%~1
echo msgbox WScript.Arguments(0),0,WScript.Arguments(1) >"%temp%\input.vbs"
cscript //nologo "%temp%\input.vbs" "%message%" "%heading%"


I need to understand each line mentioned in above code
Posted
Updated 6-May-18 1:43am

1 solution

That isn't VB.
It's DOS / CMD commands as used inside a batch file.
SET lest you manipulate Environment Variables: Batch files - The SET command[^]
REM is a comment.
ECHO displays text to the user: Help for all Windows 2000 SP 4 commands[^]
CSCRIPT runs a script file: cscript | Microsoft Docs[^] - in this case it runs a VBS file called INPUT.VBS from the TEMP folder, and passes it two Environment Variables that were supplied when teh original batch file was executed, but with any quotes around them removed.
 
Share this answer
 
Comments
shiv7 6-May-18 7:44am    
Thank you, but i am aware of the theoretical explanations about wscript or cscript.

I am confused how its working in combined to batch.

How its using the bat variables

Could you please explain the code above.
shiv7 6-May-18 7:59am    
Thanks you "it runs a VBS file called INPUT.VBS from the TEMP folder, and passes it two Environment Variables" cleared one of my doubt.

But how is this working:

REM returns 6 = Yes, 7 = No. Type=4 = Yes/No
set YesNo=
set MsgType=4
set heading=%~2
set message=%~1
echo wscript.echo msgbox(WScript.Arguments(0),%MsgType%,WScript.Arguments(1))

i am confused about %MsgType% ??, REM returns 6 = Yes, 7 = No. Type=4 = Yes/No
set YesNo=
set MsgType=4
OriginalGriff 6-May-18 8:21am    
Anything enclosed in '%' characters is an Environment variable. So since you set MsgType to 4 above that that it what %MsgType% will resolve to.

REM is still a comment!
shiv7 6-May-18 8:31am    
Thank you so much for clearing my doubts.
Few more things to ask please:

If REM is just a comment then how its working, since 6 is inside a comment.
how 6 and 7 provided inside the REM are impacting the code

if "%YesNo%"=="6" (
echo "hello"
)
OriginalGriff 6-May-18 9:04am    
It isn't - it's a comment to tell you, the person reading it what the values should do!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900