Computer Hope
Microsoft => Microsoft DOS => Topic started by: tendude on July 14, 2013, 11:11:09 AM
-
hi...
i need help
i try create grammar batch...
batch can load text from file.txt
i use this code and its load fine
-------------
@echo off
setlocal disableDelayedExpansion
echo ---
type file.txt
echo ---
-------------
the question is...how can i manipulate the text?
text -------------------------
I washed the car yesterday.
The dog ate my homework.
John studies English and French.
Lucy enjoys listening to music.
-------------------------------
how to apart word one by one so i can set the work as
(pronoun) (noun) (verb) (adverb) (adjective) (preposition) (subject) (object)
exp-
(pronoun) (verb) (noun) (adverb)
I washed the car yesterday
thank you...i bad in english...i hope i can easily understand and learn better went this grammar batch are complete.
ty
-
.
-
if i enter text
for exp-
"I washed the car yesterday."
how can i set each word one by one?
" I " set to
1 (pronoun)
2 (noun)
3 (verb)
4 (adverb)
5 (adjective)
6 (preposition)
7 (subject)
8 (object)
so i can chose by enter the number
-
This is a very complicated problem. It would probably be too complex for batch. You could always make a list of words and their parts of speech and then loop through the lists until you find your word, then assign it. This would take a long time, and ultimately, due to the complexity of English, turn out wrong answers most of the time. You may want to look into a different way to learn grammar. I would recommend reading lots of books.
-
dont worry about that...
i want know how to get the word, one by one from the text.
"I washed the car yesterday."
I
washed
the
car
yesterday
i just know get letter by letter
for exp-
-----------------------------------------------------------
@echo off
:loop
cls
set /p input=enter/paste document here :
cls
REM Encode
set output=
set output2=
rem loop through the string
set j=0
set a=0
:Loop1
call set inchar=%%input:~%j%,1%%
if "%inchar%"=="" goto ExitLoop1
IF "%inchar%"=="A" set outchar=a
IF "%inchar%"=="B" set outchar=b
IF "%inchar%"=="C" set outchar=c
IF "%inchar%"=="D" set outchar=d
IF "%inchar%"=="E" set outchar=e
------------------------------------------------------
any suggestion?
-
for /f "tokens=* delims= " %%A in ("TEXT") do (
CODE
)
each word will be represented by %%A , %%B , %%C , %%D ...
OR
you can use:
for %%A in (TEXT) do (
CODE
)
it will then run the code for each word, using %%A as the variable.
EDIT:
If you plan on altering any veriables within the for loop, you need to use 'setlocal EnableDelayedExpansion' and refer to them as !var! instead of %var%.
-
for /f "tokens=* delims= " %%A in ("TEXT") do (
CODE
)
each word will be represented by %%A , %%B , %%C , %%D ...
@echo off
setlocal=enabledelayedexpansion
set /p input=enter/paste document here :
(I washed the car yesterday)
:loop
for /f "tokens=* delims= " %%A in input do (
if exist "%%A" goto exist
if not exist "%%A" goto notexist
)
:exist
echo "%%A" >> "%%A".txt
(safe in same name)
exp-
washed save in washed.txt
:notexist
echo "%%A" >> word.txt
for %%A in (TEXT) do (
CODE
)
it will then run the code for each word, using %%A as the variable.
@echo off
setlocal=enabledelayedexpansion
set /p input=enter/paste document here :
(I washed the car yesterday)
:loop
for %%A in input do (
if exist "%%A" goto exist
if not exist "%%A" goto notexist
)
:exist
echo "%%A" >> "%%A".txt
(safe in same name)
exp-
washed save in washed.txt
:notexist
echo "%%A" >> word.txt
like this?
-
...
@echo off
setlocal=enabledelayedexpansion
set /p input=enter/paste document here :
(I washed the car yesterday)
:loop
for %%A in input do (
if exist "%%A" goto exist
if not exist "%%A" goto notexist
)
:exist
echo "%%A" >> "%%A".txt
(safe in same name)
exp-
washed save in washed.txt
:notexist
echo "%%A" >> word.txt
like this?
@echo off
setlocal=enabledelayedexpansion
set /p input=enter/paste document here :
(I washed the car yesterday)
:loop
for /f "delims=" %%A in ("%input%") do (
for %%B in (%%A) do (
if exist "%%A" goto exist
if not exist "%%A" goto notexist
)
)
Don't quite understand what you are doing with the individual words, but %%A will be the whole line (that you are working with), and %%B will be the current word that it is running. Make sure that you have 'goto :eof' at the end of :exist and :notexist otherwise it will run both sometimes.
-
tendude,
Why do you want to do this in DOS batch?
Yes, it can be done. But batch was make many years ago for limited needs taht existed at that time. Somewhere back in the 1980s I recall.
Presently Microsoft recommends users make use of advanced tools provided by Microsoft and others. Except for very basic things, like making copies of selected files.
What you are doing is string manipulation. This is better done with VBScript or Win script. May I suggest the OP look at this:
Getting Started with Windows Script Host and Vb Script (http://www.robvanderwoude.com/wshstart.ph)
But if you prefer Batch, pardon me.
-
i want know how to get the word, one by one from the text.
"I washed the car yesterday."
I
washed
the
car
yesterday
Try this as an example:
@echo off
for /f "tokens=1-5" %%a in ('type "file.txt" ') do (
echo %%a
echo %%b
echo %%c
echo %%d
echo %%e
)
pause
-
@echo off
setlocal=enabledelayedexpansion
set /p input=enter/paste document here :
:loop
for /f "tokens=1-5" %%a in ("input") do (
echo %%a
echo %%b
echo %%c
echo %%d
echo %%e
)
pause
if i want enter the text in input by use this code. why its does't work?
-
setlocal=enabledelayedexpansion
Nobody has picked this up. It's
setlocal enabledelayedexpansion
and anyhow it seems to be used as a kind of magic incantation, or as "cargo cult" code, since no delayed expansion has been called for in any of the code in this thread.
-
for /f "tokens=1-5" %%a in ("input") do (
("input") should be ( ' type "%input%" ' )
-
:loop
This doesn't do anything
-
.
-
"input" should be "%input%"
i already try. i enter "I washed the car yesterday" its does't work
so i deside use this
---------------------------------------------
@echo off
set /p input=file name with (.txt) : to enter file name its work
type "%input%" show all the text
for /f "tokens=1-5" %%a in ('type "%input%" ') do ( just show 1-5 word. not all
echo %%a echo first word
if "%%a"=="" goto nothaveit if have new word
)
:nothaveit
echo word %%a now save
echo %%a >> word.txt save new word to word.txt
pause
[/quote]
-
for /f "tokens=1-5" %%a in ('type "%input%" ') do (
echo %%a
if "%%a"=="" goto nothaveit
)
will only act upon the first word in each sentence of "%input%"
"input" should be "%input%"
This was my fault, I was working off the assumption that %input% was the line, not the file name. You are correct in that regard.
try
for /f "delims=" %%A in ('type "%input%"') do (
for %%B in (%%A) do (
echo %%B
if "%%B"=="" goto nothaveit
)
)
the 'for /f' will go through the file 1 line at a time, and then feed that line into 'for' for it to work though, word by word. This should allow your code to act upon every word in the document.
EXAMPLE:
tst:
This is
a test
cmd.exe:
C:\Users\Lemonilla>for /f "delims=" %A in ('type "tst"') do (
More? for %B in (%A) do (
More? echo %~B
More? ))
C:\Users\Lemonilla>(for %B in (This is ) do (echo %~B ) )
C:\Users\Lemonilla>(echo This )
This
C:\Users\Lemonilla>(echo is )
is
C:\Users\Lemonilla>(for %B in (a test ) do (echo %~B ) )
C:\Users\Lemonilla>(echo a )
a
C:\Users\Lemonilla>(echo test )
test
C:\Users\Lemonilla>
-
wow!! its work...i try use some paragraph which have a lot of work
example-
As a describer of life and manners, he must be allowed to stand perhaps the first of the first rank. His humour, which, as Steele observes, is peculiar to himself, is so happily diffused as to give the grace of novelty to domestic scenes and daily occurrences. He never "o'ersteps the modesty of nature," nor raises merriment or wonder by the violation of truth. His figures neither divert by distortion nor amaze by aggravation. He copies life with so much fidelity that he can be hardly said to invent; yet his exhibitions have an air so much original, that it is difficult to suppose them not merely the product of imagination.
and all the word show perfectly...
and next
how can i save each word in to word.txt?
echo %%B >> word.txt does't work
-
Do you want them still in the sentence line? or do you want them each on their own line?
echo %%B >>word.txt
should create/edit a text file called word.txt with 1 word per line
if you have echo %%A >>word.txt after the first close parentheses ")" then it will write the whole line to word.txt
also: Just noticed this, but this will not remove punctuation from the word, so it will read "himself" and "himself," differently. I would recommend asking someone else for a .vbs script, that will change this, as I lack the knowledge.
-
echo %%B>>"word.txt"
save work perfectly
-----------------------------------------------------------
for /f "delims=" %%A in ('type "%input%"') do (
for %%B in (%%A) do (
echo %%B>>"word.txt"
-----------------------------------------------------------
thank you
actually, each one of word will be save as a list + code
example
"I washed the car yesterday"
save in to word.txt as a list+code and look like this
"
if "%word%"=="I" set CODE
if "%word%"=="washed" set CODE
if "%word%"=="the" set CODE
if "%word%"=="car" set CODE
if "%word%"=="yesterday" set CODE
"
how to save each word and became like that?
i try this script
for /f "delims=" %%A in ('type "%input%"') do (
for %%B in (%%A) do (
echo %%B
set "code=if "%word%"==""
set "code2= set CODE"
set "word=%%B"
set "output=%code%%word%%code2%"
echo %output% >> "word.txt"
echo word " %%B " now save
if "%%B"=="" goto somewere
)
)
:somewere
pause
if "%word%"=="I" set CODE - i apart this line into 3 set
if "%word%"=="I" set CODE
set "code=if "%word%"=="" part one
set "word=%%B" part three
set "code2= set CODE" part two
and this 3 set became set output
set "output=%code%%word%%code2%"
hope became like i want...
"
if "%word%"=="I" set CODE
if "%word%"=="washed" set CODE
if "%word%"=="the" set CODE
if "%word%"=="car" set CODE
if "%word%"=="yesterday" set CODE
"
but on word.txt show like this
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
other one...
how to separate text? line? and paragraph?
example
As a describer of life and manners, he must be allowed to stand perhaps the first of the first rank. His humour, which, as Steele observes, is peculiar to himself, is so happily diffused as to give the grace of novelty to domestic scenes and daily occurrences. He never "o'ersteps the modesty of nature," nor raises merriment or wonder by the violation of truth. His figures neither divert by distortion nor amaze by aggravation. He copies life with so much fidelity that he can be hardly said to invent; yet his exhibitions have an air so much original, that it is difficult to suppose them not merely the product of imagination.
separate text by text
As a describer of life and manners,
he must be allowed to stand perhaps the first of the first rank.
His humour,
separate line by line
As a describer of life and manners, he must be allowed to stand perhaps the first of the first rank.
His humour, which, as Steele observes, is peculiar to himself, is so happily diffused as to give the grace of novelty to domestic scenes and daily occurrences.
separate paragraph by paragraph
As a describer of life and manners, he must be allowed to stand perhaps the first of the first rank. His humour, which, as Steele observes, is peculiar to himself, is so happily diffused as to give the grace of novelty to domestic scenes and daily occurrences. He never "o'ersteps the modesty of nature," nor raises merriment or wonder by the violation of truth. His figures neither divert by distortion nor amaze by aggravation. He copies life with so much fidelity that he can be hardly said to invent; yet his exhibitions have an air so much original, that it is difficult to suppose them not merely the product of imagination.
-
1) you are using the veriable word twice in there. also, you need to enable delayed expansion because you are changing veriables within a for loop. to do this you need to use 'setlocal EnableDelayedExpansion' then surround your veriable names with ! instead of %
Exp:
set "output=%code%%word%%code2%"
becomes
set "output=!code!!word!!code2!"
2) you are getting the ECHO is off. error because %output% refers to the value of output before the for loop started, which consequently is nothing, so you end up running echo as 'echo >>"word.txt"
3) Try running the help for the 'for' command 'for /?' or 'help for'. you will want to pay special attention to '/f' and "delims".
-
ty
its work
------------------------------------------------------------
for /f "delims=" %%A in ('type "%input%"') do (
for %%B in (%%A) do (
echo %%B
set "if=if"
set "tword=work"
set "code=word"
set "code2=set CODE"
set "word=%%B"
set "output=!if! "%%!tword!%%"=="!word!" !code2!"
echo !output!>>"word.txt"
echo word " %%B " now save
if "%%B"=="" goto nothaveit
)
)
------------------------------------------------------------
output
if "%work%"=="I" set CODE
if "%work%"=="wash" set CODE
if "%work%"=="the" set CODE
if "%work%"=="car" set CODE
if "%work%"=="yesterday" set CODE
just like i want. its becomes new script, so i just copy and paste in grammar.bat.
if have a new word its automaticly save
now to deside each word as
1 (pronoun)
2 (noun)
3 (verb)
4 (adverb)
5 (adjective)
6 (preposition)
7 (subject)
8 (object)
--------------------------------------------------
echo set " %%B " as
set/p "cho=>"
echo 1 (pronoun)
echo 2 (noun)
echo 3 (verb)
echo 4 (adverb)
echo 5 (adjective)
echo 6 (preposition)
echo 7 (subject)
echo 8 (object)
if %cho%==1 goto SOMEWERE
if %cho%==2 goto SOMEWERE
if %cho%==3 goto SOMEWERE
if %cho%==4 goto SOMEWERE
if %cho%==5 goto SOMEWERE
if %cho%==6 goto SOMEWERE
if %cho%==7 goto SOMEWERE
if %cho%==8 goto SOMEWERE
echo Invalid choice.
----------------------------------------------------
and here i am...i so blurr
-
1) set/p should be set /p (with a space)
2) the goto SOMEWHERE needs to corresponded with a flag ":somewhere"
3) how do you plan on storing this information?
-
actually i dont know yet...now i just thinking to solve other problem...
--------------------------------------------------------------------------
for /f "delims=" %%A in ('type "%input%"') do (
for %%B in (%%A) do (
echo %%B
:set
:save
how to make each word/%%B goto :set and next goto :save...
echo %%B just echoing all word at the end, did goto :save and next goto :save...
i try this
------------------------------------------------------------------
@echo off
setlocal enabledelayedexpansion
set /p input=file name with (.txt) :
:loop
for /f "delims=" %%A in ('type "%input%"') do (
for %%B in (%%A) do (
echo %%B
goto set
:set
CODE
goto save
:save
CODE
goto loop
---------------------------------------------------------
each its going back to loop, it will be same word...the first word
example
"I wash the car yesterday"
goes on the screen becomes
I
word " %B " now save
I
word " %B " now save
I
word " %B " now save
I
word " %B " now save
I
word " %B " now save
I
word " %B " now save
I
word " %B " now save
I
word " %B " now save
I
word " %B " now save
output on word.txt becomes
if "%work%"=="%B" set CODE
if "%work%"=="%B" set CODE
if "%work%"=="%B" set CODE
if "%work%"=="%B" set CODE
if "%work%"=="%B" set CODE
if "%work%"=="%B" set CODE
if "%work%"=="%B" set CODE
if "%work%"=="%B" set CODE
-
this is how i would write that, but there are different ways of doing it that still work.
for /f "delims=" %%A in ('type "%input%"') do (
for %%B in (%%A) do (
echo %%B
call set "%%B"
call save "%%B"
)
)
goto :endLoop
:set
CODE (using %~1 in replacment of %%B)
goto :eof
:save
CODE (using %~1 in replacment of %%B)
goto :eof
:endLoop
rest of program
OR
for /f "delims=" %%A in ('type "%input%"') do (
for %%B in (%%A) do (
echo %%B
REM set
CODE
REM save
CODE
)
)
The good thing about the first code is that you don't really need to use 'setlocal EnableDelayedExpansion', but it also requiters you to have an exit or it will rerun :set and :save with no input, which could cause errors. The 2nd code however is very difficult to debug, especially when it gets long.
-
1-
call set "%%B"
call save "%%B"
its doesn't work
on the :save and on :set not recognize %%B
i try using loop on this script
:loop - goto :save - goto :set - and back to :loop
but its just show first word...
call set word=%%B:~%j%,1%% , this is right way to use %~1 in replacment of %%B?
-
can you post your code? I'm having difficulty understanding what actually is happening in it.
code:
@echo off
set input=tst
for /f "delims=" %%A in ('type "%input%"') do (
for %%B in (%%A) do (
echo.
echo %%B
call :set "%%B"
call :save "%%B"
)
)
goto :endLoop
:set
echo :set %~1
goto :eof
:save
echo :save %~1
goto :eof
:endLoop
file [tst]:
this is text
output:
C:\test>a.bat
this
:set this
:save this
is
:set is
:save is
text
:set text
:save text
C:\test>
-
@echo off
setlocal enabledelayedexpansion
set /p input=file name with (.txt) :
type "%input%"
echo.
echo.
:loop
for /f "delims=" %%A in ('type "%input%"') do (
for %%B in (%%A) do (
echo %%B
call :set "%%B"
call :save "%%B"
)
)
:set
echo set " %%B " as
set/p "cho=>"
echo 1 (pronoun)
echo 2 (noun)
echo 3 (verb)
echo 4 (adverb)
echo 5 (adjective)
echo 6 (preposition)
echo 7 (subject)
echo 8 (object)
if %cho%==1 goto SOMEWERE
if %cho%==2 goto SOMEWERE
if %cho%==3 goto SOMEWERE
if %cho%==4 goto SOMEWERE
if %cho%==5 goto SOMEWERE
if %cho%==6 goto SOMEWERE
if %cho%==7 goto SOMEWERE
if %cho%==8 goto SOMEWERE
echo Invalid choice.
:save
set "if=if"
set "tword=work"
set "code=word"
set "code2=set CODE"
set "word=%%B"
set "output=!if! "%%!tword!%%"=="!word!" !code2!"
echo !output!>>"word.txt"
echo word " %%B " now save
if "%%B"=="" goto nothaveit
goto loop
--------------------------------------------------------------------------
on the :save and on :set not recognize %%B
on :set
echo set " %%B " as
output on screen
set " %B " as
not set " I " as
went it goto loop
its show the first word only...
-
try:
@echo off
setlocal enabledelayedexpansion
set /p input=file name with (.txt) :
type "%input%"
echo.
echo.
:loop
for /f "delims=" %%A in ('type "%input%"') do (
for %%B in (%%A) do (
echo %%B
call :set "%%B"
call :save "%%B"
)
)
goto :end
:set
echo set " %~1 " as
set/p "cho=^>"
echo 1 (pronoun)
echo 2 (noun)
echo 3 (verb)
echo 4 (adverb)
echo 5 (adjective)
echo 6 (preposition)
echo 7 (subject)
echo 8 (object)
if %cho%==1 goto SOMEWERE
if %cho%==2 goto SOMEWERE
if %cho%==3 goto SOMEWERE
if %cho%==4 goto SOMEWERE
if %cho%==5 goto SOMEWERE
if %cho%==6 goto SOMEWERE
if %cho%==7 goto SOMEWERE
if %cho%==8 goto SOMEWERE
echo Invalid choice.
goto :eof
:save
set "if=if"
set "tword=work"
set "code=word"
set "code2=set CODE"
set "word=%~1"
set "output=!if! "%%!tword!%%"=="!word!" !code2!"
echo !output!>>"word.txt"
echo word " %~1 " now save
if "%~1"=="" goto nothaveit
goto :eof
:end
echo END OF CODE
pause>nul
-
i try add new script
set "techo=echo"
set "simbol=!"
set "tbword=b!word!"
set "output5=!techo! !simbol!!tbword!!simbol!>>"bword.txt""
echo !output5!>>"word.txt"
output become
echo bI>>"bword.txt"
echo bwash>>"bword.txt"
echo bthe>>"bword.txt"
echo bcar>>"bword.txt"
echo byesterday>>"bword.txt"
where ! not show on word.txt
whish i want this output becomes like this
echo !bI!>>"bword.txt"
echo !bwash!>>"bword.txt"
echo !bthe!>>"bword.txt"
echo !bcar!>>"bword.txt"
echo !byesterday!>>"bword.txt"
how can i make ! save on word.txt?
any suggestion?
-
I don't have a computer with me, but try ^!
-
thanks alot...using ^! its work thank you
now
-------------------------------------------------------------------
set bI=1
set bwash=2
set bthe=3
set bcar=4
set byesterday=5
if "%word%"=="I" do (
set /a bI=%bI%+1
set "bI=!tset! !tbword!=!bI!"
echo !bI!>>"bword.txt"
)
goto :eof
if "%word%"=="wash" do (
set /a bwash=%bwash%+1
set "bwash=!tset! !tbword!=!bwash!"
echo !bwash!>>"bword.txt"
)
goto :eof
if "%word%"=="the" do (
set /a bthe=%bthe%+1
set "bthe=!tset! !tbword!=!bthe!"
echo !bthe!>>"bword.txt"
)
goto :eof
if "%word%"=="car" do (
set /a bcar=%bcar%+1
set "bcar=!tset! !tbword!=!bcar!"
echo !bcar!>>"bword.txt"
)
goto :eof
if "%word%"=="yesterday" do (
set /a byesterday=%byesterday%+1
set "byesterday=!tset! !tbword!=!byesterday!"
echo !byesterday!>>"bword.txt"
)
goto :eof
-------------------------------------------------------------------
each set plus 1
but output becomes
set bI=2
set bwash=2
set bthe=2
set bcar=2
set byesterday=2
not
set bI=2
set bwash=3
set bthe=4
set bcar=5
set byesterday=6
-
any one?
-
goto :eof
d
That is not in the right place. What you want it to mean?
Are your thinking about a CASE statement?
Batch does not have a CASE statement, not does it lend itself to a graceful way of making something like a CASE or SELECT structure.
-
i put goto :eof because i dont want it run all not necessary script.
-----------------------------------------------------------------------------------
i put value to each set
set bI=1
set bwash=2
set bthe=3
set bcar=4
set byesterday=5
went i run this script below
if "%word%"=="I" do (
set /a bI=%bI%+1
set "bI=!tset! !tbword!=!bI!"
echo !bI!>>"bword.txt"
)
goto :eof
if "%word%"=="wash" do (
set /a bwash=%bwash%+1
set "bwash=!tset! !tbword!=!bwash!"
echo !bwash!>>"bword.txt"
)
goto :eof
if "%word%"=="the" do (
set /a bthe=%bthe%+1
set "bthe=!tset! !tbword!=!bthe!"
echo !bthe!>>"bword.txt"
)
goto :eof
if "%word%"=="car" do (
set /a bcar=%bcar%+1
set "bcar=!tset! !tbword!=!bcar!"
echo !bcar!>>"bword.txt"
)
goto :eof
if "%word%"=="yesterday" do (
set /a byesterday=%byesterday%+1
set "byesterday=!tset! !tbword!=!byesterday!"
echo !byesterday!>>"bword.txt"
)
goto :eof
------------------------------------------------------------------
this script should make each set +1
from this to
plus 1 each of set
set bI=1 1+1=2 set bI=2
set bwash=2 2+1=3 set bwash=3
set bthe=3 3+1=4 set bthe=4
set bcar=4 4+1=5 set bcar=5
set byesterday=5 5+1=6 set byesterday=6
but output on bword.txt becomes like this
set bI=2
set bwash=2
set bthe=2
set bcar=2
set byesterday=2
you know how to solve this?
-
Just remove all of goto :eof and it might work.
-
it not work
it just going run all script...
output on bword.txt becomes
set bI=2
set bI=3
set bI=4
set bI=5
set bI=6
set bwash=2
set bwash=3
set bwash=4
set bwash=5
set bwash=6
set bthe=2
set bthe=3
set bthe=4
set bthe=5
set bthe=6
set bcar=2
set bcar=3
set bcar=4
set bcar=5
set bcar=6
it run all not necessary script.
if "%word%"=="I" do (
set /a bI=%bI%+1
set "bI=!tset! !tbword!=!bI!" if i remove goto :eof its will be run all not necessary script below
echo !bI!>>"bword.txt"
)
goto :eof
if "%word%"=="wash" do (
set /a bwash=%bwash%+1
set "bwash=!tset! !tbword!=!bwash!"
echo !bwash!>>"bword.txt"
)
goto :eof
if "%word%"=="the" do (
set /a bthe=%bthe%+1
set "bthe=!tset! !tbword!=!bthe!"
echo !bthe!>>"bword.txt"
)
goto :eof
if "%word%"=="car" do (
set /a bcar=%bcar%+1
set "bcar=!tset! !tbword!=!bcar!"
echo !bcar!>>"bword.txt"
)
goto :eof
if "%word%"=="yesterday" do (
set /a byesterday=%byesterday%+1
set "byesterday=!tset! !tbword!=!byesterday!"
echo !byesterday!>>"bword.txt"
)
goto :eof
-
This is as far as I can help you.
This term
"%word%"
is a persistent entity in the code you gave. It does not wear mutilate or change value by itself.
When the test of
==
meaning really equal to,
is used, the result is exclusive for a persistent entity tested on unique values., but not null null values. You were supposed to learn that back in Programming 101 some time ago.
Sorry, if you don't grasp this, I can not help you.
The script you gave has blocks that are mutually exclusive, so a break is not needed. Take out all the gooto.
-
@echo off
setlocal enabledelayedexpansion
echo 1 scan document
echo 2 create document
echo 3 reset document
set/p "pilih=^>"
if %pilih%==1 goto :scan
if %pilih%==2 goto :create
if %pilih%==3 goto :reset
:reset
set bI=0
set bwash=0
set bthe=0
set bcar=0
set byesterday=0
goto enter
:create
set bI=1
set bwash=2
set bthe=3
set bcar=4
set byesterday=5
if "%word%"=="I" do (
set /a bI=%bI%+1
set "bI=!tset! !tbword!=!bI!"
echo !bI!>>"bword.txt"
)
if "%word%"=="wash" do (
set /a bwash=%bwash%+1
set "bwash=!tset! !tbword!=!bwash!"
echo !bwash!>>"bword.txt"
)
if "%word%"=="the" do (
set /a bthe=%bthe%+1
set "bthe=!tset! !tbword!=!bthe!"
echo !bthe!>>"bword.txt"
)
if "%word%"=="car" do (
set /a bcar=%bcar%+1
set "bcar=!tset! !tbword!=!bcar!"
echo !bcar!>>"bword.txt"
)
if "%word%"=="yesterday" do (
set /a byesterday=%byesterday%+1
set "byesterday=!tset! !tbword!=!byesterday!"
echo !byesterday!>>"bword.txt"
)
goto :eof
:enter
echo enter text and enter
set /p input=:
:savebword
:scan
set /p input=file name with (.txt) :
type "%input%"
echo.
echo.
:loop
for /f "delims=" %%A in ('type "%input%"') do (
for %%B in (%%A) do (
echo %%B
call :set "%%B"
call :save "%%B"
call :create "%%B"
echo.
)
)
goto :end
:set
echo set " %~1 " as
echo 1 (pronoun)
echo 2 (noun)
echo 3 (verb)
echo 4 (adverb)
echo 5 (adjective)
echo 6 (preposition)
echo 7 (subject)
echo 8 (object)
set/p "cho=^>"
if %cho%==1 goto SOMEWERE
if %cho%==2 goto SOMEWERE
if %cho%==3 goto SOMEWERE
if %cho%==4 goto SOMEWERE
if %cho%==5 goto SOMEWERE
if %cho%==6 goto SOMEWERE
if %cho%==7 goto SOMEWERE
if %cho%==8 goto SOMEWERE
echo Invalid choice.
goto :eof
:save
set "word=%~1"
set "if=if"
set "tword=word"
set "code=word"
set "tset=set"
set "tbword=b!word!"
set "techo=echo"
set "simbol=^!"
set "output=!if! "%%!tword!%%"=="!word!" goto !tbword!"
set "outputt=:!tbword!"
echo !output!>>"word.txt"
echo !outputt!>>"word.txt"
set "output2=!tset! !tbword!=0"
echo !output2!>>"setword.txt"
set "output3=!tset! /a !tbword!=%%!tbword!%%+1"
echo !output3!>>"word.txt"
echo (set /a bword=%bword%+1)
set (bof=%bof%)
set "output4=!tset! !tbword!=%%!tbword!%%"
set "output6=!tset! "!tbword!=!simbol!tset!simbol! !simbol!tbword!simbol!=!simbol!!tbword!!simbol!""
set "output7=!techo! !simbol!!tbword!!simbol!>>"bword.txt""
set "output8=goto :eof"
echo !output6!>>"word.txt"
echo !output7!>>"word.txt"
echo !output8!>>"word.txt"
echo word " %~1 " now save
if "%~1"=="" goto nothaveit
goto :eof
:end
echo END OF CODE
pause>nul
this full script i make so far...
the problem is here
if "%word%"=="I" do (
set /a bI=%bI%+1
set "bI=!tset! !tbword!=!bI!"
echo !bI!>>"bword.txt"
)
goto :eof
if "%word%"=="wash" do (
set /a bwash=%bwash%+1
set "bwash=!tset! !tbword!=!bwash!"
echo !bwash!>>"bword.txt"
)
goto :eof
if "%word%"=="the" do (
set /a bthe=%bthe%+1
set "bthe=!tset! !tbword!=!bthe!"
echo !bthe!>>"bword.txt"
)
goto :eof
if "%word%"=="car" do (
set /a bcar=%bcar%+1
set "bcar=!tset! !tbword!=!bcar!"
echo !bcar!>>"bword.txt"
)
goto :eof
if "%word%"=="yesterday" do (
set /a byesterday=%byesterday%+1
set "byesterday=!tset! !tbword!=!byesterday!"
echo !byesterday!>>"bword.txt"
)
goto :eof
it should create output like this
set bI=2
set bwash=3
set bthe=4
set bcar=5
set byesterday=6
but
set bI=2
set bwash=2
set bthe=2
set bcar=2
set byesterday=2
!bI!, !bwash!, !bthe! ,!bcar! and !byesterday! all =2...
why?
this is the problem that i need help to solve
-
Try changing your set /a to
Set /a %var%+=1
-
if "%word%"=="wash" do (
set /a bwash=%bwash%+1
set "bwash=!tset! !tbword!=!bwash!"
echo !bwash!>>"bword.txt"
)
1. There is no IF .... DO in batch language. (Are you making the syntax up as you go?) I am amazed you have not seen lots of error messages (or are you running batch scripts by double clicking them?)
2. To alter, or set and then read a variable inside parentheses you need delayed expansion. (Read about it).
I suggest you read the documentation for each command or keyword, either from the prompt by typing the command followed by /? (example: if /?) or you can use a site like ss64.com
http://ss64.com/nt/
Start with simple scripts and learn how each command or keyword works. You are just making up code by guesswork, and that will just lead to very long threads like this one.