Jump to content

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

Case sensitive variables possible?


  • Please log in to reply
13 replies to this topic
Richsm
  • Members
  • 11 posts
  • Last active: Jan 01 2011 05:42 AM
  • Joined: 09 Aug 2010
I have a large set of data with two letters (case sensitive) that are associated with a name. Is there any way to assign these variables so that they are case sensitive?

; Example Data:
aB = Name 1
bF = Name 2
AB = Name 3

MsgBox, %aB% %bF% %AB%
; Displays Name 3 Name 2 Name 3
Thanks!

TodWulff
  • Members
  • 142 posts
  • Last active: Sep 15 2013 04:16 PM
  • Joined: 29 Dec 2007
Interesting question (Thinking out loud here).

I suspect that if you do up a couple of function to assign and get contents to/from a variable, and pass the var name as a parameter (possibly byref?), that maybe you could change the internal storage representation of the variable name to it's ASCII equiv:

i.e. var name aB could become V_9766 and var name AB could become V_6566?

Just a thought of how I might attempt to approach that...

-t
When replying, please feel free to address me as Tod. My AHK.net site...

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
Realistically, no.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Ditto to what Leef_me said. AHK is designed to be case-insensitive. One possibility would be to use a Scripting.Dictionary object (example requires AutoHotkey_L):
sd := ComObjCreate("Scripting.Dictionary")
sd.item("aB") := "Name 1"
sd.item("AB") := "Name 3"
MsgBox, % sd.item("aB") "`n" sd.item("AB")

More importantly, what can Scripting.Dictionary do that the built-in objects can't do?

:wink: - case sensitive keys

girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
Look at this command to see if it could be used to handle the case sensitivity that you need.

StringCaseSense, On ;would technically solve that problem for you.

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
StringCaseSense has nothing to do with variable names.

girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
Lexikos: Maybe i'm reading his post incorrectly, and if so I sincerely apologize, But I'm seeing the problem isn't the variables but the 2 letter case sensitive data that is associated with the names which need to be uniquely stored. Each 2 letter combination can map to one of 4 possible states AA, Aa, aA, and aa. By reading the data in from a file using case sensitivity to compare it's state, and preconditioning the data with a state number 1-4 before storing in memory, the data could be entirely defined as being in one of the 4 possible states for any given 2-letter combination. If you think strictly of the case sensitivity as being a variable only issue then yes AHK is case insensitive and the problem remains. What I'm hearing is that he needs to be able to store them uniquely in memory and retrieve them with their original state preserved. A state number based on a case sensitive comparison during a read from file could possibly do that. Decoding the data would be simply a matter of reading the letter combination and selecting the appropriate response based on the data and it's state value.

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif


purloinedheart
  • Members
  • 538 posts
  • Last active: Sep 22 2014 09:35 PM
  • Joined: 04 Apr 2008
There are lots of possible workarounds.

ie
var(,"a","Contents of var a")
var(,"A","Contents of var A")

Msgbox % var(1, "a")
Msgbox % var(1, "A")


Var(action=0, variable="", content=""){
Static
If !action ;Store value
 {
  Count++
  Var%Count% := variable "_" content
 }
else if action = 1 ;Retrieve value
 {
  Retrieved =
  Loop % Count
   {
     if (SubStr(Var%A_Index%, 1, InStr(Var%A_Index%,"_")-1) == variable)
      {
       Retrieved := SubStr(Var%A_Index%, InStr(Var%A_Index%,"_")+1)
       return Retrieved
      }
    }
 }
}

However, I'm fairly sure it would be impossible (or very difficult) to initialize a variable through AHK normally and be able to tell the original case.

Eedis
  • Members
  • 1775 posts
  • Last active: Aug 14 2015 06:33 PM
  • Joined: 12 Jun 2009
Just curious, what is so important that you need case sensitive variables? In any script, you can use "thisismytotallyawesomeyetextremelylongandhardtoreadvariablename" as a variable and it'd work.

If you told us the reason behind needing this, maybe we can approach this from a completely different angle and solve it with some other method.
AutoHotkey state, the forum, Poly, and Drainx1. The short story.
I love my wife, my life, my atomic-match; for giving me the greatest gift a man could ask for, such a perfect and beautiful little girl.
9rjbjc.png

dysmas
  • Members
  • 63 posts
  • Last active: Apr 06 2011 11:01 AM
  • Joined: 28 Dec 2010
Have a look at the answer of a4u to my question in the post How make Associative array keys case sensitive
I think your problem is exactly the same as mine. Here is my full test code (including the two solutions tested, which both work fine) :

#w::

    a1 := "ae"
    a2 := "AE"

    sd := ComObjCreate("Scripting.Dictionary")
    sd.item(a1) := "æ"
    sd.item(a2) := "Æ"
    MsgBox, % sd.item(a1) "`n" sd.item(a2)
    
    
    array := CSobj()
    array[a1] := "æ"
    array[a2] := "Æ"
    MsgBox, % array["ae"] "`n" array["AE"]
    
    for k,v in array
       t .= k " : " v "`n"
    MsgBox, %t%


CSobj() {
   static base := object("_NewEnum","__NewEnum", "Next","__Next", "__Set","__Setter", "__Get","__Getter")
   return, object("__sd_obj__", ComObjCreate("Scripting.Dictionary"), "base", base)
}
   __Getter(self, key) {
      return, self.__sd_obj__.item(key)
   }
   __Setter(self, key, value) {
      self.__sd_obj__.item(key) := value
      return, false
   }
   __NewEnum(self) {
      return, self
   }
   __Next(self, ByRef key = "", ByRef val = "") {
      static Enum
      if not Enum
         Enum := self.__sd_obj__._NewEnum
      if Not Enum[key], val:=self[key]
         return, Enum:=false
      return, true
   }


return


Richsm
  • Members
  • 11 posts
  • Last active: Jan 01 2011 05:42 AM
  • Joined: 09 Aug 2010
Well, I don't think any of these suggestions will help in my case. Besides, I was hoping for more of a simple solution.

Here's an example of my code:
Output = %A_ScriptDir%\Output.csv
XMLFile = %A_ScriptDir%\Input.xml
CodeCount = 0

Loop, read, %XMLFile%
{
	IfInString, A_LoopReadLine, <item name=
		IfInString, A_LoopReadLine, type="type"
		{
			RegExMatch(A_LoopReadLine, "(?<=name="")\w+", Name)
			RegExMatch(A_LoopReadLine, "(?<=code="")\w+", Code)
		}

	If (Name and Code)
	{
		IfNotInString, A_LoopReadLine, </item> ; Not reached end of Item, continue
		{
			IfInString, A_LoopReadLine, <next> ; Next Code
				RegExMatch(A_LoopReadLine, "(?<=\<next\>)\w+", NextCode)
		}
		Else
		{
			If (Name and Code and NextCode)
			{
				CodeCount += 1
				NameList%CodeCount% := Name
				CodeList%CodeCount% := NextCode
				name%Code% := Name
			}
			Name = 0
			NextCode = 0
		}
	}
}
Loop, %CodeCount% ; Output to CSV
{
	iName := NameList%A_Index%
	iNextCode := CodeList%A_Index%
	iNextName := name%iNextCode%
	FileAppend, %iName%`,%iNextName%`n, %Output%
}
Problem is name%Code% creates several variables which are case sensitive (because the items in the XML are case sensitive). Maybe there is a different way to do this that bypasses the whole case sensitivity issue?

a4u
  • Guests
  • Last active:
  • Joined: --

Problem is name%Code% creates several variables which are case sensitive

As stated above, you could use a scripting.dictionary object (example uses AutoHotkey_L, but could easily be modified for AHK Basic):
Output = %A_ScriptDir%\Output.csv

XMLFile = %A_ScriptDir%\Input.xml

CodeCount = 0

[color=darkred]name := ComObjCreate("Scripting.Dictionary")[/color]



; ....................



            ; name%Code% := Name

            [color=darkred]name.item(Code) := Name[/color]

         }

         Name = 0

         NextCode = 0

      }

   }

}

Loop, %CodeCount% ; Output to CSV

{

   iName := NameList%A_Index%

   iNextCode := CodeList%A_Index%

   ; iNextName := name%iNextCode%

   [color=darkred]iNextName := name.item(iNextCode)[/color]

   FileAppend, %iName%`,%iNextName%`n, %Output%

}


dysmas
  • Members
  • 63 posts
  • Last active: Apr 06 2011 11:01 AM
  • Joined: 28 Dec 2010

; name%Code% := Name
name.item(Code) := Name


or, if you use the "long" version, the one a4u wrote for me in the post I mentioned, then you would have the syntax :


name[code=auto:0] := Name

Which is fine.
You have just to paste the functions in the beginning of your code.

Richsm
  • Members
  • 11 posts
  • Last active: Jan 01 2011 05:42 AM
  • Joined: 09 Aug 2010
Thanks!

Much appreciated, you guys are great.