Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am new to programming and would like help.
I am trying to create a batch file so that a user input is yes or no. An .ini file would be written based on the answer supplied.Batch file
q do you want to use the new data?
y/n
if yes then write data.ini with the following
[data]
DatabaseType=ASA
DBMS=ODBC
LogId=
LogPassword=
DbParm=DisableBind=1,DelimitIdentifier='No'
DSN=ABC Serverif no then write data.ini with the following
[data]
DatabaseType=ASA
DBMS=ODBC
LogId=
LogPassword=
DbParm=DisableBind=1,DelimitIdentifier='No'
DSN=DEF ServerAny recommendations would be great. Thanks

test and make sure it gives you what you need.
@echo off
:again
echo do you want to use the new data?
echo type y or n
set /p choice=
if [%choice%]==[] goto again
if [%choice%]==[y] goto 1
if [%choice%]==[n] goto 2
goto again:1
echo [data]>inifile.ini
echo DatabaseType=ASA>>inifile.ini
echo DBMS=ODBC>>inifile.ini
echo LogId=>>inifile.ini
echo LogPassword=>>inifile.ini
echo DbParm=DisableBind=1,DelimitIdentifier='No'>>inifile.ini
echo DSN=ABC Server>>inifile.ini
goto end:2
echo [data]>inifile.ini
echo DatabaseType=ASA>>inifile.ini
echo DBMS=ODBC>>inifile.ini
echo LogId=>>inifile.ini
echo LogPassword=>>inifile.ini
echo DbParm=DisableBind=1,DelimitIdentifier='No'>>inifile.ini
echo DSN=DEF Server>>inifile.ini
goto end:end
-------------
well there is a batch file to do it. just copy and paste and your set.
now for how it works if you want to know.
:again
echo do you want to use the new data?
echo type y or n
set /p choice=
if [%choice%]==[] goto again
if [%choice%]==[y] goto 1
if [%choice%]==[n] goto 2
goto again
that asks the user the question then the if statements check if it was a y or n then goes to the section for the selected answer:1
echo [data]>inifile.ini
echo DatabaseType=ASA>>inifile.ini
echo DBMS=ODBC>>inifile.ini
echo LogId=>>inifile.ini
echo LogPassword=>>inifile.ini
echo DbParm=DisableBind=1,DelimitIdentifier='No'>>inifile.ini
echo DSN=ABC Server>>inifile.ini
goto endThe :1 is the label the goto looks for. Then echo line is echoed into the file because > is used. if one > is used it will over write the file, but if two > are used it adds to the file. So the first time the file is written over but every other line is added. The goto end goes to the label at the end of the program so the other choices are not ran. The same thing happens for the second choice.
need more help just ask. later

You can streamline it a bit.
=============================================
@echo off > data.ini & setLocal EnableDelayedExpansionset /p T=do you want to use the new data?
goto !T!:Y
>> data.ini echo [data]
>> data.ini echo DatabaseType=ASA
>> data.ini echo DBMS=ODBC
>> data.ini echo LogId=
>> data.ini echo LogPassword=
>> data.ini echo DbParm=DisableBind=1,DelimitIdentifier='No'
>> data.ini echo DSN=ABC Servergoto :eof
:N
>> data.ini echo [data]
>> data.ini echo DatabaseType=ASA
>> data.ini echo DBMS=ODBC
>> data.ini echo LogId=
>> data.ini echo LogPassword=
>> data.ini echo DbParm=DisableBind=1,DelimitIdentifier='No'
>> data.ini echo DSN=DEF Server
=====================================
If at first you don't succeed, you're about average.M2

Mechanix2Go: You can streamline it a bit.
I can play that game, too!
@echo off set dsn=ABC Server set /p T=do you want to use the new data? if /i "%T%"=="Y" set dsn=DEF Server >data.ini ( echo [data] echo DatabaseType=ASA echo DBMS=ODBCA echo LogId= echo LogPassword= echo DbParm=DisableBind=1,DelimitIdentifier='No' echo DSN=%dsn%)
I'll play nice now...

Pretty slick, Slick.
=====================================
If at first you don't succeed, you're about average.M2

![]() |
Change wallpaper with bat...
|
How to fix regedit home p...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |