batch file probs


(J35t3r) #1

Hi everyone, long time reader newbie poster. :moo:
First of all great job splashdamage on a awesome game and site.
The state of online gaming today is a lot more enjoyable with “team mates” doing an objective, rarther than a group of people with the same goal.

Ok now after reading this forum for quite awhile I’ve learnt there are some very smart people floating round here.
So im chasing a little help with a batch file, Ive never written one before so excuse me if I’ve missed a basic step.

It was to be a simple file that, when run would display a list of options with a corresponding number. All was fine untill I reached option 10, putting in 10 (one zero) would relaunch option 1.

heres the offending part of the script,

@echo off
:start
cls
set /p userinp=choose a number(1-85):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto 1
if "%userinp%"=="2" goto 2
if "%userinp%"=="3" goto 3
if "%userinp%"=="4" goto 4
if "%userinp%"=="5" goto 5
if "%userinp%"=="6" goto 6
if "%userinp%"=="7" goto 7
if "%userinp%"=="8" goto 8
if "%userinp%"=="9" goto 9
if "%userinp%"=="10" goto 10
if "%userinp%"=="11" goto 11
if "%userinp%"=="12" goto 12

Now I have tried the obvious addition of a 0 infront of all numbers 1-9 but no luck

Any ideas people?
Im not gonna be to happy if its only able to go up to 9, I got 85 doh.
Thanks in advance for any help & if this is too offtopic then please remove.


(Sauron|EFG) #2

Remove “:~0,1”?


(nUllSkillZ) #3

I haven’t written batch’s myself.

But first thought I have had:
Split it up again and goto a new menu.
So if you first select 0 a second menu opens where you have a choice from 0 to 9.
If you select 1 a second menu opens where you have a choice from 0 to 9.

So you would be able to have 100 choices.


(Gimpsta) #4

This is done best using Windows scripting and batch.
You could do it all in Windows scripting but we will just get the key input and then use batch.

[b]
Step 1 - Create the VBS file

[/b]
Open notepad
Paste the follwing in (text between the —snip— )

-------------------------snip-------------------------

strUserIn = InputBox(“Enter Data”)
Set fs = CreateObject(“Scripting.FileSystemObject”)
strFileName = fs.BuildPath(Wscript.ScriptFullName & “…”, “~userin.bat”)
strFileName = fs.GetAbsolutePathName(strFileName)
Set ts = fs.OpenTextFile(strFileName, 2, True)
ts.WriteLine “set userin=” & strUserIn
ts.Close

-------------------------snip-------------------------

Select File, Save As
Browse to the directory where you want to store the file
Select file type as . (i.e. not text)
Enter the filename as userin.vbs

You should now have a file called userin.vbs

[b]
Step 2 - Create a batch file to call the VBS

[/b]
An example of what your batch file may look like is:

start /w wscript.exe userin.vbs
call ~userin.bat
del ~userin.bat

goto %USERIN%

:1
echo You entered 1
goto :end

:10
echo You entered 10
goto :end

:end

Let me know if you have any problems.

Regards,

:smiley:


(J35t3r) #5

Well thanks go out to “Sauron|EFG, nUllSkillZ & Gimpsta” for their help :drink: .

My plan of attack was the same as “nUllSkillZ’s” if I couldnt get it to work, however the notes that “Gimpsta” provided saved me a whole lot of editing time.

It took me awhile to get it to work only because I kept adding complex commands to the userin.vbs window eg %userinp% 1, call 1, load 1 when all I had to do was type “1” (allways keep it simple stupid) :banghead: .

So I now have my own (albeit small & simple) program running that does things my way & was written by myself (with some very handy help).

I am still left wondering if this can be done purely in dos :???:.

All in all I’m very happy with what started out as a “hey I wonder if I can do this” type situation & has turned itself into something I have an interest in learning more about :clap: .


(Sauron|EFG) #6

My solution works in the w2k command prompt, but I can’t swear it works in “real” MS-DOS. :slight_smile: