News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Visual Basic style input box

Started by Vortex, March 10, 2012, 10:57:22 AM

Previous topic - Next topic

Vortex

Here is a simple input box implementation to support batch files. No any dependence to the Visual Basic scripting engine.

InputBox.exe <message to display> <caption> <x-coordinate> <y-coordinate>

The string !!##*++ is returned by InputBox if the user hits the Cancel button. Not the best solution but a practical and easy one.

The Msgbox tool is based on the MessageBox API function.

Examples :


SET MB_ICONEXCLAMATION=48
SET MB_ICONINFORMATION=64
SET MB_ICONERROR=16

:start

SET choice=

FOR /F "tokens=1 delims=" %%A in ('InputBox.exe "Type yes to continue, no to exit" "Hello" 100 100') do SET choice=%%A

IF "%choice%" == "" (
Msgbox "Please type yes or no" Error %MB_ICONERROR%
GOTO :start
    )


IF "%choice%" == "!!##*++" (
Msgbox "You clicked cancel" Inputbox %MB_ICONEXCLAMATION%
GOTO :start
   )

IF "%choice%" == "yes" (
Msgbox "You selected %choice%" "Your choice" %MB_ICONINFORMATION%
GOTO :EOF
       )

IF "%choice%" == "no" GOTO :EOF

GOTO start



@SET MB_YESNOCANCEL=3
@SET MB_ICONINFORMATION=64
@SET /A ICON_TYPE="%MB_ICONINFORMATION% | %MB_YESNOCANCEL%"

@SET YES=6
@SET NO=7
@SET CANCEL=2

Msgbox "Click yes, no or cancel" "Message box" %ICON_TYPE%

@SET e=%ERRORLEVEL%

@IF %e% == %NO% echo You clicked no
@IF %e% == %YES% echo You clicked yes
@IF %e% == %CANCEL% echo You clicked cancel

Pause

jj2007

Looks nice. Hint: Use the test.bat file to see what it does :bg

Minor point: My old-fashioned unzipper was not happy with the format of the attachment - WinZip max non-portable?

Vortex

Hi Jochen,

I am using 7-Zip to unpack .zip archives. It works on the attached file too. The batch file test.bat demonstrates an example looking a bit primitive but it does the job to explain the usage of the tool. I am intending to use the registry to store the result string of the input box.

jj2007

Hi Erol,
My unzipper uses Christian Ghisler's Unzip.dll dated 5 November 1999 - so that is no surprise :wink

Vortex

The string received by the input box is now stored in the registry.  I coded an additional tool named ReadInputBox to get easily the string.

An entry named InputBoxString is created in HKEY_CURRENT_USER\Environment


SET MB_ICONEXCLAMATION=48
SET MB_ICONINFORMATION=64
SET MB_ICONERROR=16

:start

SET choice=

InputBox.exe "Type yes to continue, no to exit" "Hello" 100 100

SET e=%ERRORLEVEL%

IF %e% == 0      (
  Msgbox "You clicked cancel" Inputbox %MB_ICONEXCLAMATION%
  GOTO :start
)

FOR /F "delims=" %%A in ('ReadInputBox.exe') do SET choice=%%A

IF "%choice%" == "" (
Msgbox "Please type yes or no" Error %MB_ICONERROR%
GOTO :start
    )


IF "%choice%" == "yes" (
Msgbox "You selected %choice%" "Your choice" %MB_ICONINFORMATION%
GOTO :EOF
       )

IF "%choice%" == "no" GOTO :EOF

GOTO start

Vortex

- Fixed a bug in ReadInputBox - RegCloseKey was missing to close an open key
- Added the tool CaseConv to do uppercase \ lowercase string convertions.


SET MB_ICONINFORMATION=64

InputBox.exe "Type a message to be converted to uppercase" "Hello" 100 100

SET e=%ERRORLEVEL%

IF %e% == 0 GOTO :EOF

FOR /F "delims=" %%A in ('ReadInputBox.exe') do SET str=%%A

IF "%str%" == "" GOTO :EOF

@REM CaseConv.exe "%str%" -l converts to lowercase

FOR /F "delims=" %%A in ('CaseConv.exe "%str%" -u') do SET str2=%%A

Msgbox "%str2%" "Uppercase" %MB_ICONINFORMATION%

Pause