reading "special" characters from a file

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
GTM
Posts: 19
Joined: 24 Mar 2020, 18:44

reading "special" characters from a file

26 Mar 2020, 10:10

I'm attempting to use 'loop, read' and 'loop, parse' to read encoded strings from a file and I've run into the problem that characters like # are not read, and even worse, the exclamation ! will take out a neighboring character with it .

If I go in and manually throw the characters within curly braces {} it works, but I dont know if Ill be able to do that always. Id like to get away from as much manual interaction as possible.

Is there an option or parameter to get around this?

also how are you supposed to use fileopen?? it doesnt seem to matter how I try to reference the file location, I get illegal character warnings. Ive tried escaping all the back slashes, and the colon, set the location as a variable first and then tried to pass that.. doesnt seem to matter what I do, illegal character in expression. Its driving me nuts.. so many weird quirks with this language man.

And why is A_workingdir not the directory the script is in, but its parent????
GTM
Posts: 19
Joined: 24 Mar 2020, 18:44

Re: reading "special" characters from a file

26 Mar 2020, 11:23

Also Im really trying to make sense of the legacy vs expression thing, I thought I had it, and then I ran into this situation.

Code: Select all

;this is legacy, not function syntax, so variables must be enclosed in %, ok cool I get it
Loop, read, %fileToRead% 

;But down here im using the built in var A_LoopReadLine, and I HAVE to omit the % 
Loop, parse, A_LoopReadLine
In both instances Im using the variable in place of their contents, trying to reference the contents right??? if I omit the % in the first case nothing happens cause it takes the variable name to be the literal file which isnt gonna work so that cool I get it.
But in the second I have to omit the % or I get illegal character in variable name error.

So how TF does this work? What am I missing



;///////////////////////////////// EDIT

So while I'm here asking questions, why is it that when I create an object, I can only seem to assign to it using object.Property and not object[property] or object["property"], but at the same time, if I want to pass the value of a particular property to a function, I have to user object["property"] because the other 2 ways I mentioned dont seem to work???????

THIS IS SO CONFUSING
GTM
Posts: 19
Joined: 24 Mar 2020, 18:44

Re: reading "special" characters from a file

27 Mar 2020, 00:45

Spend over an hour debugging a section of my code, to FINALLY have it output FLAWLESSLY

But then the output stops.

I start to trace back over the same steps that I spent the last hour and a half of my life tracing. Nothing is wroking. Try changing some things. WHy are these variables null now? Try some more stuff.

Try everything imaginable.

Trace back even more right to the very input to the whole module.

Its not there.

Yes, thats correct, the module that was feeding the one you were currently working on, is no longer sending data, everything is empty

So now I must go back even further through my code, to the stuff that was working well before.

Did I mention that nothing seems to match up correctly? Half my user functions have a different set of text mates than the others, FOR ABSOLUTELY NO REASON.

How can a module that I have folded and have not even touched, just stop working? Literally have its data dry up?

HOW
Last edited by gregster on 27 Mar 2020, 00:57, edited 1 time in total.
Reason: Removed uncivil language
gregster
Posts: 8921
Joined: 30 Sep 2013, 06:48

Re: reading "special" characters from a file

27 Mar 2020, 00:54

It would probably help to keep a cool mind. I know debugging can be tough, but this is true for every programming language.

If you want help, it would probably help to post your code (or a part you have problems with), and perhaps example data, instead of ranting - and describe the intended goal and what doesn't work as expected. Currently, no one knows what you are actually talking about.

And please mind your language!
GTM
Posts: 19
Joined: 24 Mar 2020, 18:44

Re: reading "special" characters from a file

27 Mar 2020, 01:12

wow and now after I went and made sure everything was expanded to the limit

now its not registering my hot key.

:dance:

seriously.

The amount of fricking time ive spent bashing my head against the wall with this shit I could have written something in assembly by now
GTM
Posts: 19
Joined: 24 Mar 2020, 18:44

Re: reading "special" characters from a file

27 Mar 2020, 01:28

Honestly, this makes absolutely NO sense to me at all.

I change the indent on a function and it breaks the entire main loop.

I went back to the beginning of the section I said that stopped working. It was giving no output, I did this

Code: Select all


 getUserInformation()
    {
        blockString := ""
        userInformation := Object()
            Loop,
        {
            blockString := getUserInput(false)
            send % "blockString is: " blockString "`r"
            userInformation.definition := getHeaderDefinitionNum(blockString)
            send % "userInformation.definition is: " userInformation.definition "`r"
            blockStringLen := strlen(blockString)
            send % "blockStringLen is: " blockStringLen "`r"
            last5Chars := subStr(blockString, -4)
            send % "last5Chars is: " last5Chars "`r"

            strPos := 0

.	    ...
		
		
		and so on
I added those send blocks to see what the F@#$ was going on

and now,

like magic.

its all working again.

Heres a sample of the output from this module

Code: Select all

blockString is: 3TESTING123/*666
userInformation.definition is: 03
blockStringLen is: 15
last5Chars is: /*666
User text: TESTING123
Block Width: 666
Comment Char:  /*
End Char: */
Comment Definition: 03
I use the data parsed and extrapolated from a text file of definitions to generate what you see above and then it is further processed. This is largely an excercise in learning this stuff. My main goal is to create an import/export script so I can code Excel VBA in VSCode (you HAVE to use the VBA ide to compile and run applications unfortunately, and its IDE is literally 20 years old with 3 colors for your syntax, and if you want anything other than the base 16 standard colors from 1980 then you need to hack vbe7.dll with your own custom colors.. but still, 16, and only 3 apply to syntax...

Anyway .. I digress

somebody please explain,

hoenstly. please.

Its been like this all day. I add in send blocks to analyze whats going on, and then it starts working.

I will try to remove them now and it will stop working. Or it will continue to work for a little while before deciding to break again on me.

I know I am a trash-teir programmer. I know I have a lot to learn and what not. But its the inconsistencies that I just cant handle, how am I supposed to learn when the playing field keeps shifting on me and throwing curveballs that make no sense?
gregster
Posts: 8921
Joined: 30 Sep 2013, 06:48

Re: reading "special" characters from a file

27 Mar 2020, 01:50

Hard to say from what I see, but it could be a timing issue (and the sends slow it down just a little).
But the actual problem might be in getUserInput().
GTM
Posts: 19
Joined: 24 Mar 2020, 18:44

Re: reading "special" characters from a file

27 Mar 2020, 02:24

So more digging, I had a misplaced default value that wasnt occuring if I didnt enter that parameter directly. A total oof where I had a set of function parameters backwards.. I cant even begin to understand how that happened or how it ever output anything,

Right now I am looking at this

Code: Select all

blockString is: 5TESTING/*
userInformation.definition is: 05
blockStringLen is: 9
last5Chars is: ING/*
User text: TESTING
Block Width: 80
Comment Char:  /*
End Char: */
Comment Definition: 05
;--------------------------------------------------
blockWidth: 80 : chars to fill out: 79
numOfCopies: 79 - extrasNeeded: 0
virginChunk[1] = _
lineOfChunks[chunksToMod[1]][chars] =
lineOfChunks[chunksToMod[2]][chars] =
;--------------------------------------------------
blockWidth: 80 : chars to fill out: 55
numOfCopiesLeft: 28 - numOfCopiesRight: 27
numOfCopies: 28 - extrasNeeded: 0
virginChunk[1] = %
numOfCopies: 27 - extrasNeeded: 0
virginChunk[1] = %
lineOfChunks[chunksToMod[1]][chars] =
lineOfChunks[chunksToMod[2]][chars] =
;--------------------------------------------------
blockWidth: 80 : chars to fill out: 79
numOfCopies: 79 - extrasNeeded: 0
virginChunk[1] = ‾
lineOfChunks[chunksToMod[1]][chars] =
lineOfChunks[chunksToMod[2]][chars] =
1:1 - 1:_
1:1 - 2:<rF>
1:1 - 3:1
1:1 - 4:<'_'rF>
2:1 - 1:%
2:1 - 2:<rH
2:1 - 3:1
2:1 - 4:<'%'rH
2:2 - 1:(
2:2 - 2:
2:2 - 3:2
2:2 - 4:'( '
2:3 - 1:T--E--S--T--I--N--G
2:3 - 2:s2
2:3 - 3:19
2:3 - 4:TESTING
2:4 - 1: )
2:4 - 2:
2:4 - 3:2
2:4 - 4:' )'
2:5 - 1:%
2:5 - 2:rH>
2:5 - 3:1
2:5 - 4:'%'rH>
3:1 - 1:‾
3:1 - 2:<rF>
3:1 - 3:1
3:1 - 4:<'‾'rF>
This is my code for this part of my project:

Code: Select all

expandAllLines(byRef chunkArray, blockWidth) {
        Loop, % chunkArray.maxindex() {
            send % ";--------------------------------------------------`r"
            expandChunks(chunkArray[A_index], blockWidth)
        }
    }

    expandChunks(byRef lineOfChunks, blockWidth)
    {
        charsRemain := blockWidth - sumOfChunks(lineOfChunks)
        chunksToMod := []
        send % "blockWidth: " blockWidth " : "
        send % "chars to fill out: " charsRemain "`r"
        Loop, % lineOfChunks.maxindex()
        {
            if (instr(lineOfChunks[A_index, 2], "rH") || instr(lineOfChunks[A_index, 2], "rF"))
            {
                chunksToMod.Push(A_index)
            }
        }
        if (chunksToMod.maxindex() > 2)
        {
            errorhandler(false, "Check configuration text file, invalid chunk paramters")
        }
        else if (chunksToMod.maxindex() == 1)
        {
            chunkExpander(lineOfChunks[chunksToMod[1]], charsRemain)
        }
        else if (chunksToMod.maxindex() == 2)
        {
            numOfCopiesLeft := ceil(charsRemain / 2)
            numOfCopiesRight := charsRemain - numOfCopiesLeft
            send % "numOfCopiesLeft: " numOfCopiesLeft " - numOfCopiesRight: " numOfCopiesRight "`r"
            chunkExpander(lineOfChunks[chunksToMod[1]], numOfCopiesLeft)
            chunkExpander(lineOfChunks[chunksToMod[2]], numOfCopiesRight)
        }
        send % "lineOfChunks[chunksToMod[1]][chars] = " lineOfChunks[chunksToMod[1]] "`r"
        send % "lineOfChunks[chunksToMod[2]][chars] = " lineOfChunks[chunksToMod[2]] "`r"
        Return true
    }

    chunkExpander(ByRef virginChunk, numCharsToExpandTo)
    {
        numOfCopies := floor(numCharsToExpandTo / virginChunk[3])
        extrasNeeded := Mod(numCharsToExpandTo, virginChunk[3])
        send % "numOfCopies: " numOfCopies " - extrasNeeded: " extrasNeeded "`r"
        charExpansion := virginChunk[1]
        ;Loop, % numOfCopies
        ;    charExpansion .= charExpansion
        ;charExpansion .= substr(virginChunk[1], 1, extrasNeeded)
        ;virginChunk[1] := charExpansion
        send % "virginChunk[1] = " virginChunk[1] "`r"

        return true
    }

    sumOfChunks(lineOfChunks)
    {
        sum := 0
        loop, % lineOfChunks.maxindex()
            sum += lineOfChunks[A_Index, 3]
        return sum
    }
    
expandAllLines is called from the main and multidim array and a value from the userinput is passed to it and it goes from there.
It is getting to chunkExpander and now its throwing a huge fit and blowing my memory up.

In the output above the numbers represent [line number][chunk number][values 1 to 4] It seems that somehow I am deleting the keys because theyre no longer displaying.

I have a hunch about what it might be, earlier I was trying to set one object to have keys I could reference, and no matter what my references didnt seem to work, but the objects maxindex was exactly what I imagined it to be, Long story short and a for loop later I discovered that it had the keyd indexes I created, but also the exact same number of integer indexes and maxindex() doesnt pick up on the keys.. so I literally spent probably 30 mins scratching my head trying different things to no avail..

Anyway.. I had the proper output before as can be seen here

Image

So I know that it can be done without memory leaks..

Anyway. I need to sleep.

Please Ill take any suggestions you have, Im really rough around the edhes with the whole objects thing and Ive never encountered it explained or presented in the same way it is here with autohotkey. I also dont understand when I should be declaring variables or not, and like even the class definition stuff everything Ive learned about and used and expect is there but its not.. its really confusing the hell out of me. And then its all like theyre just arrays bro, you can magically add any property you want. and im like well wheres the let/get/set definitions I gotta set up etc.. even when Ive read about it on here, the docs, the forum, its kinda presented and blown right through and Im kinda left like uhh so how does this work in this?? and the gist I get is it doesnt matter because you can just type in something and it will work.

idk please help

how can I minimize the memory load, its actually pretty insane. is it cause of the big array? honestly I never really used a 3 way multidim, it just kinda worked easy.. but I had the idea to create a class for each line, with its children being the "chunks" and then from there the chunks have their set of properties.. but in the end I guess thats just more arrays anyway so :cookie:
Last edited by gregster on 27 Mar 2020, 02:40, edited 1 time in total.
Reason: Image link fixed again. If you edit, it will break again.
GTM
Posts: 19
Joined: 24 Mar 2020, 18:44

Re: reading "special" characters from a file

27 Mar 2020, 02:43

oh shit I realized what I did...

I tried to make 2^99 characters :clap:

OOF

lmao
gregster
Posts: 8921
Joined: 30 Sep 2013, 06:48

Re: reading "special" characters from a file

27 Mar 2020, 02:44

Fyi, you can upload pictures to the forums via the Full editor > Attachments > Add files (> place inline).
But external image links will currently break for you, because you haven't enough posts yet (a moderator can fix the link, but each time you edit the specific post, it will break again.)
GTM
Posts: 19
Joined: 24 Mar 2020, 18:44

Re: reading "special" characters from a file

27 Mar 2020, 04:17

success!

Code: Select all

blockString is: 02TESTING123/*120
userInformation.definition is: 02
blockStringLen is: 15
last5Chars is: /*120
User text: TESTING123
Block Width: 120
Comment Char:  /*
End Char: */
Comment Definition: 02
;--------------------------------------------------
blockWidth: 120 : chars to fill out: 112
virginChunk[1] = lineOfChunks[chunksToMod.1][chars] = lineOfChunks[chunksToMod.2][chars] =
;--------------------------------------------------
blockWidth: 120 : chars to fill out: 113
virginChunk[1] = -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
lineOfChunks[chunksToMod.1][chars] = -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
lineOfChunks[chunksToMod.2][chars] =
;--------------------------------------------------
blockWidth: 120 : chars to fill out: 86
numOfCopiesLeft: 43 - numOfCopiesRight: 43
virginChunk[1] = @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
virginChunk[1] = @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
lineOfChunks[chunksToMod.1][chars] = @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
lineOfChunks[chunksToMod.2][chars] = @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;--------------------------------------------------
blockWidth: 120 : chars to fill out: 113
virginChunk[1] = -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
lineOfChunks[chunksToMod.1][chars] = -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
lineOfChunks[chunksToMod.2][chars] =
;--------------------------------------------------
blockWidth: 120 : chars to fill out: 112
virginChunk[1] = lineOfChunks[chunksToMod.1][chars] = lineOfChunks[chunksToMod.2][chars] =
1:1 - 1:  //
1:1 - 2:<
1:1 - 3:4
1:2 - 1:################################################################################################################
1:2 - 2:rF
1:2 - 3:1
1:3 - 1:\\
1:3 - 2:>
1:3 - 3:3
2:1 - 1: //
2:1 - 2:<
2:1 - 3:3
2:2 - 1:-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
2:2 - 2:rF
2:2 - 3:2
2:3 - 1:\\
2:3 - 2:>
2:3 - 3:2
3:1 - 1://
3:1 - 2:<
3:1 - 3:2
3:2 - 1:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
3:2 - 2:rH
3:2 - 3:1
3:3 - 1:T--E--S--T--I--N--G--1--2--3
3:3 - 2:s2
3:3 - 3:28
3:3 - 4:TESTING123
3:4 - 1:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
3:4 - 2:rH
3:4 - 3:1
3:5 - 1://
3:5 - 2:>
3:5 - 3:2
4:1 - 1:\\
4:1 - 2:<
4:1 - 3:2
4:2 - 1:-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
4:2 - 2:rF
4:2 - 3:2
4:3 - 1://
4:3 - 2:>
4:3 - 3:3
5:1 - 1: \\
5:1 - 2:<
5:1 - 3:3
5:2 - 1:################################################################################################################
5:2 - 2:rF
5:2 - 3:1
5:3 - 1://
5:3 - 2:>
5:3 - 3:4
These are the changes I made

Code: Select all

expandAllLines(byRef chunkArray, blockWidth) {
        Loop, % chunkArray.maxindex() {
            send % ";--------------------------------------------------`r"
            expandChunks(chunkArray[A_index], blockWidth)
            sleep, 200
        }
        returN True
    }

    expandChunks(byRef lineOfChunks, blockWidth)
    {
        charsRemain := blockWidth - sumOfChunks(lineOfChunks)
        chunksToMod := []
        send % "blockWidth: " blockWidth " : "
        send % "chars to fill out: " charsRemain "`r"
        Loop, % lineOfChunks.maxindex()
        {
            if (instr(lineOfChunks[A_index, 2], "rH") || instr(lineOfChunks[A_index, 2], "rF"))
            {
                chunksToMod.Push(A_index)
            }
        }
        chunksToModMaxIndex := chunksToMod.maxindex()
        switch chunksToModMaxIndex
        {
        Case >2: errorhandler(false, "Check configuration text file, invalid chunk paramters")
        Case 1: lineOfChunks[chunksToMod.1, 1] := chunkExpander(lineOfChunks[chunksToMod.1, 1], charsRemain)
        Case 2:
            numOfCopiesLeft := ceil(charsRemain / 2)
            numOfCopiesRight := charsRemain - numOfCopiesLeft
            send % "numOfCopiesLeft: " numOfCopiesLeft " - numOfCopiesRight: " numOfCopiesRight "`r"
            lineOfChunks[chunksToMod.1, 1] := chunkExpander(lineOfChunks[chunksToMod.1, 1], numOfCopiesLeft)
            lineOfChunks[chunksToMod.2, 1] := chunkExpander(lineOfChunks[chunksToMod.2, 1], numOfCopiesRight)
        Case 0: returN
        }
        send % "lineOfChunks[chunksToMod.1][chars] = " lineOfChunks[chunksToMod.1, 1] "`r"
        send % "lineOfChunks[chunksToMod.2][chars] = " lineOfChunks[chunksToMod.2, 1] "`r"
        chunksToMod := ""
        returN true
    }

    chunkExpander(virginChunkChars, numCharsToExpandTo)
    {
        while (strlen(virginChunkChars) < numCharsToExpandTo)
            virginChunkChars .= virginChunkChars
        virginChunkChars := substr(virginChunkChars, 1, numCharsToExpandTo)

            send % "virginChunk[1] = " virginChunkChars "`r"
        returN virginChunkChars
    }

    sumOfChunks(lineOfChunks)
    {
        sum := 0
        loop, % lineOfChunks.maxindex()
            sum += lineOfChunks[A_Index, 3]
        returN sum
    }
   
I added a slight sleep in expand all lines, and I also added a conditional to where its called because the next output function was running before expandalllines had completed. Just a simple if expandalllines(x,y) -> run other func since it wont go until it returns. removed the 4th index which was unnecessary, it just held the unmodified string.

created vars for frequently called things like maxindex. turned the ifs into a switch case. realized I didnt need to pass the string length to chunk expander and did away with the logic there. I thought I was being clever before but this is much simpler. so I removed the byref call in chunk expander as well, seems like it helps.

Id like to somehow get away from all the index loops, they seem excessive, and I think hey I must be able to store that info somewhere... :trollface:

Anyway its time to put all this together into some actual output :beer: :lol:

whats next...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 139 guests