This code doesn't work the way I want:
words := {}
words["who"] := "an English pronoun"
words["WHO"] := "World Trade Organization"
msgbox % words["who"] ; shows "World Trade Organization" instead of "an English pronoun"
because the system seems to make no difference between "who" and "WHO" considering them to be one and the same key of the object. Is there any way to make the keys in objects case-sensitive?
How to make keys in objects case-sensitive?
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: How to make keys in objects case-sensitive?
Plain vanilla objects do not support case sensitive keys but you can use a COM Dictionary object if you want case sensitive keys.
The syntax is a little different but you can probably do what you want with a COM object.
FG
Code: Select all
words := ComObjCreate("Scripting.Dictionary")
words.item("who") := "an English pronoun"
words.item("WHO") := "World Trade Organization"
MsgBox % words.item("WHO")
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: How to make keys in objects case-sensitive?
Re-post (guest posting messes the formatting):
You can wrap Scripting.Dictionary in a class to use it with AHK syntax:
You can wrap Scripting.Dictionary in a class to use it with AHK syntax:
Code: Select all
class Dict
{
__New(p*) {
this.Insert("_", ComObjCreate("Scripting.Dictionary"))
Loop % p.MaxIndex()//2
this[p[A_Index*2-1]] := p[A_Index*2]
}
__Call(m, p*) {
if m in % "
(LTrim Join,
Add
Exists
Item,Items
Key,Keys
Remove,RemoveAll
)"
return (this._)[m](p*)
}
__Set(k, v, p*) {
if (k = "base" || k = "__Class")
goto bypass_set
else if (k == "CompareMode")
return this._[k] := v
else if this.Exists(k)
return this._.Item(k) := v
else return this.Add(k, v)
bypass_set:
}
__Get(k, p*) {
if (k = "base" || k = "__Class")
goto bypass_get
else if k in Count,CompareMode
return this._[k]
else if this.Exists(k)
return this.Item(k)
bypass_get:
}
_NewEnum() {
return new this.base.Enum(this)
}
class Enum
{
__New(obj) {
this.obj := obj
this.enum := obj._._NewEnum()
}
Next(ByRef k, ByRef v:="") {
if (r:=this.enum.Next(k, v))
v := (this.obj)[k]
return r
}
}
}
d := new Dict("who", "an English pronoun", "WHO", "World Trade Orgaization")
d.Who := "Dr. Who"
for k, v in d
MsgBox %k% = %v%
return
Re: How to make keys in objects case-sensitive?
deleted errored post
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
Re: How to make keys in objects case-sensitive?
- Thank you FanaticGuru for this code, but something is wrong. I tried to run it and it doesn't work.FanaticGuru wrote:...you can use a COM Dictionary object if you want case sensitive keys.
Code: Select all
words := ComObjCreate("Scripting.Dictionary") words.item("who") := "an English pronoun" words.item("WHO") := "World Trade Organization" MsgBox % words.item("WHO")
- What is a plain vanilla object?FanaticGuru wrote:Plain vanilla objects do not support case sensitive keys
Re: How to make keys in objects case-sensitive?
- Thank you Coco! Your script works just fine. I am studying it at the moment. Class is something that I know almost nothing about. It is both intimidating and very much attractive to me :)Coco wrote:You can wrap Scripting.Dictionary in a class to use it with AHK syntax...
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: How to make keys in objects case-sensitive?
Strange that the code does not work for you. It works fine for me. Do you have the newest version of AHK?Benny-D wrote:- Thank you FanaticGuru for this code, but something is wrong. I tried to run it and it doesn't work.FanaticGuru wrote:...you can use a COM Dictionary object if you want case sensitive keys.
Code: Select all
words := ComObjCreate("Scripting.Dictionary") words.item("who") := "an English pronoun" words.item("WHO") := "World Trade Organization" MsgBox % words.item("WHO")
- What is a plain vanilla object?FanaticGuru wrote:Plain vanilla objects do not support case sensitive keys
http://ahkscript.org/download/
As for plain vanilla object, that is not a technical term just me referring to the basic object like you were trying. COM objects are more like chocolate, not as common but a little more fancy and interesting.
Coco's class uses the same COM object but just adds some sugar to the syntax (that IS a semi-technical term). It is some pretty sweet sugar by the way. Thanks Coco!
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: How to make keys in objects case-sensitive?
- Mine is 1.1.14.03FanaticGuru wrote:Strange that the code does not work for you. It works fine for me. Do you have the newest version of AHK?
- Ah, I see. Thank you.FanaticGuru wrote:As for plain vanilla object, that is not a technical term just me referring to the basic object like you were trying
- :)FanaticGuru wrote:COM objects are more like chocolate, not as common but a little more fancy and interesting. Coco's class uses the same COM object but just adds some sugar to the syntax (that IS a semi-technical term). It is some pretty sweet sugar by the way
Who is online
Users browsing this forum: Google [Bot], scriptor2016 and 275 guests