Assign values to variable named by 2nd field

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
walfredo
Posts: 21
Joined: 22 May 2014, 19:32

Assign values to variable named by 2nd field

26 May 2014, 11:09

Hello,
I am trying to parse a variable that contains 2 columns. It's called FacList and looks list this:
FacID|DelRt
160|LCL
166|TMP
200|PRPL
201|PRPL
202|PRPL
203|PRPL
etc.
Spoiler
I am trying to use this list to create variables named by the 2nd column, and a unique value list for a user to select later on to call on those values.
i.e.
User selects from Gui, Add, ListBox, Multi vDelChoice, %DelRtList%
Where DelRtList is all the unique values obtained from column 2, delimited by |
and I can collect all the FacID's that were associated with those DelRt's chosen by the user.
e.g. They choose PRPL, FBLCK, and FELPA and I get
40
41
42
43
200
201
202
203
93
91
97

Which I will then use for selecting items from a different program's listbox, but that part I can figure out.

I'm pulling the FacList from a MSSQL DB using ADOSQL(), and can control the delimiter, if that matters. So I guess I can just pull the DelRt's unique fields with SELECT DISTINCT, create the listbox for the user with those values, then hit up the SQL DB again using WHERE DelRt is in %DelRtList%, but I'd like to do only one query to the SQL DB, if possible. I'm sure there is a solution using loops and stringsplits but I am having a hard time wrapping my brain around them.
User avatar
jigga
Posts: 93
Joined: 24 Jan 2014, 00:31

Re: Assign values to variable named by 2nd field

26 May 2014, 11:16

If i understand what you want to do correctly, you could make an array containing the other values, then use AltSubmit in your listbox (user's choice is the index instead of the value) and sync up the user's choice with the corresponding value from the array.
walfredo
Posts: 21
Joined: 22 May 2014, 19:32

Re: Assign values to variable named by 2nd field

26 May 2014, 12:08

jigga wrote:If i understand what you want to do correctly, you could make an array containing the other values, then use AltSubmit in your listbox (user's choice is the index instead of the value) and sync up the user's choice with the corresponding value from the array.
I'd like the listbox to only consist of
LCL
TMP
PRPL
FELPA
FBLCK
FORAN
TMP
BLU
YLW
STT
So are you saying that 1 would be LCL, 2 would be TMP, etc? How do I associate "1" with all the LCL FacID's? I've never touched arrays in the new AHK; I didn't even know they existed like that until now.
User avatar
jigga
Posts: 93
Joined: 24 Jan 2014, 00:31

Re: Assign values to variable named by 2nd field

26 May 2014, 12:15

Have your listbox elements like this: LCL|TMP|PRPL etc etc

Then make an array like this:

Code: Select all

myArray := ["160", "166", "200", etc etc]
When the user selects an item in your listbox (must have altsubmit), the listbox's variable will be the index of the list. So if they pick item 2:

Code: Select all

selection := myArray[DelChoice]
selection would = "166"
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Assign values to variable named by 2nd field

26 May 2014, 12:30

Spoiler
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Assign values to variable named by 2nd field

26 May 2014, 12:39

more music and less talk! tested and hit the spot! :lol: :geek:
AlphaBravo wrote:
Spoiler
walfredo
Posts: 21
Joined: 22 May 2014, 19:32

Re: Assign values to variable named by 2nd field

26 May 2014, 12:44

jigga wrote:Have your listbox elements like this: LCL|TMP|PRPL etc etc

Then make an array like this:

Code: Select all

myArray := ["160", "166", "200", etc etc]
When the user selects an item in your listbox (must have altsubmit), the listbox's variable will be the index of the list. So if they pick item 2:

Code: Select all

selection := myArray[DelChoice]
selection would = "166"
Thanks. But one of their choices can contain multiple FacID's. When they select #2 on the list, TMP, it needs to = 166, 53, 55, 61, etc.
User avatar
jigga
Posts: 93
Joined: 24 Jan 2014, 00:31

Re: Assign values to variable named by 2nd field

26 May 2014, 12:48

walfredo wrote: Thanks. But one of their choices can contain multiple FacID's. When they select #2 on the list, TMP, it needs to = 166, 53, 55, 61, etc.

Oh... So when they choose 'TMP' it would show all values that match TMP? I'm not following :(
walfredo
Posts: 21
Joined: 22 May 2014, 19:32

Re: Assign values to variable named by 2nd field

26 May 2014, 13:00

AlphaBravo wrote:
Spoiler
Thank you! I actually almost got to that point on my own with stringtrimleft. My greater concern is the creation of the variables named TMP, LCL, etc. that will contain the FacID associated with them. I was thinking it should be something like:

Code: Select all

loop, parse, FacilityList, `n, `r
{
    if A_Index=1
        continue
    StringSplit, field, A_LoopField, |
    %field2% .= field1 `n
}
But that just gives me an error.

jigga wrote:
walfredo wrote: Thanks. But one of their choices can contain multiple FacID's. When they select #2 on the list, TMP, it needs to = 166, 53, 55, 61, etc.
Oh... So when they choose 'TMP' it would show all values that match TMP? I'm not following :(
Yessir.
User avatar
jigga
Posts: 93
Joined: 24 Jan 2014, 00:31

Re: Assign values to variable named by 2nd field

26 May 2014, 13:05

Code: Select all

loop, parse, FacilityList, `n, `r
{
    if A_Index=1
        continue
    StringSplit, field, A_LoopField, |
    field2 .= field1 "`n"
}
walfredo
Posts: 21
Joined: 22 May 2014, 19:32

Re: Assign values to variable named by 2nd field

26 May 2014, 13:20

jigga wrote:

Code: Select all

loop, parse, FacilityList, `n, `r
{
    if A_Index=1
        continue
    StringSplit, field, A_LoopField, |
    field2 .= field1 "`n"
}
My fault. I'm not very articulate.
That seems to just concatenate the two fields over and over.

I want the first loop to create a variable LCL which assigned the value of field1 (in this case, 160).

2nd loop creates var named TMP with a value of 166

3rd loop creates var named PRPL with a value of 200

4th loop appends 201 to PRPL so now
PRPL =
200
201

5th loop appends 202 to PRPL so now
PRPL =
200
201
202

5th loop appends 203 to PRPL so now
PRPL =
200
201
202
203

6th loop creates a var named FORAN and assigns a value of 270

7th loop appends 221 to FORAN so now
FORAN =
270
221

I can manually break up this list myself and be done with it, but I want the script to grow with the program. Within the program/DB I am working with, there could for example be an addition of 5 new FacID's across 2 DelRt's. I begin the script with a query that pulls all the FacID's and the DelRt's that they are grouped into.
Last edited by walfredo on 26 May 2014, 13:25, edited 1 time in total.
User avatar
jigga
Posts: 93
Joined: 24 Jan 2014, 00:31

Re: Assign values to variable named by 2nd field

26 May 2014, 13:24

Code: Select all

loop, parse, FacilityList, `n, `r
{
    if A_Index=1
        continue
    StringSplit, field, A_LoopField, |
    %field2% = %field2%`n%field1%
}
walfredo
Posts: 21
Joined: 22 May 2014, 19:32

Re: Assign values to variable named by 2nd field

26 May 2014, 13:35

jigga wrote:

Code: Select all

loop, parse, FacilityList, `n, `r
{
    if A_Index=1
        continue
    StringSplit, field, A_LoopField, |
    field2 .= field1 "`n"
}
Got it! Thanks for y'alls help.

Code: Select all

loop, parse, FacList, `n, `r
{
    if A_Index=1
        continue
    StringSplit, field, A_LoopField, |
    list .= (list?"|":"") field2
    %field2% .= field1 "`n"
}
Sort, list, UD|

MsgBox % list
Msgbox % LCL
Msgbox % TMP

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 266 guests