Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ask for user input with “suggestions”

64 views
Skip to first unread message

teren...@gmail.com

unread,
Apr 17, 2013, 5:16:13 AM4/17/13
to
Hi,
How can I prompt users for an answer, suggesting something they can edit? I know how to make a q&a like:

1. The sky is:
The user put the answer and:
echo For you the sky is %var%

But i want something like:

1. The sky is: Blue
echo For you the sky is Blue

But the user can change it
1. The sky is: Green
echo For you the sky is Green

Thanks

foxidrive

unread,
Apr 17, 2013, 5:42:46 AM4/17/13
to
On 17/04/2013 7:16 PM, teren...@gmail.com wrote:
> How can I prompt users for an answer, suggesting something they can edit? I know how to make a q&a like:
>
> But i want something like:
>
> 1. The sky is: Blue
> echo For you the sky is Blue
>
> But the user can change it
> 1. The sky is: Green
> echo For you the sky is Green

How do you want them to edit the text? Do you want to simply prompt for a new word and then have you
program repeat the echo statements with the new word?



--
foxi

teren...@gmail.com

unread,
Apr 17, 2013, 5:58:25 AM4/17/13
to
I'd like a question like:
The sky color: Blue
I want the use can delete the word blue with Backspace or Canc in real-temp, or confirm the word Blue. The answer will be stored in a variable

foxidrive

unread,
Apr 17, 2013, 6:10:02 AM4/17/13
to
This might be as close as you can get, with simple commands.

@echo off
set "word=Blue"
echo Press enter to leave the colour as %word% or type a new colour
set /p "word=The sky is :%word%: "
echo You chose "%word%"
pause


--
foxi

Stanley Daniel de Liver

unread,
Apr 17, 2013, 12:37:18 PM4/17/13
to
Sounds a bit like you'd want a "graphical" User Interface.

ChooseBetween "Red","Blue","Yellow"
rem displays default choice, allows csr up/dn to select other options,
enter to continue
if errorlevel 3 goto Yellow
....


NB my "ChooseBetween" is vapourware, but maybe someone's already written
one?

--
It's a money /life balance.

Todd Vargo

unread,
Apr 17, 2013, 5:25:26 PM4/17/13
to
set answer=blue
set /p answer=The sky is (default=blue):

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Indochine

unread,
Apr 18, 2013, 1:52:52 PM4/18/13
to
Probably 3rd party tools are not suitable, but for home use, Bill Stewart's
free EditVar (http://www.westmesatech.com/editv.html) is handy & allows
editing of a suggested variable value, as well as: (from the site)

It can limit the length of the typed variable.
It can mask the typed input for simple password security.
It can limit typed input to numbers only.
It offers a timeout feature (useful when a script needs to run
unattended).
It can automatically "escape" reserved shell characters in variables it
creates.
It provides useful exit codes: For example, an exit code of 4 means
that the user pressed Ctrl-C to abort.
It comes with an MS-DOS version that works in Windows 9x/Me as well as
on MS-DOS boot media.

Stanley Daniel de Liver

unread,
Apr 18, 2013, 5:49:54 PM4/18/13
to
Well I'm doing it - in asm. (waits for HK to bite!)

JJ

unread,
Apr 18, 2013, 7:06:07 PM4/18/13
to
Now I miss ANSI.SYS...

Herbert Kleebauer

unread,
Apr 19, 2013, 6:59:17 AM4/19/13
to
On 18.04.2013 23:49, Stanley Daniel de Liver wrote:

>>> I'd like a question like:
>>> The sky color: Blue
>>> I want the use can delete the word blue with Backspace or Canc in
>>> real-temp, or confirm the word Blue. The answer will be stored in a
>>> variable

> Well I'm doing it - in asm. (waits for HK to bite!)

I'm not sure what you really want to do, but I suppose
neither batch nor assembler is the right choice. But
here is a small utility (getkey.exe) which maybe
is useful in a batch version. It reads a character
from keyboard (stdin) and writes 3 bytes to stdout:
the first byte is the read character if it is a-z,
A-Z, 0-9 or BACKSPACE, in all other cases a $ is written.
Byte 2-3 are the hex values of the read character.


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

@echo off
certutil -f -decode %~f0 getkey.exe>nul

set color=blue
set length=4

set <nul /p =Which color: %color%

:loop

if "%color%"=="blue" color 9f
if "%color%"=="red" color c0
if "%color%"=="green" color a0
if "%color%"=="yellow" color e0
if "%color%"=="black" color 0f
if "%color%"=="white" color f0

for /f %%i in ('getkey.exe') do set inp=%%i
if %inp:~0,1% == $ goto :skip
if not %inp:~1,2% == 08 goto nobs

if %length% equ 0 goto :loop
set /a length=length-1
call set color=%%color:~0,%length%%%

set /p =%inp:~0,1%<nul
set <nul /p ="_"
set <nul /p =%inp:~0,1%
goto :loop

:nobs
set color=%color%%inp:~0,1%
set /a length=length+1
set <nul /p =%inp:~0,1%

:skip

if not %inp% == $0d goto :loop
echo.
echo.

del getkey.exe
goto :eof

-----BEGIN CERTIFICATE-----
TVpgAQEAAAAEAAAA//8AAGABAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAoAAAAA4fug4AtAnNIbgBTM0hTmljZSB0byBtZWV0IHNvbWVi
b2R5IHdobyBpcyBzdGlsbCB1c2luZyBET1MsDQpidXQgdGhpcyBwcm9ncmFtIHJl
cXVpcmVzIFdpbjMyLg0KJFBFAABMAQEAUHmlNgAAAAAAAAAA4AAPAQsBBQwAAgAA
AAAAAAAAAADIEAAAABAAAAAgAAAAAEAAABAAAAACAAAEAAAAAAAAAAQAAAAAAAAA
ACAAAAACAAAAAAAAAwAAAAAAEAAAEAAAAAAQAAAQAAAAAAAAEAAAAAAAAAAAAAAA
HBAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAcAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALnRleHQAAAD4AQAAABAAAAACAAAAAgAA
AAAAAAAAAAAAAAAAIAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABuEAAAfBAAAIwQAACYEAAA
pBAAALYQAAAAAAAAUhAAAAAAAAAAAAAARBAAAAAQAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAEtFUk5FTDMyLmRsbAAAbhAAAHwQAACMEAAAmBAAAKQQAAC2EAAAAAAAAAAA
RXhpdFByb2Nlc3MAAABHZXRTdGRIYW5kbGUAAAAAUmVhZEZpbGUAAAAAV3JpdGVG
aWxlAAAAR2V0Q29uc29sZU1vZGUAAAAAU2V0Q29uc29sZU1vZGUAAOirAAAAPf//
//91ArAaiMK5AgAAAMHgCMDCBIjQJA8EMDw5dgIEJ+LswcAQPAh0GjwwchQ8OXYS
PEFyDDxadgo8YXIEPHp2ArAk6BkAAADBwAjoEQAAAMHACOgJAAAA6wBQ/xUAEEAA
YDHAAwV0EUAAdQ1q9f8VBBBAAKN0EUAAagCNVCQQUmoBg8IQUlD/FQwQQAAJwHUI
agD/FQAQQACDfCQMAXXxYZDDAAAAAAAAMcBgAwXsEUAAdTdq9v8VBBBAAKPsEUAA
aPARQABQ/xUQEEAAgCXwEUAA+f818BFAAP817BFAAP8VFBBAAKHsEUAAagCNVCQQ
UmoBg8IQUlD/FQgQQAAJwHUIagD/FQAQQACDfCQMAXQIx0QkHP////9hkMMAAAAA
AAAAAAAAAAAAAAAAAAAAAA==
-----END CERTIFICATE-----

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


The source:

winmain::
bsr.l getc
cmp.l #-1,r0
bne.b _10
move.b #$1a,r0 ; EOF -> ^Z
_10: move.b r0,r1
move.l #2,r2

_30: lsl.l #8,r0
rol.b #4,r1
move.b r1,r0
and.b #$0f,r0
add.b #'0',r0
cmp.b #'9',r0
bls.b _20
add.b #'a'-'0'-10,r0
_20: dbf.l r2,_30
rol.l #16,r0

cmp.b #$08,r0 ; Backspace
beq.b _50

cmp.b #'0',r0
blo.b _40
cmp.b #'9',r0
bls.b _50

cmp.b #'A',r0
blo.b _40
cmp.b #'Z',r0
bls.b _50

cmp.b #'a',r0
blo.b _40
cmp.b #'z',r0
bls.b _50

_40: move.b #'$',r0
_50: bsr.l putc

rol.l #8,r0
bsr.l putc
rol.l #8,r0
bsr.l putc

br.b exit


Stanley Daniel de Liver

unread,
Apr 24, 2013, 9:20:54 AM4/24/13
to
On Thu, 18 Apr 2013 21:49:54 -0000, Stanley Daniel de Liver
I have something that is nearly working, in 250 bytes (excluding error
messages).
(I had trouble mixing blank delimited and quoted strings)

Spec is

Selstr defaultoption "2nd choice has spaces" 3rdchoice etc

when/if fully debugged I'll post here, if there's any interest.

Herbert Kleebauer

unread,
Apr 24, 2013, 4:19:57 PM4/24/13
to
On 24.04.2013 15:20, Stanley Daniel de Liver wrote:

> I have something that is nearly working, in 250 bytes (excluding error
> messages).

> when/if fully debugged I'll post here, if there's any interest.

If it really has only 250 bytes, then it most probably will not
work on most systems: a 32 bit exe has more than 250 bytes
and a 16 bit program can't be used in 64 bit Windows (which
is the standard since years).


jeb

unread,
Apr 25, 2013, 6:27:18 AM4/25/13
to
You could solve it with pure batch.

I solve it with a GetKey function and using the backspace character.

@echo off
setlocal EnableDelayedExpansion

call :CreateBS
set "defaultColor=Green"
<nul set /p ".=The sky color: !defaultColor!"
call :InputLine newColor defaultColor
echo(
echo You said the sky color is !newColor!
exit /b


:InputLine
set "inputText=!%~2!"
call :strlen inputText inputPosition
:InputLine_Loop
call :GetKey
if defined key (
if "!key!"=="!BS!" (
if !inputPosition! GTR 0 (
set /a inputPosition-=1
<nul set /p ".=!BS! !BS!"
set "inputText=!inputText:~0,-1!"
)
) ELSE (
set /a inputPosition+=1
<nul set /p ".=!KEY!"
set "inputText=!inputText!!key!"
)
goto :InputLine_Loop
)
set "%~1=!inputText!"
exit /b


:GetKey
set "key="
for /F "usebackq delims=" %%L in (`xcopy /L /w "%~f0" "%~f0" 2^>NUL`) do (
if not defined key set "key=%%L"
)
set "key=%key:~-1%"
exit /b

:CreateBS
For /F "delims=;" %%# in ('"Prompt;$H;&For %%_ in (1) Do Rem"') Do Set "BS=%%#"
set "BS=%BS:~-1%"
exit /b

:strLen string len -- returns the length of a string
:$source http://www.dostips.com
( SETLOCAL ENABLEDELAYEDEXPANSION
set "S=!%~1!"
set "len=0"
for /L %%A in (12,-1,0) do (
set /a "len|=1<<%%A"
for %%B in (!len!) do if "!S:~%%B,1!"=="" set /a "len&=~1<<%%A"
)
)
( ENDLOCAL & REM RETURN VALUES
IF "%~2" NEQ "" SET /a %~2=%len%+1
)
EXIT /b


jeb

Herbert Kleebauer

unread,
Apr 25, 2013, 8:06:37 AM4/25/13
to
On 25.04.2013 12:27, jeb wrote:

> You could solve it with pure batch.
>
> I solve it with a GetKey function and using the backspace character.


Well done. Just a note:

> ) ELSE (
> set /a inputPosition+=1
> <nul set /p ".=!KEY!"

In Win7 set /p doesn't output leading spaces. If you enter
a space in your code it is counted but not displayed, so if
you later use backspaces it deletes characters beyond the
start of the text. Use instead:

<nul set /p ".=.!BS!!KEY!"

Stanley Daniel de Liver

unread,
Apr 25, 2013, 2:33:46 PM4/25/13
to
On Wed, 24 Apr 2013 21:19:57 +0100, Herbert Kleebauer <kl...@unibwm.de>
wrote:
Yes, sorry, it's 16bit asm.

Dr J R Stockton

unread,
Apr 25, 2013, 6:02:07 PM4/25/13
to
In alt.msdos.batch.nt message <kl9eqa$k87$1...@speranza.aioe.org>, Wed, 24
Apr 2013 22:19:57, Herbert Kleebauer <kl...@unibwm.de> posted:
It can be if the XP subsystem is loaded and run.

--
(c) John Stockton, nr London UK. Mail, see homepage. DOS 3.3, 6.20; WinXP, 7.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

Todd Vargo

unread,
Apr 25, 2013, 11:04:58 PM4/25/13
to
On 4/25/2013 6:02 PM, Dr J R Stockton wrote:
> In alt.msdos.batch.nt message <kl9eqa$k87$1...@speranza.aioe.org>, Wed, 24
> Apr 2013 22:19:57, Herbert Kleebauer <kl...@unibwm.de> posted:
>
>> On 24.04.2013 15:20, Stanley Daniel de Liver wrote:
>>
>>> I have something that is nearly working, in 250 bytes (excluding error
>>> messages).
>>
>>> when/if fully debugged I'll post here, if there's any interest.
>>
>> If it really has only 250 bytes, then it most probably will not
>> work on most systems: a 32 bit exe has more than 250 bytes
>> and a 16 bit program can't be used in 64 bit Windows (which
>> is the standard since years).
>
>
> It can be if the XP subsystem is loaded and run.

It would make more sense to use a WSH InputBox.

I notice the OP has not posted back in a week. Most likely not
interested in the solutions offered or no longer interested.
0 new messages