Cannot pickup data from a file

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
RareUserGerman
Posts: 1
Joined: 03 May 2024, 20:21

Cannot pickup data from a file

03 May 2024, 20:52

Hi,
below you see a copy of a file I wrote some times ago. Now that I want to convert it to V2 I was first testing if it runs in v1, but it does not.
I have been trying for hours now.

What I do as the user of this script:
First I click to where I want to paste some text with my mouse.
Second I start my menu with ^1 (several informations - line by line read from a text file - are - line by line - displayed in the menu).
Then I select the information from the menu and the selected information is pasted.

Therefore I want to read a txt-file first, but my MsgBox stays empty.

Code: Select all

^1::

Text := []

Loop, read, "C:\Users\Hp\Desktop\Daten.txt"
{
newText := A_LoopReadLine
Text := %Text% . "¦" . %newText%
}

MsgBox %Text%
;TextMenu(Text)
return

TextMenu(TextOptions){
	for k, MenuItems in StrSplit(TextOptions,"¦")
		Menu,MyMenu,Add,% trim(MenuItems),Action
Menu,MyMenu,Show
Menu,MyMenu,DeleteAll
}

Action:
ClipboardBackup:=ClipboardAll
Clipboard:=""
Clipboard:=A_ThisMenuItem
Clipwait,1
Send ^v
Sleep, 200
Clipboard:=ClipboardBackup
return

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]
User avatar
boiler
Posts: 17176
Joined: 21 Dec 2014, 02:44

Re: Cannot pickup data from a file

03 May 2024, 21:37

Since you're acting on Text as a string, you would not initialize it as an object with Text := []. You could just assign it an empty string: Text := ""

Then, you use the expression assignment operator, but then you put % symbols around variables as if it were legacy syntax, which is not correct here:

Code: Select all

Text := %Text% . "¦" . %newText%

The best way to do it is as an expression:

Code: Select all

Text := Text . "¦" . newText
or even better:

Code: Select all

Text .= "¦" . newText

Alternatively but not preferred, legacy syntax:

Code: Select all

Text = %Text%¦%newText%

There may be other things wrong with your code, but fix that first.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Albireo, Bing [Bot], just me and 90 guests