store treevalues into array?

Get help with using AutoHotkey and its commands and hotkeys
drizzt
Posts: 31
Joined: 20 Apr 2018, 20:44

store treevalues into array?

18 Jun 2018, 19:42

I am using the below script from Jeeswg to get items from a tree view and write them to a file
however now I would like to put them into an array instead so I can later pick out certain values.
I have tried many different things but keep getting errors or blank arrays

Code: Select all

#Include Acc.ahk
#Include hasVal.ahk
q:: ;Notepad - get Acc info (window)
WinGet, hWnd, ID, A
MsgBox, % Clipboard := JEE_AccGetTextAll(hWnd, "`r`n")

;MyTable := []
;JEE_AccGetTextAll(hWnd, "`r`n")




;MyPoint :=MyTable[5]
;MsgBox, % MyPoint

return


;==================================================

JEE_StrRept(vText, vNum)
{
	if (vNum <= 0)
		return
	return StrReplace(Format("{:" vNum "}", ""), " ", vText)
	;return StrReplace(Format("{:0" vNum "}", 0), 0, vText)
}

;==================================================






JEE_AccGetTextAll(hWnd:=0, vSep:="`n", vIndent:="`t", vOpt:="")
{
	
		
	
	vLimN := 20, vLimV := 20
	Loop, Parse, vOpt, % " "
	{
		vTemp := A_LoopField
		if (SubStr(vTemp, 1, 1) = "n")
			vLimN := SubStr(vTemp, 2)
		else if (SubStr(vTemp, 1, 1) = "v")
			vLimV := SubStr(vTemp, 2)
	}
	
	oMem := {}, oPos := {}
	;OBJID_WINDOW := 0x0
	oMem[1, 1] := Acc_ObjectFromWindow(hWnd, 0x0)
	oPos[1] := 1, vLevel := 1
	VarSetCapacity(vOutput, 1000000*2)
	
	Loop
	{
		if !vLevel
			break
		if !oMem[vLevel].HasKey(oPos[vLevel])
		{
			oMem.Delete(vLevel)
			oPos.Delete(vLevel)
			vLevelLast := vLevel, vLevel -= 1
			oPos[vLevel]++
			continue
		}
		oKey := oMem[vLevel, oPos[vLevel]]
		
		vName := "", vValue := ""
		
		
		
		if IsObject(oKey)
		{
			vRoleText := Acc_GetRoleText(oKey.accRole(0))
			try vName := oKey.accName(0)
			try vValue := oKey.accValue(0)
			try vPos :=Acc_Location(oKey)
			
			
			
			
			
		}
		else
		{
			oParent := oMem[vLevel-1,oPos[vLevel-1]]
			vChildId := IsObject(oKey) ? 0 : oPos[vLevel]
			vRoleText := Acc_GetRoleText(oParent.accRole(vChildID))
			try vName := oParent.accName(vChildID)
			try vValue := oParent.accValue(vChildID)
			
			
				;;;;;;;;
			
			
			
			;oAcc2:=Acc_ObjectFromEvent(vChildID,Hwnd,))
			oRect := Acc_Location(oParent, vChildId)
			vAccLocation := Format("X{} Y{} W{} H{}", oRect.x, oRect.y, oRect.w, oRect.h)
			
			
			
			if (vValue >=0)
				MyTable[oKey] := {"my location": vAccLocation, "my name": vName, "value": vValue, "pos": vPos, "okey": oKey}
			
			if (vValue >=0)
				FileAppend,
			(
			
			mylocationis %vAccLocation%
			mynameis %vName%
			myvalueis %vValue%
			myposis %vPos%
			myokeyis %oKey%
			
			
			
			), File.txt
			;;;;;;;;
			
			
			
			
			
			
		}
		
		
		
		
		if (StrLen(vName) > vLimN)
			vName := SubStr(vName, 1, vLimN) "..."
		if (StrLen(vValue) > vLimV)
			vValue := SubStr(vValue, 1, vLimV) "..."
		vName := RegExReplace(vName, "[`r`n]", " ")
		vValue := RegExReplace(vValue, "[`r`n]", " ")
		
		
		
		
		
		
		
		vAccPath := ""
		if IsObject(oKey)
		{
			Loop, % oPos.Length() - 1
				vAccPath .= (A_Index=1?"":".") oPos[A_Index+1]
		}
		else
		{
			Loop, % oPos.Length() - 2
				vAccPath .= (A_Index=1?"":".") oPos[A_Index+1]
			vAccPath .= " c" oPos[oPos.Length()]
		}
		if (vValue >1)		
			vOutput .= vAccPath "`t" JEE_StrRept(vIndent, vLevel-1) vRoleText " [" vName "][" vValue "]" "][" vAccLocation "]"vSep
		
		oChildren := Acc_Children(oKey)
		if !oChildren.Length()
			oPos[vLevel]++
		else
		{
			vLevelLast := vLevel, vLevel += 1
			oMem[vLevel] := oChildren
			oPos[vLevel] := 1
		}
	}
	
	
	return SubStr(vOutput, 1, -StrLen(vSep))
}
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: store treevalues into array?

18 Jun 2018, 19:55

Probably something like this:

Code: Select all

q:: ;CRLF-delimited list to linear array
vText := "a`r`nb`r`nc"
oArray := StrSplit(vText, "`r`n")
vOutput := ""
for vKey, vValue in oArray
	vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], boiler, djuga, Google [Bot] and 44 guests