Solved Saving a variable to a specific line and retrieve it

Hello :)I wonder if/how i could do this:First i want to save a variable like %a% on a specific line in the same program. For example:save %a% to line 2000and after that i want to be able to retrieve it again likeset a=whatever is on line 2000 in the file

that would help me really much because i could use it to save settings and restore them in the same program. I want my biggest batch file to be like all in one.

Batch is not really suited for random access retrieval. You can of course store and retrieve values, but trying to build the values into your batchfile code is very inefficient since the batchfile has to replace itself with appended data every time the data is stored. (ie: batch is sequential or block-mode access, not random). Better to just use a text data-storage file:::=== begin batch@echo off & setlocal enabledelayedexpansionset /p r=retrieve?if /i "%r%" equ "y" goto :retrieveset c=-1:1set /a c+=1set x%c%=set /p x%c%=enter data %c%if defined x%c% goto :1echo saving data:set xpauseset x>tempgoto :eof:retrievefor /f "tokens=*" %%a in (temp) do set %%aecho retrieved data:set xgoto :eof::==== endalthought this doesn't give you "line storage", it does give you a semblance of random-access storage by using the index of x(x0, x1, x2 etc) to pull specific items from the data-clump.

It doesn't apply to my situation i think. I know some stuff in batch programming, but i have no idea on the subject I'm asking for in this thread. If that was what you were thinking about, i don't know "half the code", and i hope I've been clear enough on what i want to achieve :)

Actually, that blog post does apply to your situation. The problem with it is that the lesson to be learned was obscured with the added commentary.

You have an XY problem. Meaning that you have problem X and have decided on a faulty solution Y and have asked us how to implement your faulty solution rather than asking how to solve the root problem.

Batch is not really suited for random access retrieval. You can of course store and retrieve values, but trying to build the values into your batchfile code is very inefficient since the batchfile has to replace itself with appended data every time the data is stored. (ie: batch is sequential or block-mode access, not random). Better to just use a text data-storage file:::=== begin batch@echo off & setlocal enabledelayedexpansionset /p r=retrieve?if /i "%r%" equ "y" goto :retrieveset c=-1:1set /a c+=1set x%c%=set /p x%c%=enter data %c%if defined x%c% goto :1echo saving data:set xpauseset x>tempgoto :eof:retrievefor /f "tokens=*" %%a in (temp) do set %%aecho retrieved data:set xgoto :eof::==== endalthought this doesn't give you "line storage", it does give you a semblance of random-access storage by using the index of x(x0, x1, x2 etc) to pull specific items from the data-clump.

Quote:Actually, that blog post does apply to your situation. The problem with it is that the lesson to be learned was obscured with the added commentary.You have an XY problem. Meaning that you have problem X and have decided on a faulty solution Y and have asked us how to implement your faulty solution rather than asking how to solve the root problem.

Now i understood what you were asking for :)Well the root problem is probably that i want to be able to save stuff as passwords, colour settings etc. inside the batch file instead of saving it to another txt file or something like that. I don't want more files or subfolder or stuff like that. I want everything to be able to be done inside its own file.The settings should be saved so i don't have to register a new password or changing the color settings everytime i start the file.

@Razor: wow, that's (setx) a new one for me, it's impressive! too bad it's not on xp.

@op: One good thing about a separate text file: if you want to hide passwords, at least you can zip it encrypted with a "master" password. You could also append it to a random media file (jpg, mp3, bmp, etc) to hide it. But of course, if you use your batchfile to extract the passwords, then the master password, (and the target file and methodology) will be plain for anyone to examine in the code unless you use a batch-encryptor.

The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this
site. Computing.Net and Compnet Ventures, LLC hereby disclaim all responsibility
and liability for the content of Computing.Net and its accuracy.