Solved

Need to get User Input and validate the input from file

Posted on 2011-02-22
7
410 Views
Last Modified: 2012-05-11
Need to get 3 digit numeric values and validate it with file.  If doesn't match, request input again.

Enter the person ID or Q to Cancel? 123
Match Found, Triggering action

Enter the person ID? 888
Match NOT Found, Please enter again or Q to Cancel.
0
Comment
Question by:sk7815
  • 4
  • 2
7 Comments
 
LVL 9

Accepted Solution

by:
Scottyworld earned 300 total points
ID: 34956675
This will automatically loop if the number is not found in the text file
 
@echo off

:TOP
set /p digits= Enter number: 

findstr /m "%digits%" "c:\support\myfile.txt"
If %errorlevel%==0 (
echo Found number
GOTO END
) else (
Echo Match not found
GOTO TOP
)
:END

Open in new window

0
 
LVL 8

Expert Comment

by:subhashchy
ID: 34956705
you should put your action stuffs after :END in the batch code provided by Scottyworld:
0
 

Author Comment

by:sk7815
ID: 34956903
Thank you, can you add 'Q" or 'q' to exit out.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:sk7815
ID: 34956921
may be '000' will work since we setting up as numeric.

@echo off

:TOP
set /p digits= Enter Store Number:

IF %digits% == 000 GOTO END

findstr /m "%digits%" "c:\junk\foo.dat"
If %errorlevel%==0 (
echo Found number
GOTO END
) else (
Echo Match not found
GOTO TOP
)
:END
0
 

Author Comment

by:sk7815
ID: 34956968
When the input value matches the string, it displays the file name.  Can we avoid it?
0
 
LVL 8

Assisted Solution

by:subhashchy
subhashchy earned 100 total points
ID: 34956986
add >nul after this line like this....

findstr /m "%digits%" "c:\support\myfile.txt" >nul
0
 

Author Closing Comment

by:sk7815
ID: 34957021
Great Team!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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