Many URLS in One Variable Breaks Script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
RoseCode
Posts: 50
Joined: 24 Jan 2015, 15:34

Many URLS in One Variable Breaks Script

07 Jul 2019, 13:46

Greetings and thanks for your help! I find I cannot get Autohotkey to work with a long list of contiguous URL-text that does not contain any linebreaks at all. My proof of concept below works great but breaks when many URLS are placed in a block variable. The URLS are contiguous and have no line breaks at all: just one long string because that's what the FireFox Copy All Tabs addon yields. I'm trying to add line breaks to the URLS by replacing the string "mynewline," which is the only separator in my block of URL-text.

The errors I get as I try to work through this are:
1 Variable too long
2 This parameter contains a variable name missing its ending percent sign.

THANK YOU for your input!

Code: Select all

; Replace String "MyNewLine" with Line Breaks `r`n
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance, Force
#InstallKeybdHook
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
;MsgBox %A_AhkPath%
;#include %A_AhkPath%\Lib\ScrollBox.ahk   ; cannot use a variable to find ScrollBox.ahk in the Autohotkey.exe directory tree?
#include C:\Program Files\AutoHotkey\Lib\ScrollBox.ahk
;VarSetCapacity(user, 111110240000)
;Msgbox %user%
return

F4::
ReplaceStringWithLineBreaks:
TextToManipulate = 
(
fat bunny
big bun
lonely bun
fat BOOOBOOOBOOOny
big BOOOBOOOBOOO
lonely BOOOBOOOBOOO
hellomynewlinehello
hellomynewlinehello
)

sleep 200
String1 = bun
String2 = mynewline
sleep 100
InputVar1 = %TextToManipulate%
;MsgBox % clipboard
;gosub LineBreakGui
StringReplace, OutPutVar1, InputVar1, %String1%,BOOOBOOOBOOO, All
sleep 200
StringReplace, OutPutVar2, OutPutVar1, %String2%,`r`n, All
sleep 200
;MsgBox % OutPutVar2
clipboard := OutPutVar2
gosub LineBreakGui
return

MyLinks2:

clipboard =
(
long url text goes here but breaks scripts many ways:
Variable too long
percent signs break script too
This parameter contains a variable name missing its ending percent sign.
)

goto MyLinks1
return

MyLinks1:
Gui, Submit
Gui, Destroy
YourNewLineString = "mynewline"
StringReplace, YourLineBreaksVar, clipboard, %YourNewLineString%,BOOOBOOOBOOO, All
sleep 200
;MsgBox % YourLineBreaksVar
clipboard := YourLineBreaksVar
ClipBoardContents := "Your LineBreaks Have Been Added and Clipboard now contains: `r`n" clipboard
sleep 200
ScrollBox(ClipBoardContents, "p w b1 f{s12 cBlack, Lucida Console} x5 y10 h700 w900")
MsgBox % clipboard
sleep 300
return

LineBreakGui:
Gui default
gui, font, s12, Verdana
Gui, Add, Picture, x0 y0 w610 h385 +0x4000000, ;%A_ScriptDir%\img\anon.png
Gui, Color, 000000
Gui, Font, cwhite
Gui, Add, Text, yp+40, `n    To Replace all instances of MyNewLine with Line Breaks   `n    Hit the Big Button ! `n`n    F4 key to re-open this window `n`n    Esc key to exit
;~ Gui, Add, Text, yp+20, Enter Directory of Kontakt Library Below
;~ Gui, Add, Text, yp+20, WE FOUND an UNUSED Number below!
;~ Gui, Add, Text, xp+10 yp+44, k2lib0
Gui, Font, cblack
;Gui, Add, Edit, yp+40 vSomeVariableFive, %SomeTestLinksAndText%
gui, font, s24, Verdana
Gui, Font, cwhite
Gui, Add, Button, Default gMyLinks1, Proof of Concept Button 
Gui, Add, Button, Default gMyLinks2, Too Many Contiguous URLS Button Will not Work?
Gui Show, , Window
Return

Esc::
Gui, Destroy
return

;======================= STANDARD AUTOHOTKEY FOOTER
RAlt::
IfWinActive, SciTE
{
sendinput ^s
sleep 300
}
IfWinExist, DebugView
{
	;MsgBox hello

ControlSend, , ^x, DebugView
sleep 300
}

Reload
return


^Esc::
exitapp
return


BIGEXIT:
	exit
	
Last edited by RoseCode on 09 Jul 2019, 15:28, edited 1 time in total.
User avatar
RoseCode
Posts: 50
Joined: 24 Jan 2015, 15:34

Re: Many URLS in One Variable Breaks Script

09 Jul 2019, 15:25

If a contiguous string is too long, such as the long list of urls at the root of my problem, does one necessarily have to place it into a file so that it can be read by the file reading mechanism instead of the variable reading mechanism? The below completely breaks any script into which I place it. Long list of URLS are a common thing nowadays and I'm surprised they are not easily handled?

Code: Select all

https://www.google.com/search?q=autohotkey+variable+too+long&client=firefox-b-d&ei=4vkkXd7qF9WQtAbxu5mYCQ&start=10&sa=N&ved=0ahUKEwje47qv16jjAhVVCM0KHfFdBpMQ8tMDCIgB&biw=1920&bih=944mynewlineautohotkey variable too long - Google Searchmynewlinehttps://autohotkey.com/board/topic/40545-how-to-deal-with-large-long-strings-for-variables/mynewlineHow to deal with large (long) strings for variables? - Ask for Help - AutoHotkey Communitymynewlinehttps://www.autohotkey.com/boards/viewtopic.php?t=56524mynewline(3) RegExMatch limit (variable too long?) - AutoHotkey Communitymynewlinehttps://autohotkey.com/board/topic/73078-string-too-long-error/mynewlineString too long error - Ask for Help - AutoHotkey Communitymynewlinehttps://autohotkey.com/board/topic/36134-string-is-too-long/mynewlineString is too long - Ask for Help - AutoHotkey Communitymynewlinehttps://www.autohotkey.com/boards/viewtopic.php?t=28288mynewline(3) Array - Expression Too Long - AutoHotkey Communitymynewlinehttps://autohotkey.com/board/topic/73539-variable-limit/mynewlineVariable Limit - Issues - AutoHotkey Communitymynewlinehttps://autohotkey.com/board/topic/90299-string-too-long-for-interpreter-to-handle/mynewlineString too long for interpreter to handle? - Ask for Help - AutoHotkey Communitymynewlinehttps://autohotkey.com/board/topic/98443-expression-too-long/mynewlineExpression too long? - Ask for Help - AutoHotkey Communitymynewlinehttps://autohotkey.com/board/topic/15185-maximum-variable-size/mynewlineMaximum variable size? - Ask for Help - AutoHotkey Communitymynewlinehttps://autohotkey.com/board/topic/93983-continuation-section-too-long/mynewlineContinuation section too long. - Ask for Help - AutoHotkey Communitymynewlinehttps://autohotkey.com/board/topic/18399-maximum-variables/mynewlineMaximum Variables - Ask for Help - AutoHotkey Communitymynewlinehttps://autohotkey.com/board/topic/117949-string-appears-to-be-too-long/mynewlineString appears to be too long - Ask for Help - AutoHotkey Communitymynewlinehttps://autohotkey.com/board/topic/1729-max-string-length/mynewlinemax string length? - Ask for Help - AutoHotkey Communitymynewlinehttps://autohotkey.com/board/topic/118074-how-to-store-large-variable/mynewlineHow to store large variable? - Ask for Help - AutoHotkey Communitymynewlinehttps://www.autohotkey.com/docs/commands/StringLen.htmmynewlineStrLen() / StringLen - Syntax & Usage | AutoHotkeymynewlinehttps://www.autohotkey.com/docs/commands/VarSetCapacity.htmmynewlineVarSetCapacity() - Syntax & Usage | AutoHotkeymynewlinehttps://autohotkey.com/board/topic/32981-error-when-run-autohotkeyexe-with-long-parameters/page-2mynewlineERROR when Run autohotkey.exe with long parameters - Page 2 - Ask for Help - AutoHotkey Communitymynewline
Why Vegan? Because...because..I mean, have you ever seen a Lamb play? http://VeganGod.org :-)
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Many URLS in One Variable Breaks Script  Topic is solved

09 Jul 2019, 15:40

If a contiguous string is too long, you can also replace it with concatenation:

Code: Select all

loop 20000
veryLongString .= "Line" . A_Index
MsgBox, % StrLen(veryLongString)
User avatar
RoseCode
Posts: 50
Joined: 24 Jan 2015, 15:34

Re: Many URLS in One Variable Breaks Script

09 Jul 2019, 20:27

Hi Wolf! Thanks for the tip! It turns out my problem was all related to the limitations of block variables! To keep from copying the long string onto the clipboard I put it into a block variable like this:

Code: Select all

MyLongVar =
(
a billion bits of stuff here!!!
)
And it would fail in many ways regarding length or illegal characters. But if I just left the super long string on the clipboard or read it from a file, all worked as expected. Block variables are highly limited, so now I know :-)

So the above script worked just fine, without the block variable. Thanks again Wolf!
Why Vegan? Because...because..I mean, have you ever seen a Lamb play? http://VeganGod.org :-)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Aqualest, mikeyww and 332 guests