Making variable into an .txt file Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Making variable into an .txt file

Post by armin889 » 02 Dec 2022, 03:26

Hi community
in my ahk-code I have some variables like this:

Code: Select all

key1 := "3uuuuuu9"
key2 := "b357751"
key3 := "52977f1"
key4 := "b78555"
key5 := "844326"
key6 := "378zza5b"
I want to but them in an external file like .txt and read them after starting the ahkgui
What's the best and shortest code for doing this?

Thanks a lot

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Making variable into an .txt file

Post by Rohwedder » 02 Dec 2022, 04:19

Hallo,
try:

Code: Select all

FileDelete, Key.txt
FileAppend, 3uuuuuu9|b357751|52977f1|b78555|844326|378zza5b, Key.txt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FileRead, Keys, Key.txt
StringSplit, Key, Keys, |
MsgBox,% Key1 " > " Key6

armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: Making variable into an .txt file

Post by armin889 » 02 Dec 2022, 05:09

Thanks a lot for your reply
the problem in your code is in my case, I can not change the value in .txt without changing the ahk too.

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Making variable into an .txt file

Post by Rohwedder » 02 Dec 2022, 05:16

You could get the idea to delete the lines with FileDelete and FileAppend and change Key.txt using Notepad!

armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: Making variable into an .txt file

Post by armin889 » 02 Dec 2022, 07:15

Ok thanks, I understand now, yes it is working
but the text file has to look like this then
3uuuuuu9|b357751|52977f1|b78555|844326|378zza5b

in long txt it gets a little confusing, is there a way to put it line by line like this:
3uuuuuu9
b357751
52977f1
b78555
844326
378zza5b

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Making variable into an .txt file  Topic is solved

Post by Rohwedder » 02 Dec 2022, 08:49

Then:

Code: Select all

FileRead, Keys, Key.txt
StringSplit, Key, Keys, `n, `r
MsgBox,% Key1 " > " Key6

armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: Making variable into an .txt file

Post by armin889 » 02 Dec 2022, 22:08

Thanks Rohwedder
works great

Post Reply

Return to “Ask for Help (v1)”