Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Why use AutoHotkey_L? Ask Questions Here...


  • Please log in to reply
128 replies to this topic
sbc
  • Members
  • 321 posts
  • Last active: Jun 07 2011 10:24 AM
  • Joined: 25 Aug 2009

The third param of Loop-parse needs to be a variable, not an object value.

So a variable's value and an object property value are two different things. This is something new to me. Thanks jethrow.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Obj["list"] is an expression; it is an instruction to retrieve the property "list" from the object Obj. It is clearly not a variable. It might help to think of it in terms of a function-call (which incidentally is how the expression parser represents it): ObjGet(Obj, "list").

On a related note:

InputVars: Possibly get rid of the concept of an InputVar by allowing percent signs around such variables:

Loop, Parse, InputVar
Loop, Parse, %InputVar%
(However, obvious arrays such as Array%i% should still be recognized.) Although this would break some existing scripts and reduce flexibility, it might be worth it because Input Variables have been cited as a source of confusion by me and others because they deviate in counterintuitive, seemingly haphazard ways from the practice of enclosing vars in percent signs.

Laszlo: InputVars: E.g. in <Loop, Parse, InputVar> it was more logical to allow any expression in place of InputVar. A variable is still valid, but we could have literal strings in quotes, too. <Loop, Parse, %InputVar%> would mean a 2-level dereference, which is rarely used.

Source: AutoHotkey v2

Allowing InputVar to be an expression as per Laszlo's suggestion would make your code work. It should not break any existing scripts, so could be implemented before or after v2.

sbc
  • Members
  • 321 posts
  • Last active: Jun 07 2011 10:24 AM
  • Joined: 25 Aug 2009

Obj["list"] is an expression

This makes it clear. Thanks.

It might help to think of it in terms of a function-call (which incidentally is how the expression parser represents it): ObjGet(Obj, "list").

I get "Error: Call to nonexistent function" with ObjGet(). Is it an internal hidden function of some sort that users don't have to use or know about? I could not find relavant information that helps me understand what it is.

AHK_L Change Log[/url]":3nolkj5e]a.b.c[d] is equivalent to ObjGet(a.b,"c",d) and x.y[z]:=v is equivalent to ObjSet(x,"y",z,v)

Default Base
When a non-object value is used with object syntax or passed to ObjGet, ObjSet or ObjCall, the default base object is invoked.


Allowing InputVar to be an expression as per Laszlo's suggestion would make your code work. It should not break any existing scripts, so could be implemented before or after v2.

Sounds great. I look forward to it. :)

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

I get "Error: Call to nonexistent function" with ObjGet().

I said "think", not "execute".

Is it an internal hidden function of some sort that users don't have to use or know about?

Yes, but that's beside the point. It is evaluated like a function-call. It may even ultimately result in a function-call, depending on the object.

I could not find relavant information that helps me understand what it is.

If you understand what a function-call is, that should be sufficient.

sbc
  • Members
  • 321 posts
  • Last active: Jun 07 2011 10:24 AM
  • Joined: 25 Aug 2009

If you understand what a function-call is, that should be sufficient.

list := "a,b,c,d,e"
Loop, Parse, SubStr(list, 5), `,
   out .= A_LoopField "`n"
msgbox % out
Is the part in this case SubStr(list, 5) a function call or is the term more specific to objects?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
It's a function call... :?

<!-- m -->http://www.autohotke...s/Functions.htm<!-- m -->

sbc
  • Members
  • 321 posts
  • Last active: Jun 07 2011 10:24 AM
  • Joined: 25 Aug 2009

It's a function call... :?

Oh, I got it. Thank you. (I'm terrible at terminologies.)

file man
  • Guests
  • Last active:
  • Joined: --
Let's say that I have txt file in UTF-8 format like this:

This is first line.
This is second line.
Thie is third line.
... etc. up to 50000 lines.

Now let's say I just want to change second line from this:

This is second line.

to that:

This is 2. line.

and leave other lines as they are.

Currently, i would use this method which is slow and inefficient;
FileRead, FileText, C:\Some file.txt

Loop, parse, FileText, `n, `r
{
	if A_Index = 2
	New_FileText .= "This is 2. line.`n"		; modified line
	else
	New_FileText .= A_loopField "`n"		; leave as is
}

FileDelete, C:\Some file.txt
FileAppend, %New_FileText%, C:\Some file.txt, UTF-8
Is there some better method to do that job in AHK_L? Like;
> use that File Object (file := FileOpen(Filename, Flags [, Encoding])),
> move file pointer to second line (File.Seek),
> delete just that line (what command???),
> write new line(File.Write(String)), and
> save & close file (File.Close()) (without modifying other lines.)

Or something else? Please help. Method above is really slow and inefficient.

file man
  • Guests
  • Last active:
  • Joined: --
I hope you understand what's my point.
If my file is

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
... etc.

and all I want to do is to modify just one little part:

xYxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
... etc.

It's silly to rewrite whole giant file just because of one little modification.
I hope there is a way just to change that little part on hard disk, and leave other as is.

a4u
  • Guests
  • Last active:
  • Joined: --
As long as the new text length is <= the one text being replaced, you could do this:
str := [color=#666666]"This is 2. line."[/color]



File := [color=#107095]FileOpen[/color]([color=#666666]"File.txt"[/color], [color=#666666]"rw`n"[/color])

File.ReadLine()

pos := File.pos

[color=#107095]Loop[/color], % [color=#107095]StrLen[/color](File.ReadLine()) - [color=#107095]StrLen[/color](str) - 1

	pad .= [color=brown]A_Space[/color]

File.pos := pos

File.WriteLine(str . pad)

File.Close()


file man
  • Guests
  • Last active:
  • Joined: --
what if new text length is > text being replaced?

a4u
  • Guests
  • Last active:
  • Joined: --
I don't know of a way to do a text insert & move the rest of the data back, so I'd just read & rewrite it:
str := [color=#666666]"what if new text length is > text being replaced?"[/color] 



File := [color=#107095]FileOpen[/color]([color=#666666]"File.txt"[/color], [color=#666666]"rw`n"[/color]) 

File.ReadLine() 

pos := File.pos 

File.ReadLine()

data := File.Read()

File.pos := pos 

File.WriteLine(str)

File.Write(data)

File.Close()


file man
  • Guests
  • Last active:
  • Joined: --
Ok. Thanks.

cmulcahy
  • Members
  • 17 posts
  • Last active: Apr 06 2012 05:26 PM
  • Joined: 02 Nov 2010
I read the thread, know the difference in string encoding but seem to NOT know how to resolve this issue.

Using Winsock2.ahk for sending email. It was working. Upgraded to Autohotkey_L and it's not working. Seems the strings being passed in are getting mangled. It's likely the DLLCall in __WinINet_InternetCrackURL

Anyone have a solution?

Thanks

a4u
  • Guests
  • Last active:
  • Joined: --
See: COnverting Script to AHK_L - specifically AHKsock - A simple AHK implementation of Winsock (TCP/IP)