Computing.Net > Forums > Programming > Move text var to notepad (bat)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Move text var to notepad (bat)

Reply to Message Icon

Name: cholo71796
Date: June 8, 2008 at 21:30:15 Pacific
OS: Windows XP
CPU/Ram: Noidea
Product: Yes
Comment:

(This is a question about batch files)
I was wondering if there is a way to take a multi-word text variable (I'm not confused about that part) and place it in a notepad file. You know, like a survey- for example, if the program asks, "Do you like chicken? Y/N" (with the appropriate coding) and you input 'N' and the program asks you, "Why?" I would like the program to save/move the answer in a notepad file- either several answer in one notepad file, or one for every answer. Thanks in advance!



Sponsored Link
Ads by Google

Response Number 1
Name: cholo71796
Date: June 8, 2008 at 21:31:49 Pacific
Reply:

Whoops, I meant "...I would like the program to save/move the answer TO a notepad file..."


0

Response Number 2
Name: Mechanix2Go
Date: June 8, 2008 at 23:09:21 Pacific
Reply:

echo %var% >> some.txt


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 3
Name: cholo71796
Date: June 9, 2008 at 07:24:33 Pacific
Reply:

Awesome! Thanks! The only problem is that if I use the program again it will remove the first variables data in that file, right? I'll try it now.


0

Response Number 4
Name: cholo71796
Date: June 9, 2008 at 07:56:32 Pacific
Reply:

Okay, dang, it's even worse than I thought, I must be doing something wrong. I run the script:

cls
@ECHO OFF
setlocal EnableDelayedExpansion
:QUESTION
echo Do you like chicken? (Y/N)
set/p "cho=>"
if %cho%==Y goto THESTORE
if %cho%==y goto THESTORE
if %cho%==N goto SURVEY
if %cho%==n goto SURVEY

echo Input unknown.
goto QUESTION

:THESTORE
echo Good, I'll go buy some now.
PAUSE
goto end

:SURVEY
echo What? Why don't you like chicken?
set/p !var!=Type your response:
sleep 3
echo !var!>>Reason.txt

I'm probably forgetting something very simple, but I can't find out what I'm doing wrong. The program creates a new file called 'Reason' and all it says is ECHO is off.


0

Response Number 5
Name: Mechanix2Go
Date: June 9, 2008 at 12:29:37 Pacific
Reply:

this:

set/p !var!=Type your response:

should be:

set/p var=Type your response:


=====================================
If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: cholo71796
Date: June 9, 2008 at 17:09:25 Pacific
Reply:

Ach, thanks, I knew it was simple, works like a charm!
One final question: Say that I were to give my batch file to someone who is literally incapable of editing the code, I would want them to be able to put some data into a .txt which would then be imported to the .bat file. How would I go about importing the text? Or as a better alternative, would there be a way for the script to ask for the user to create their password on first use?


0

Response Number 7
Name: cholo71796
Date: June 9, 2008 at 19:25:04 Pacific
Reply:

Oh, also, is there a way to make text typed into the batch file appear as asterisks (like a password)?


0

Response Number 8
Name: Mechanix2Go
Date: June 10, 2008 at 00:32:12 Pacific
Reply:

Not that I know of.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 9
Name: cholo71796
Date: June 10, 2008 at 08:50:58 Pacific
Reply:

Okay, I doubted the last (Number 7) post, but I'm still wondering at number 6, I know there's a way to call batch files and also to send text to text files, but is there a way to call text files? I really, really hope so, but if there's not, it's okay, I guess.


0

Response Number 10
Name: Mechanix2Go
Date: June 11, 2008 at 08:02:33 Pacific
Reply:

What does it mean to 'call a text file'?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 11
Name: Shr0Om
Date: June 16, 2008 at 13:20:22 Pacific
Reply:

To ask for password on first run (possible that it works with XP only if you want to use %username%)


@echo off
if not exist "c:\%username%.pwd" (goto :CrePassword) else goto :login

:CrePassword
cls
echo Hello: %username%
echo As this is your first time here, you need to create a password.
set /p pass1=Please enter new password:
if "%pass1%" equ "" echo You cannot make an empty password! & PAUSE & goto :CrePassword
set /p pass2=Please confirm password:
if "%pass1%" neq "%pass2%" echo Passwords doesn't match. Try again! & pause & goto :CrePassword
echo %pass1% >"c:\%username%.pwd"

::Hides the file
attrib +h "c:\%username%.pwd"


:login
cls
echo LOGIN:
if exist c:\%username%.pwd set /p login=<c:\%username%.pwd
set /p pass=Enter password:
if %pass% equ %login% (goto :start) else echo Incorrect password. & pause & goto login


:Start
echo Login sucsess..
pause


0
Reply to Message Icon

log key strokes - VB, c++... Image Converter



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Move text var to notepad (bat)

VB6 - Passing 2 vars to shell() www.computing.net/answers/programming/vb6-passing-2-vars-to-shell/16274.html

batch: copy one var to another www.computing.net/answers/programming/batch-copy-one-var-to-another/9107.html

Importing Text file to Ms Access www.computing.net/answers/programming/importing-text-file-to-ms-access/4308.html