 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
tuna
Joined: 03 Oct 2007 Posts: 47 Location: Bristol, England
|
Posted: Fri Dec 14, 2007 8:47 pm Post subject: Writing all variables |
|
|
Does anyone know how I would be able to write all variables to a file without processing each individual one at a time, perhaps using a similar method to how listvars can list all variables?
Many thanks. |
|
| Back to top |
|
 |
JDN
Joined: 24 Mar 2004 Posts: 135
|
Posted: Fri Dec 14, 2007 10:11 pm Post subject: |
|
|
I originally thought this would be a lot more difficult than I now think it is. With a little luck, it won't be very hard at all.
One of the most important questions though, is the format of the output file you desire. If you are not too fussy, it can be a much smaller job than if you are. Personally, I would think the best all purpose general format would be the same format used by Autohotkey's IniWrite command. That is the format that lists the name of each variable and its value in a style like the following:
[DATA SECTION]
Var_Nam = Jones, Hector
Salary = 20000
Street = Main Street
Age = 45
Suppose we use the two MOD keys ALT+WIN to define all the hotkeys we will use in this example.
To begin, you would define one hotkey to execute the ListVars command.
Suppose the first hotkey is ALT+WIN+1 and defined as follows:
#!1::Listvars
Listvars opens a window and you have to capture the contents of that window with a second hotkey - say #!2 as follows:
#!2::Send +^{end}^c
Actually you don't need all of these hotkeys. You could probably combine several operations into one hotkey. But it's good to break them up. It helps the planning process.
So, #!2 uses the SHIFT+CTL+END to go from the beginning of the window opened by Listvars to the end of the window and highlight the entire window. The CTL+C then copies the entire contents of the window into the clipboard. Listvars, by the way, defaults to having the cursor positioned at the beginning of the data window that it opens. So SHIFT+CTL+END highlights the entire window and CTL+A copies it all to the clipboard.
Then you need a third hotkey to paste the clipboard into an editor. So, you will need an editor handy. Let's assume you have already opened NotePad or NoteTab. I'll assume you can open some editor on your own and so you just need to use CTL+V to paste the contents of the clipboard into that editor and save it to file if you like.
If you are not fussy as to the format of the output file, you may now be finished. The format will be exactly like the format of the ListVars command. So that may not be what you want. If that is not what you want, you will have to manipulate the contents of the file to re-format it. This wil depend on you. But let me know? It sounds like an interesting project and I might like to try it.
It probabl won't be too difficult to convert the format of the Listvars command to the format produced by the IniWrite command. If I can get a script to work, I'll post it in another message.
In the meantime, you have to decide upon the format you want for the output file. Do you want to use the IniWrite format that is supplied by AutoHotkey? I think that would make it easy to debug.
Good luck to you.
Last edited by JDN on Sat Dec 15, 2007 12:50 am; edited 6 times in total |
|
| Back to top |
|
 |
JDN
Joined: 24 Mar 2004 Posts: 135
|
Posted: Fri Dec 14, 2007 11:57 pm Post subject: |
|
|
OK. I wrote a small script that reads a file in the format of the ListVars command and converts it into something like the format of the IniWrite command. I recommend the format of the IniWrite command to you because there are some Windows commands that support it and it is also very readable. You can visually examine the files and easily read its contents and they tend to make a lot of sense.
I hope this is fairly close to what you wanted. You still have to create the file in the format of the ListVars command. But I think the instructions I provided in the previous post should help you to do that.
For example, if the input file is:
Var_Name[4 of 7]: SMIT
Top[1 of 4]: 33
It produces the output:
Var_Name= SMIT
Top= 33
Here is the script:
Loop READ, C:\LV.TXT
{
H:= A_LoopReadLine
P:= InStr(H, "[")
Q:= InStr(H, "]")
Out_Rec:= SubStr(H, 1, P - 1) "=" SubStr(H, Q + 2)
Msgbox % Out_Rec
}
In the above script, the name of my input file is "C:\LV.TXT"
You will have to modify the script to output to a file of your choosing. As it stands, it just shows you each output line in the form of the MsgBox command. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|