1.

Solve : Quality control or Validation for a commandline entry?

Answer»

here's a vbscript.
Code: [Select]Option Explicit
Dim objArgs,SSNumber
Set objArgs = WScript.Arguments
SSNumber=objArgs(0)
If Len(SSNumber)>9 Then
WScript.Echo "SSN number more than 9 chars"
WScript.Quit(1)
ElseIf IsNumeric(SSNumber) = False Then
WScript.Echo "SSN number contains alphabets"
WScript.Quit(2)
ElseIf Mid(SSNumber,4,2) = "00" Then
WScript.Echo "SSN 4th/5th digits are 00"
WScript.Quit(3)
Else
WScript.Quit(0)
End If
how to use in your batch:
Code: [Select]@echo off
#enter SSN number .....
cscript /nologo myscript.vbs 123456789
if %errorlevel% EQU 0
echo "Good SSN"
...
...
@echo off

set /a n=
set /a x=0

:start
cls

choice /C 1234567890 /N /M "%n%"

if %errorlevel%==10 (
set n=%n%0
) else (
set n=%n%%errorlevel%
)

set /a x+=1
if %x%==9 goto end

goto start

:end
cls

echo Number is: %n%
echo.
pause >NUL

This simply sets two variables, the number n, and a loop counter, x.
You are then presented with the value of n and a choice prompt, upon typing a number and only a number it will be added to the end of n. (Or n will become it if it was first press).
One will be added to X.
Repeat until looped 9 times, and length of n is 9.
Output entered number.
Contrex,
Sorry for taking so long to respond...

I finally got a chance to integrate the length portion into my code, and once again it worked beautifully.... THANK you so vary much...

I THOUGHT I could get by the testers without it, but they started putting in all kinds of stuff (mostly using a blank space), and the program was failing.... but thanks to you, things look golden!!

at least until the testers get it again...


I have another issue coming soon, that If I cannot find by searching these boards, I may create a new topic....

The issue is creating a UNIQUE file name-- every time i run my program I have to give it a file name to save as, so I just use the SSN which is okay, until I have to ZIP these zip files....

basically at the end, i zip five zip files that have been named SSN.zip... right now i'm naming the final zip file "master-lastSSN.zip".... i got a feeling the testers are gonna bust me on this...

i've seen some code where they use a "timestamp" to create a name... you have any ideas??

Quote from: cornbread on July 25, 2007, 09:17:36 AM

i've seen some code where they use a "timestamp" to create a name... you have any ideas??

Some of this might be useful...

Quote
@echo off

echo today is %date% and the time now is %time%
echo.

REM slice up date system variable
FOR /f "tokens=1,2,3 delims=/-" %%a in ("%date%") do (

REM Locale dependent - EUROPE dates are dd/mm/yyyy
REM you may need to swap these
set day=%%a
set month=%%b

set year=%%c
)

set yy=%year:~2,2%
set y=%year:~3,1%

REM slice up time system variable
REM euro time format is 24 hr ("MILITARY")
REM local xp %time% format is hh:mm:ss.cs (cs=centiseconds)
REM if you have am/pm etc that may break this code, I'm not sure...
FOR /f "tokens=1,2,3,4 delims=:." %%a in ("%time%") do (
set hour=%%a
set minute=%%b
set second=%%c
set csecond=%%d
)

echo day %day%
echo month %month%
echo 4 fig year %year%
echo 2 fig year %yy%
echo 1 fig year %y%
echo.
echo hour %hour%
echo minute %minute%
echo second %second%
echo centisecond %csecond%

echo.

REM some ideas...

set filename1=%year%%month%%day%-%hour%%minute%%second%%csecond%.rar
set filename2=%yy%%month%%day%-%hour%%minute%%second%.rar
set filename3=%month%%day%-%hour%%minute%%second%.rar
set filename4=%y%%month%%day%%hour%%minute%%second%%csecond%.rar

echo %filename1%
echo %filename2%
echo %filename3%
echo %filename4%

Quote
today is 25/07/2007 and the time now is 18:19:16.71

day 25
month 07
4 fig year 2007
2 fig year 07
1 fig year 7

hour 18
minute 19
second 16
centisecond 71

20070725-18191671.rar
070725-181916.rar
0725-181916.rar
7072518191671.rar

The XP system time variable %time% has a resolution of 1/100th of a second which ought to guarantee fairly unique timestamps. If there is a danger of duplication you could add a delay by eg pinging a nonexistent ip address with a 5 (approx) millisecond timeout

Quote
echo %time%
PING 1.1.1.1 -n 1 -w 5 >NUL
echo %time%

Quote
18:38:23.23
18:38:23.62

Contrex,

Thanks again for your help on this project.

The testers found two errors. I tried to fix them but I'm having trouble.

Error 1: for some weird reason, the program accepts 22233355& as a valid nine digit, numbers only entry. or any other 8 digit + the "&".... all other 8 digit + other symbol entry is rejected (22233355*, 22233355!, etc)

Error 2: the program is supposed to zip all the files with the same SSN into one zip file, and the user can zip up to five SSN which then gets zipped into a master zip file... the error the testers found is that if the user attempts to zip the same SSN into one bundle, I increase the count, even though, the number of SSNs does not increase.... basically, i need a way to keep track of the SSNs in the program...

is there a source where i can get some quick basics on the power of DOS programming... i'm more familiar with more structured programming languages, with arrays and stuff..
ok, i fix error two.... with a little thought, i figured out to move the zipped files to a separate directory, then if it exist, do not count or zip again... doh! sometimes you can't see the forrest for the trees..

i'm still perplexed by error number 1.... i know & and * are wild cards in DOS, but why is & considered a valid number but * is not??

The ampersand, "&" is what is called a "poison character". It breaks code that works with all others. I am working on a solution.

Are you allowed to use a DOS executable? I can easily write a compiled app in FreeBASIC which can be called from a batch file and which would receive user input and check for ANY non-numeric character. The FreeBASIC COMPILER is free and I can give the source code and links to the compiler and IDE so you can modify it and experiment. FreeBASIC is like QBasic in syntax, but it is not a 1980s product.


contrex,

thanks for all your help..... i appreciate your offer of a different solution, but I don't want to go down that road, yet....

i ask the the user to put in an SSN, and we catch 99.9 percent of the possible errors, so if they put in an ampersand, they deserve what they get.... (what are the odds that someone is gonna hold down the Shift key, let alone the Shift key and the number 7)

if you can point me to a link that shows that & is a "poison character", i can probably justify the program we have

Quote from: cornbread on August 02, 2007, 11:27:56 AM
if you can point me to a link that shows that & is a "poison character", i can probably justify the program we have

Well, the first few of these ought to do it...

http://www.google.co.uk/search?source=ig&hl=en&q=ampersand+poison+character&btnG=Google+Search&meta=

let me know if you want more/others
perfect.... thanks (i owe you part of my pay!!)

if its any consolation, the work i'm doing (with your help), is for disable militaryQuote from: cornbread on August 02, 2007, 12:26:10 PM
if its any consolation, the work i'm doing (with your help), is for disable military

Glad to help.

some more

http://www.google.co.uk/search?num=100&hl=en&safe=off&q=batch+poison+characters&btnG=Search&meta=





Discussion

No Comment Found