Comparing large list of strings to user input

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MikeyG12
Posts: 30
Joined: 03 May 2018, 14:21

Comparing large list of strings to user input

14 Nov 2018, 14:47

Hello Generous Helpers!

I have a situation where I need to take a users input (a serial number) and compare the first 5 character to a huge (500 items) list and display the model of the device based on the users input. I wanted to know if there was an 'easy' way to compare a huge list of strings to the input. I have the list of serial number prefix's in an excel doc but I want the data to live in the code and not as a separate doc and I know that I can concatenate using Excel to quickly edit the list so that I can just copy and paste it into my AHK editor but I need to know what the format of the code should look like as I would rather not have to go back and edit 500 lines of code by hand. Basically is there some sort of repetitive format I can use like
If user input equals ABC123 then variable equals "Your device is blahblahblah"
If user input equals XYZ987 then variable equals "Your device is blahblahblah"
ect #500Times

If I can make Excel do the heavy lifting by concatenating the code before I copy and paste it that would be ideal. Any assistance in this would be ideal. I reviewed the Help section in AutoHotKey but I didn't find anything helpful so I figured I'd reach out here.
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Comparing large list of strings to user input

14 Nov 2018, 17:53

Code: Select all

; if you put all lines under one continuation section you'll get "expression to long"
; break it down like so (50 lines a piece or so)
data1 =
(
a:aaaa
b:bbbb
c:cccc
d:dddd
)

data2 =
(
e:eeee
f:ffff
g:gggg
h:hhhh
)

oData := []

loop, 2	; 2 = number of data sections above
	loop, parse, data%A_Index%, `n, `r
	{
		x := StrSplit(A_LoopField, ":")
		oData[x.1] := x.2
	}
	
MsgBox % oData["a"]
MsgBox % oData["h"]
return

F1::
InputBox, var
MsgBox % oData[var]
return
oif2003
Posts: 214
Joined: 17 Oct 2018, 11:43
Contact:

Re: Comparing large list of strings to user input

14 Nov 2018, 19:15

You can append the data to the end of your script after /* (block comment) and parse the script file to read them in as variables. See example with 1k rows (2 columns copied directly from Excel).
Note: this is for AutoHotkey v2.

Code: Select all

#SingleInstance

gui := GuiCreate()
editBox := gui.Add("Edit", "w600")
dispBox := gui.Add("Edit", "r20 w600 readonly -wrap -vscroll")
editBox.onEvent("Change", () => editBoxChanged())
gui.show()

label := "/* my list of stuff starts here"
script := fileRead(A_ScriptFullPath)
startpos := InStr(script, label, , -1)

data := {}
loop Parse SubStr(script, startpos + StrLen(label)) , "`n" {
	row := StrSplit(A_LoopField, "`t")
	if row[1] != "" && row[2] != ""
		data[row[1]] := row[2]
}

editBoxChanged() {
	global editBox, dispBox, gui, data
	dispBox.Value := ""
	matchedCount := 0
	len := StrLen(editBox.Value)
	for k, v in data {
		if matchedCount > 19 
			return
		if SubStr(k, 1, len) == editBox.Value {
			dispBox.Value .= k ":" v "`n"
			matchedCount++
		}
	}
}
	

/* my list of stuff starts here
58132	3585379
74426	4805209
74601	6294755
85177	5123003
335	9919741
63904	5592403
2395	6605401
26722	6022079
48392	4866759
86742	736956
22463	3804520
15188	4529171
95136	9696121
84665	461645
51079	5804588
83683	7719897
79907	3985180
44246	3501426
99489	8608137
15659	1589892
36460	6790731
30456	8623794
13899	3044623
42821	2445618
92425	9962661
3809	1955843
44721	4817214
64769	5830473
49123	178184
15651	836042
18586	8950735
35948	8840705
91600	9177471
25044	8123175
6611	267800
12522	7212570
26076	3237035
15887	1627833
73409	5634596
7349	542268
61254	3866260
82971	2563704
10579	749171
83566	5110985
6295	3291795
84709	129252
76473	325488
15230	7514377
54436	5101923
18179	9846148
33827	9893086
95364	1118679
67334	1403882
44271	6291407
80389	4173296
18347	4433795
8711	2088848
68779	7731869
62872	6348559
98084	3692359
95331	2162658
33183	2219273
73180	5699300
21443	7747876
75696	3628617
81636	8077517
88926	7158830
38453	509255
35403	3645139
44321	2153370
37832	9103137
96702	6359243
81495	8427297
16172	6541879
28745	2207439
48041	9923160
21085	8705441
7467	6307898
27922	7735810
14904	8151428
94841	4598183
30915	9888698
64487	7734051
33850	6724268
23668	7138806
80119	4671232
38257	7251618
57129	4669782
80872	4744938
29721	4053090
2500	5746865
12572	9813736
13695	6574484
9089	3912255
13782	8473098
13024	8350749
83372	768015
69848	192978
71847	3591963
4767	2708961
86352	6095912
21865	281975
23571	4415864
79137	6026089
63666	7724471
8792	8389001
15621	2749279
30943	5942920
49876	6492455
40376	1267312
74582	3636611
23287	4089155
94807	7774064
78333	7380976
60123	4852549
95961	6138283
37020	9995366
85416	9066042
36674	9763035
18641	1302734
87979	5698431
2681	7050796
28155	1734195
92443	5602641
49424	6744156
9881	5252061
42994	4050191
8328	3122555
13398	9900998
10648	2735375
6534	9155936
75809	3708905
19395	5042902
96633	7724137
53874	70043
30264	1167322
86107	3384269
11687	2713095
13618	4185318
86471	4302554
14599	4196539
52700	6981615
3877	8615429
23270	85200
71976	6445742
48570	2931107
66048	7514400
77271	1705564
25195	4993996
52535	1145326
8588	6411841
54712	2636283
15775	2067802
13611	484592
93925	4583328
99768	8000426
66031	8876937
2050	2757430
68348	8671647
18438	6696266
24172	4419176
1000	9940431
10384	6822627
16010	5571640
90883	4403862
74547	5054920
9621	9352912
42631	3604674
78912	2956716
54814	4592720
76514	1580467
627	4165205
22471	3093723
52616	3240479
36623	30137
54459	9012675
58681	4693803
72797	153746
3785	8474640
88649	5144240
73740	8716615
75280	4548980
49566	7670617
48162	4771731
88785	6991656
2494	4529761
75969	4657188
607	617359
4180	9720358
57135	7282502
55810	8200820
56906	3604312
60686	2434084
18926	783834
85316	1261554
81054	6211461
5461	1030830
48171	9422542
19760	7812400
68832	5457290
30205	5265430
41867	4599489
15624	2578514
37928	8958159
77976	487802
38350	2552089
80777	5715469
15556	2713425
67204	130867
66311	2825181
50218	7024261
65883	9243441
28084	4168452
68064	4049278
3	2588593
42601	6400623
89120	5507405
19589	3484857
29955	3330947
12915	9170552
58125	355888
79397	9057461
99804	7614176
86157	3346619
47119	3273126
64810	6435325
33218	9121124
95304	933895
18251	3167093
90928	8649786
96316	1080042
44449	9840154
7405	9059347
96716	621292
51419	9413615
95440	2921093
19048	6141371
18193	7607557
43481	2026109
42570	5883844
61126	1510486
55031	1514117
2159	1591255
76193	53430
27563	2199685
89358	1653566
32376	2135313
42451	5134516
84768	2981337
56032	2529618
93465	7150389
82372	1819941
63535	2214054
5337	1329
2383	4846644
79598	1757788
25387	85597
85232	7729902
60232	4276909
33923	6963360
63916	2117099
60442	95358
81495	7913594
22127	4508036
8851	5212118
41511	6464060
30630	2523049
35980	5599876
44131	7584977
98990	7704031
84099	6761325
7959	4796449
12974	5638273
59785	9488280
16932	1085910
58782	8192319
31294	8386957
56568	8900972
80706	4964954
75213	1946766
19998	2531084
22180	9608183
11593	4740363
29047	294767
45965	3804452
55695	1839508
15041	9172588
89333	2419243
7646	1407229
34608	1002364
11402	5676608
33078	5426825
60250	74121
57069	8848087
62173	7492200
76740	4317110
22897	4735085
22496	4262113
72268	5955594
6281	2176606
31567	34980
94923	6085722
33508	5463732
55634	9932681
11690	8133426
98379	6480175
34442	2188157
91063	8426218
32563	5485271
21609	9574252
49581	9617701
91456	3739529
40212	6017440
7063	3262427
78958	6338525
26186	7797356
58421	7306755
19610	9415716
85781	6245853
91584	7234809
65637	7073739
77110	9682292
37235	2897753
69248	268040
87172	1141192
53473	5697158
25222	6178100
11350	2531392
14267	9629169
22432	9316865
14459	3500461
95354	8781402
88962	1498928
91049	1675498
650	3079204
78405	7709460
56666	398207
76386	6409272
46845	2029740
83019	5846140
51475	8418716
13046	9016453
54334	4031261
30760	7373007
75990	4260466
53063	6145968
61323	3861683
48107	742054
61484	8179447
91581	6809605
16820	5401635
81029	280976
52502	9997136
22052	9533218
43945	6481669
8820	9329133
15616	2983227
58245	5634742
98319	1794488
14496	9676974
7465	1273933
77662	6147470
29492	3592460
59164	6876043
71681	5655327
52098	9479677
79639	8535772
29048	5473340
76526	1335928
29077	7848325
13017	964118
91143	1201072
1103	9604911
10132	7145813
98950	8996309
52467	1524140
73192	371705
55861	8554761
27904	9355488
78223	2945980
57126	9454106
19950	2541389
86357	9976629
9053	2025291
29801	5953206
20995	2898006
19131	3417777
88291	6363459
8822	4998798
9502	8014140
25661	1157332
71368	6723277
60463	6814593
93060	3621272
44512	1380483
96620	6015097
56990	8667300
41408	3070278
13320	2067086
78954	5209130
43496	4784645
34091	102324
74203	5457637
98263	2917357
85175	704205
81796	185956
80837	6588300
29431	5106126
72699	805704
87309	2911833
92790	7613406
50677	4730709
24601	8357198
43835	9732657
48847	6763490
64952	4747148
35289	315160
67861	1728508
14041	8688885
55877	1493186
41614	2539166
17690	1087785
28961	2812256
97092	3823414
44605	9858752
54034	7444786
46825	26731
88492	7190546
94053	861631
3785	4624563
76148	4384769
23104	7837117
94674	7529880
77870	8350031
41563	812817
79760	1224526
62193	5673759
77820	3707075
23826	2212707
16210	550012
69237	7963437
77446	4026428
27070	9283906
14053	2816272
9754	4080530
45236	1121927
80919	3174771
47159	8153526
23403	6933551
65372	8829157
96186	535159
83933	8542071
76974	524784
30659	9091953
65763	1692759
69098	4835214
73748	8663834
34556	7659998
73451	8470271
40496	1561771
71271	6911977
53877	8615761
1565	3229985
57594	9795107
5605	7369883
45728	8680758
92956	3328112
56373	8022940
53927	1598555
19094	4640369
18711	1317726
75485	8825616
80891	6544809
10723	4670292
52294	2454571
18593	6327717
65929	367685
79167	1480268
50204	9640288
39550	9946026
81226	5107324
25067	4755649
47221	1830096
6566	3895374
92527	3699845
48232	3047097
5637	510382
31505	8569988
79728	992357
36946	2077977
89623	5534488
63088	1318564
8501	6238507
48632	4789341
12249	1048528
35768	5838975
20392	3426890
15957	8684778
87001	4030929
61604	7502455
70653	4957195
77758	9867318
8138	2290960
34565	5585048
89050	5192675
26421	6292043
91151	5109262
35825	1620483
88293	8433167
10263	5721979
17007	5608684
98979	7109879
72148	5792395
1060	5112130
59238	702963
26060	9473024
57483	5713685
96310	2415611
15215	1160551
57987	9357509
42907	9636565
78450	352235
85976	1349851
9404	9719146
85945	5629012
61532	2327477
5406	7395567
82759	2101473
21279	3030216
14306	2742232
52060	1933415
67564	506877
63267	9902457
92943	3274088
68350	8008646
1152	6397755
30093	8207631
64943	918417
45777	7451631
93651	5066453
70911	7525676
31298	1311351
31701	6626482
66823	6996994
48785	6991567
6013	1436062
94881	9718046
56614	4817625
76165	6207411
31666	8248358
2581	2492035
82013	5336469
51699	2244297
17327	4373334
8283	9844657
23398	266908
19553	5732391
24430	4899238
22347	5701883
75438	2628375
80313	1586356
91006	9477617
65588	6179607
16592	6892117
48132	9625692
11526	4178998
55414	6267680
98161	7907025
41647	5158768
86778	9405053
7061	8169213
52233	1060495
30967	7118366
67886	5160279
5540	9115837
75228	9789170
77541	8780741
63085	6934099
28632	1902981
28706	6658102
49751	5086060
34795	2195732
40903	3193347
18580	4630042
73406	4426463
79863	4240001
91278	2626993
81286	1854953
67825	9062577
49421	5965931
57752	8402731
3915	6827554
75612	6723974
65438	6671731
17714	9082932
17656	8182644
99314	3972093
29606	3597949
83414	1586157
6316	8210128
68615	1789994
6219	3552301
41424	8833984
27667	1304848
47302	364772
4869	1097698
42673	5103063
64385	2895002
76772	7847052
65414	2673695
4436	93427
95000	3481741
76323	5990480
11229	4478435
9760	9647216
3858	6801474
78566	2894244
72818	4624537
32425	9694460
42928	2119158
69517	5935506
75568	4049063
71405	8506622
25549	7784910
21816	955702
60815	9069032
70435	4125994
86706	2924815
37316	7874032
54011	2139751
17607	9202148
79416	5627137
21894	7261941
93716	7370560
76058	5497522
3373	7755029
57863	4072865
79712	6774129
97184	4369721
64475	2318262
26300	1300754
42379	9160422
45329	3364404
95675	7641568
36764	6253414
61292	9034200
86173	8566520
58742	7335396
61302	3473818
40600	468418
34688	9189995
75796	1929374
76957	212740
98111	4993583
30958	7854079
46758	511184
84168	570471
47508	7618096
90784	1965956
43957	5639151
57976	1425306
78034	1280633
11178	3694207
93463	4658480
6064	6622270
74868	8000326
17952	66986
61879	6958235
85914	5192101
27550	2032516
29825	3475162
29560	9867320
63471	8915576
28217	1400061
95790	3899770
41029	9194855
75877	1649097
53156	7296930
75724	7352829
10321	472140
17801	1914635
17564	4850943
50394	7153224
28387	7096004
80931	6664237
24753	418880
1302	8154326
81480	9386236
25184	2544996
63202	1259528
78494	8514450
29879	5434370
2242	6498335
52408	3255810
53867	8261910
45585	5206546
30647	6406921
29059	4123752
55259	1095609
96777	6968542
66757	157355
54856	5402660
33959	5670432
96631	4991053
40566	6379151
75650	2522827
22689	1581192
30933	179138
59091	5646156
54992	6762261
8237	7510096
94751	5269990
37628	2663830
965	4693771
44965	2519799
53802	8872428
25003	2000318
48338	3000771
66733	8690309
13195	7476687
80965	9070204
9976	9812963
80159	16
12605	5017943
35135	7545419
12312	8586545
54144	1677647
30702	1577803
12021	5781468
84001	3735911
24784	4892175
787	2988862
64380	4199850
96293	6060245
85438	4840857
65536	2128706
50406	7090595
92255	9307892
10916	2685017
75744	9398037
88555	1057202
26676	4805562
88004	5554978
98575	7251295
36741	1984578
91595	9674974
49159	9477602
37623	6142188
97442	2381336
16291	6429437
72224	3864699
23577	2843060
29832	3818849
24760	407081
47982	9887765
91251	5669542
38936	1375100
49968	7926574
40983	6207701
39152	2742306
99263	286250
71999	4278243
5030	8045562
71193	8310186
69558	2130739
15416	5006522
72503	6857884
47833	3666851
14743	664778
23164	7475470
8568	7041559
75046	282452
70488	9093558
27870	1035873
60144	2155090
7379	2508587
74439	5445119
71278	1033757
15892	7162849
5848	8791819
67224	9530469
42434	4301778
83248	9809434
31608	3964941
77530	8323088
67810	3370204
72835	2979419
57362	7062509
26459	774896
72165	4352935
41905	6287569
40300	3874364
18031	8644528
61257	3097542
88261	9947579
79847	9056306
19204	8604907
37796	4426435
29479	51150
95064	7803203
42679	2401867
66997	7031994
14346	4264263
72755	9392199
36886	7369768
71194	3622554
72155	1597814
69466	2673856
28965	7219718
18911	5845774
47871	7194213
51349	4511250
82868	3635524
33739	4158110
88962	294834
37778	3300026
15611	1904321
85245	7023609
65968	6964714
89168	7265115
60924	4075214
12128	9425064
53154	8580105
39898	5811448
30056	3912949
14000	4187989
14323	2353474
35049	3067070
59967	4759976
70204	3246857
87471	4276937
74071	2993359
84693	7260890
50011	7698984
7674	7472782
81304	704949
18128	6499410
39446	1063028
70308	8292121
72446	841631
35920	1821132
9104	7330106
2606	7253485
40344	6755166
47597	898591
70096	319214
38336	5529889
6676	4543350
46906	8629725
43046	3662594
75552	1526027
6321	7219586
7333	2261882
29002	6440958
95719	9462648
20107	9047164
78860	3045342
45517	6370668
57954	8939889
92818	194251
76262	7811479
92493	2612417
79070	946920
58525	2107309
98214	4389010
71549	1436532
9813	1844126
17873	1736496
67587	2456105
89490	7730274
95940	4665202
68274	8388956
98202	1459732
4649	838169
17563	229977
50615	899633
79915	6888000
4721	7445483
98772	1000577
75641	710833
60633	4895415
36480	3691741
65642	5963417
61705	3841752
68181	1295419
89347	9683750
47634	9242591
87951	6631790
35131	1062007
91166	6664590
24291	8967528
15132	2138289
94194	259289
69627	9247713
71660	7349217
79709	3013814
55510	1299758
504	1279543
35030	2451605
12906	5994771
94366	3782634
99243	5648705
14473	1557375
2589	1207928
30427	9544192
16336	9708319
96059	1614208
29427	6353268
65842	8351031
92446	9001324
35046	3749546
7231	9683699
52000	3914278
92038	4937391
61707	6737446
36965	6447936
65833	7636110
10355	9979783
17321	6097410
16706	6733832
97094	6932936
47577	1642190
62602	4426574
6842	4097056
93796	1304134
51157	6087350
88111	1882146
94015	2238281
13598	4998136
59055	8929312
87827	4440814
32379	3021364
10082	4237021
99369	3554612
95733	9593647
42101	6644155
59485	4595512
51778	2792188
59458	9017750
95004	5916726
29103	8824669
28050	2156675
56863	951295
8903	1957776
45236	3601452
94949	4354610
54482	9669413
55150	9807778
58611	2138431
82218	5333369
60926	6532342
61441	9949833
15744	9763310
28076	8263767
66109	6436845
14242	5086355
35793	9316274
20838	4999628
89645	8847408
66684	700212
43355	6102543
66180	4058330
16972	6420979
90777	3889824
33	2414181
14418	1952277
45301	3105623
93712	607727
64808	7729951
14108	8483667
7153	8679474
23520	1579356
76212	5736842
42263	897813
96063	9743161
36019	2746506
39899	9927811
89287	1460221
1396	2314987
3191	1748775
65472	8359759
74480	6881855
103	6436576
53798	3506389
76350	4426854
5699	789642
71502	9414150
41518	1754517
55030	8713646
35985	1669874
30274	6444869
46564	4539135
21959	5404376
74884	814068
51231	6019280
53882	7447454
84478	9848077
83858	10198
51820	7209256
32770	9825357
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Comparing large list of strings to user input

15 Nov 2018, 21:02

Oif2003, that’s actually kind of genius!
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Comparing large list of strings to user input

15 Nov 2018, 23:07

kczx3 wrote:
15 Nov 2018, 21:02
Oif2003, that’s actually kind of genius!
Yes, very impressive to use the script itself to store large data as comments.
One draw back, won't work if script is compiled.
MikeyG12
Posts: 30
Joined: 03 May 2018, 14:21

Re: Comparing large list of strings to user input

16 Nov 2018, 10:54

oif2003 wrote:
14 Nov 2018, 19:15
You can append the data to the end of your script after /* (block comment) and parse the script file to read them in as variables. See example with 1k rows (2 columns copied directly from Excel).
Note: this is for AutoHotkey v2.

Code: Select all

#SingleInstance

gui := GuiCreate()
editBox := gui.Add("Edit", "w600")
dispBox := gui.Add("Edit", "r20 w600 readonly -wrap -vscroll")
editBox.onEvent("Change", () => editBoxChanged())
gui.show()

label := "/* my list of stuff starts here"
script := fileRead(A_ScriptFullPath)
startpos := InStr(script, label, , -1)

data := {}
loop Parse SubStr(script, startpos + StrLen(label)) , "`n" {
	row := StrSplit(A_LoopField, "`t")
	if row[1] != "" && row[2] != ""
		data[row[1]] := row[2]
}

editBoxChanged() {
	global editBox, dispBox, gui, data
	dispBox.Value := ""
	matchedCount := 0
	len := StrLen(editBox.Value)
	for k, v in data {
		if matchedCount > 19 
			return
		if SubStr(k, 1, len) == editBox.Value {
			dispBox.Value .= k ":" v "`n"
			matchedCount++
		}
	}
}
	

/* my list of stuff starts here
58132	3585379
74426	4805209
74601	6294755
85177	5123003
335	9919741
63904	5592403
2395	6605401
26722	6022079
48392	4866759
86742	736956
22463	3804520
15188	4529171
95136	9696121
84665	461645
51079	5804588
83683	7719897
79907	3985180
44246	3501426
99489	8608137
15659	1589892
36460	6790731
30456	8623794
13899	3044623
42821	2445618
92425	9962661
3809	1955843
44721	4817214
64769	5830473
49123	178184
15651	836042
18586	8950735
35948	8840705
91600	9177471
25044	8123175
6611	267800
12522	7212570
26076	3237035
15887	1627833
73409	5634596
7349	542268
61254	3866260
82971	2563704
10579	749171
83566	5110985
6295	3291795
84709	129252
76473	325488
15230	7514377
54436	5101923
18179	9846148
33827	9893086
95364	1118679
67334	1403882
44271	6291407
80389	4173296
18347	4433795
8711	2088848
68779	7731869
62872	6348559
98084	3692359
95331	2162658
33183	2219273
73180	5699300
21443	7747876
75696	3628617
81636	8077517
88926	7158830
38453	509255
35403	3645139
44321	2153370
37832	9103137
96702	6359243
81495	8427297
16172	6541879
28745	2207439
48041	9923160
21085	8705441
7467	6307898
27922	7735810
14904	8151428
94841	4598183
30915	9888698
64487	7734051
33850	6724268
23668	7138806
80119	4671232
38257	7251618
57129	4669782
80872	4744938
29721	4053090
2500	5746865
12572	9813736
13695	6574484
9089	3912255
13782	8473098
13024	8350749
83372	768015
69848	192978
71847	3591963
4767	2708961
86352	6095912
21865	281975
23571	4415864
79137	6026089
63666	7724471
8792	8389001
15621	2749279
30943	5942920
49876	6492455
40376	1267312
74582	3636611
23287	4089155
94807	7774064
78333	7380976
60123	4852549
95961	6138283
37020	9995366
85416	9066042
36674	9763035
18641	1302734
87979	5698431
2681	7050796
28155	1734195
92443	5602641
49424	6744156
9881	5252061
42994	4050191
8328	3122555
13398	9900998
10648	2735375
6534	9155936
75809	3708905
19395	5042902
96633	7724137
53874	70043
30264	1167322
86107	3384269
11687	2713095
13618	4185318
86471	4302554
14599	4196539
52700	6981615
3877	8615429
23270	85200
71976	6445742
48570	2931107
66048	7514400
77271	1705564
25195	4993996
52535	1145326
8588	6411841
54712	2636283
15775	2067802
13611	484592
93925	4583328
99768	8000426
66031	8876937
2050	2757430
68348	8671647
18438	6696266
24172	4419176
1000	9940431
10384	6822627
16010	5571640
90883	4403862
74547	5054920
9621	9352912
42631	3604674
78912	2956716
54814	4592720
76514	1580467
627	4165205
22471	3093723
52616	3240479
36623	30137
54459	9012675
58681	4693803
72797	153746
3785	8474640
88649	5144240
73740	8716615
75280	4548980
49566	7670617
48162	4771731
88785	6991656
2494	4529761
75969	4657188
607	617359
4180	9720358
57135	7282502
55810	8200820
56906	3604312
60686	2434084
18926	783834
85316	1261554
81054	6211461
5461	1030830
48171	9422542
19760	7812400
68832	5457290
30205	5265430
41867	4599489
15624	2578514
37928	8958159
77976	487802
38350	2552089
80777	5715469
15556	2713425
67204	130867
66311	2825181
50218	7024261
65883	9243441
28084	4168452
68064	4049278
3	2588593
42601	6400623
89120	5507405
19589	3484857
29955	3330947
12915	9170552
58125	355888
79397	9057461
99804	7614176
86157	3346619
47119	3273126
64810	6435325
33218	9121124
95304	933895
18251	3167093
90928	8649786
96316	1080042
44449	9840154
7405	9059347
96716	621292
51419	9413615
95440	2921093
19048	6141371
18193	7607557
43481	2026109
42570	5883844
61126	1510486
55031	1514117
2159	1591255
76193	53430
27563	2199685
89358	1653566
32376	2135313
42451	5134516
84768	2981337
56032	2529618
93465	7150389
82372	1819941
63535	2214054
5337	1329
2383	4846644
79598	1757788
25387	85597
85232	7729902
60232	4276909
33923	6963360
63916	2117099
60442	95358
81495	7913594
22127	4508036
8851	5212118
41511	6464060
30630	2523049
35980	5599876
44131	7584977
98990	7704031
84099	6761325
7959	4796449
12974	5638273
59785	9488280
16932	1085910
58782	8192319
31294	8386957
56568	8900972
80706	4964954
75213	1946766
19998	2531084
22180	9608183
11593	4740363
29047	294767
45965	3804452
55695	1839508
15041	9172588
89333	2419243
7646	1407229
34608	1002364
11402	5676608
33078	5426825
60250	74121
57069	8848087
62173	7492200
76740	4317110
22897	4735085
22496	4262113
72268	5955594
6281	2176606
31567	34980
94923	6085722
33508	5463732
55634	9932681
11690	8133426
98379	6480175
34442	2188157
91063	8426218
32563	5485271
21609	9574252
49581	9617701
91456	3739529
40212	6017440
7063	3262427
78958	6338525
26186	7797356
58421	7306755
19610	9415716
85781	6245853
91584	7234809
65637	7073739
77110	9682292
37235	2897753
69248	268040
87172	1141192
53473	5697158
25222	6178100
11350	2531392
14267	9629169
22432	9316865
14459	3500461
95354	8781402
88962	1498928
91049	1675498
650	3079204
78405	7709460
56666	398207
76386	6409272
46845	2029740
83019	5846140
51475	8418716
13046	9016453
54334	4031261
30760	7373007
75990	4260466
53063	6145968
61323	3861683
48107	742054
61484	8179447
91581	6809605
16820	5401635
81029	280976
52502	9997136
22052	9533218
43945	6481669
8820	9329133
15616	2983227
58245	5634742
98319	1794488
14496	9676974
7465	1273933
77662	6147470
29492	3592460
59164	6876043
71681	5655327
52098	9479677
79639	8535772
29048	5473340
76526	1335928
29077	7848325
13017	964118
91143	1201072
1103	9604911
10132	7145813
98950	8996309
52467	1524140
73192	371705
55861	8554761
27904	9355488
78223	2945980
57126	9454106
19950	2541389
86357	9976629
9053	2025291
29801	5953206
20995	2898006
19131	3417777
88291	6363459
8822	4998798
9502	8014140
25661	1157332
71368	6723277
60463	6814593
93060	3621272
44512	1380483
96620	6015097
56990	8667300
41408	3070278
13320	2067086
78954	5209130
43496	4784645
34091	102324
74203	5457637
98263	2917357
85175	704205
81796	185956
80837	6588300
29431	5106126
72699	805704
87309	2911833
92790	7613406
50677	4730709
24601	8357198
43835	9732657
48847	6763490
64952	4747148
35289	315160
67861	1728508
14041	8688885
55877	1493186
41614	2539166
17690	1087785
28961	2812256
97092	3823414
44605	9858752
54034	7444786
46825	26731
88492	7190546
94053	861631
3785	4624563
76148	4384769
23104	7837117
94674	7529880
77870	8350031
41563	812817
79760	1224526
62193	5673759
77820	3707075
23826	2212707
16210	550012
69237	7963437
77446	4026428
27070	9283906
14053	2816272
9754	4080530
45236	1121927
80919	3174771
47159	8153526
23403	6933551
65372	8829157
96186	535159
83933	8542071
76974	524784
30659	9091953
65763	1692759
69098	4835214
73748	8663834
34556	7659998
73451	8470271
40496	1561771
71271	6911977
53877	8615761
1565	3229985
57594	9795107
5605	7369883
45728	8680758
92956	3328112
56373	8022940
53927	1598555
19094	4640369
18711	1317726
75485	8825616
80891	6544809
10723	4670292
52294	2454571
18593	6327717
65929	367685
79167	1480268
50204	9640288
39550	9946026
81226	5107324
25067	4755649
47221	1830096
6566	3895374
92527	3699845
48232	3047097
5637	510382
31505	8569988
79728	992357
36946	2077977
89623	5534488
63088	1318564
8501	6238507
48632	4789341
12249	1048528
35768	5838975
20392	3426890
15957	8684778
87001	4030929
61604	7502455
70653	4957195
77758	9867318
8138	2290960
34565	5585048
89050	5192675
26421	6292043
91151	5109262
35825	1620483
88293	8433167
10263	5721979
17007	5608684
98979	7109879
72148	5792395
1060	5112130
59238	702963
26060	9473024
57483	5713685
96310	2415611
15215	1160551
57987	9357509
42907	9636565
78450	352235
85976	1349851
9404	9719146
85945	5629012
61532	2327477
5406	7395567
82759	2101473
21279	3030216
14306	2742232
52060	1933415
67564	506877
63267	9902457
92943	3274088
68350	8008646
1152	6397755
30093	8207631
64943	918417
45777	7451631
93651	5066453
70911	7525676
31298	1311351
31701	6626482
66823	6996994
48785	6991567
6013	1436062
94881	9718046
56614	4817625
76165	6207411
31666	8248358
2581	2492035
82013	5336469
51699	2244297
17327	4373334
8283	9844657
23398	266908
19553	5732391
24430	4899238
22347	5701883
75438	2628375
80313	1586356
91006	9477617
65588	6179607
16592	6892117
48132	9625692
11526	4178998
55414	6267680
98161	7907025
41647	5158768
86778	9405053
7061	8169213
52233	1060495
30967	7118366
67886	5160279
5540	9115837
75228	9789170
77541	8780741
63085	6934099
28632	1902981
28706	6658102
49751	5086060
34795	2195732
40903	3193347
18580	4630042
73406	4426463
79863	4240001
91278	2626993
81286	1854953
67825	9062577
49421	5965931
57752	8402731
3915	6827554
75612	6723974
65438	6671731
17714	9082932
17656	8182644
99314	3972093
29606	3597949
83414	1586157
6316	8210128
68615	1789994
6219	3552301
41424	8833984
27667	1304848
47302	364772
4869	1097698
42673	5103063
64385	2895002
76772	7847052
65414	2673695
4436	93427
95000	3481741
76323	5990480
11229	4478435
9760	9647216
3858	6801474
78566	2894244
72818	4624537
32425	9694460
42928	2119158
69517	5935506
75568	4049063
71405	8506622
25549	7784910
21816	955702
60815	9069032
70435	4125994
86706	2924815
37316	7874032
54011	2139751
17607	9202148
79416	5627137
21894	7261941
93716	7370560
76058	5497522
3373	7755029
57863	4072865
79712	6774129
97184	4369721
64475	2318262
26300	1300754
42379	9160422
45329	3364404
95675	7641568
36764	6253414
61292	9034200
86173	8566520
58742	7335396
61302	3473818
40600	468418
34688	9189995
75796	1929374
76957	212740
98111	4993583
30958	7854079
46758	511184
84168	570471
47508	7618096
90784	1965956
43957	5639151
57976	1425306
78034	1280633
11178	3694207
93463	4658480
6064	6622270
74868	8000326
17952	66986
61879	6958235
85914	5192101
27550	2032516
29825	3475162
29560	9867320
63471	8915576
28217	1400061
95790	3899770
41029	9194855
75877	1649097
53156	7296930
75724	7352829
10321	472140
17801	1914635
17564	4850943
50394	7153224
28387	7096004
80931	6664237
24753	418880
1302	8154326
81480	9386236
25184	2544996
63202	1259528
78494	8514450
29879	5434370
2242	6498335
52408	3255810
53867	8261910
45585	5206546
30647	6406921
29059	4123752
55259	1095609
96777	6968542
66757	157355
54856	5402660
33959	5670432
96631	4991053
40566	6379151
75650	2522827
22689	1581192
30933	179138
59091	5646156
54992	6762261
8237	7510096
94751	5269990
37628	2663830
965	4693771
44965	2519799
53802	8872428
25003	2000318
48338	3000771
66733	8690309
13195	7476687
80965	9070204
9976	9812963
80159	16
12605	5017943
35135	7545419
12312	8586545
54144	1677647
30702	1577803
12021	5781468
84001	3735911
24784	4892175
787	2988862
64380	4199850
96293	6060245
85438	4840857
65536	2128706
50406	7090595
92255	9307892
10916	2685017
75744	9398037
88555	1057202
26676	4805562
88004	5554978
98575	7251295
36741	1984578
91595	9674974
49159	9477602
37623	6142188
97442	2381336
16291	6429437
72224	3864699
23577	2843060
29832	3818849
24760	407081
47982	9887765
91251	5669542
38936	1375100
49968	7926574
40983	6207701
39152	2742306
99263	286250
71999	4278243
5030	8045562
71193	8310186
69558	2130739
15416	5006522
72503	6857884
47833	3666851
14743	664778
23164	7475470
8568	7041559
75046	282452
70488	9093558
27870	1035873
60144	2155090
7379	2508587
74439	5445119
71278	1033757
15892	7162849
5848	8791819
67224	9530469
42434	4301778
83248	9809434
31608	3964941
77530	8323088
67810	3370204
72835	2979419
57362	7062509
26459	774896
72165	4352935
41905	6287569
40300	3874364
18031	8644528
61257	3097542
88261	9947579
79847	9056306
19204	8604907
37796	4426435
29479	51150
95064	7803203
42679	2401867
66997	7031994
14346	4264263
72755	9392199
36886	7369768
71194	3622554
72155	1597814
69466	2673856
28965	7219718
18911	5845774
47871	7194213
51349	4511250
82868	3635524
33739	4158110
88962	294834
37778	3300026
15611	1904321
85245	7023609
65968	6964714
89168	7265115
60924	4075214
12128	9425064
53154	8580105
39898	5811448
30056	3912949
14000	4187989
14323	2353474
35049	3067070
59967	4759976
70204	3246857
87471	4276937
74071	2993359
84693	7260890
50011	7698984
7674	7472782
81304	704949
18128	6499410
39446	1063028
70308	8292121
72446	841631
35920	1821132
9104	7330106
2606	7253485
40344	6755166
47597	898591
70096	319214
38336	5529889
6676	4543350
46906	8629725
43046	3662594
75552	1526027
6321	7219586
7333	2261882
29002	6440958
95719	9462648
20107	9047164
78860	3045342
45517	6370668
57954	8939889
92818	194251
76262	7811479
92493	2612417
79070	946920
58525	2107309
98214	4389010
71549	1436532
9813	1844126
17873	1736496
67587	2456105
89490	7730274
95940	4665202
68274	8388956
98202	1459732
4649	838169
17563	229977
50615	899633
79915	6888000
4721	7445483
98772	1000577
75641	710833
60633	4895415
36480	3691741
65642	5963417
61705	3841752
68181	1295419
89347	9683750
47634	9242591
87951	6631790
35131	1062007
91166	6664590
24291	8967528
15132	2138289
94194	259289
69627	9247713
71660	7349217
79709	3013814
55510	1299758
504	1279543
35030	2451605
12906	5994771
94366	3782634
99243	5648705
14473	1557375
2589	1207928
30427	9544192
16336	9708319
96059	1614208
29427	6353268
65842	8351031
92446	9001324
35046	3749546
7231	9683699
52000	3914278
92038	4937391
61707	6737446
36965	6447936
65833	7636110
10355	9979783
17321	6097410
16706	6733832
97094	6932936
47577	1642190
62602	4426574
6842	4097056
93796	1304134
51157	6087350
88111	1882146
94015	2238281
13598	4998136
59055	8929312
87827	4440814
32379	3021364
10082	4237021
99369	3554612
95733	9593647
42101	6644155
59485	4595512
51778	2792188
59458	9017750
95004	5916726
29103	8824669
28050	2156675
56863	951295
8903	1957776
45236	3601452
94949	4354610
54482	9669413
55150	9807778
58611	2138431
82218	5333369
60926	6532342
61441	9949833
15744	9763310
28076	8263767
66109	6436845
14242	5086355
35793	9316274
20838	4999628
89645	8847408
66684	700212
43355	6102543
66180	4058330
16972	6420979
90777	3889824
33	2414181
14418	1952277
45301	3105623
93712	607727
64808	7729951
14108	8483667
7153	8679474
23520	1579356
76212	5736842
42263	897813
96063	9743161
36019	2746506
39899	9927811
89287	1460221
1396	2314987
3191	1748775
65472	8359759
74480	6881855
103	6436576
53798	3506389
76350	4426854
5699	789642
71502	9414150
41518	1754517
55030	8713646
35985	1669874
30274	6444869
46564	4539135
21959	5404376
74884	814068
51231	6019280
53882	7447454
84478	9848077
83858	10198
51820	7209256
32770	9825357
I tried running this but nothing happened, I suspect it's because I'm not running AHK v2, I'm running 1.1.30.01 :/ But I like the idea. This is pretty close to what I was wanting to do. I'm thinking that I need to make a 2d array with x being the string prefix value and y being a string model and then making a loop to check if the user input matches x and returning y if it does. I'm looking up 2d arrays but nothing I'm finding is helpful.
oif2003
Posts: 214
Joined: 17 Oct 2018, 11:43
Contact:

Re: Comparing large list of strings to user input

16 Nov 2018, 11:57

I don't think you want to create a 2D array, as that would mean Array2D[prefix, model] should return something other than the model string. Perhaps you meant creating two 1D arrays : one for prefix, and one for model.

Instead of creating two arrays, I recommend creating an object that has key-value pairs that correspond to your string prefix and string model. It is essentially what I did in the example with column 1 as string prefix and column 2 as string model. The advantage in doing it this way is you will not have to loop through an array of prefix to retrieve the model. I wrote a loop for that anyway because I was taking a substring of prefix and comparing that to the characters the user has entered in realtime. Otherwise a object.HasKey(prefix) call will let you know whether or not a corresponding model exists, and retrieving model based on prefix is trivial. I hope this helps.

See AutoHotkey's documentation on Objects:
https://autohotkey.com/docs/Objects.htm
MikeyG12
Posts: 30
Joined: 03 May 2018, 14:21

Re: Comparing large list of strings to user input

16 Nov 2018, 13:24

Thank you so much for your input!! I'm reading the help page you sent me and I think I'm sort of understanding what I need to do but I was hoping to get some clarification. I took the example and am trying to get Has.Key to work and I seem to be able to check to see if the key exists. I think I might be doing something wrong or misunderstanding something though. When I try to add more key pairs it tells me that it's not valid. Here is my code with just one key, if I want to add the fill list of prefix's what would the code look like?


object := {other: "This is a test"}

if (Object.HasKey("other") = true){
MsgBox, It worked!
}else{
MsgBox, It didn't work :(
}

I tried something like this but it didn't work:

object := {
other: "This is a test"
another: "This is a different value"
}

if (Object.HasKey("other") = true){
MsgBox, It worked!
}else{
MsgBox, It didn't work :(
}

Additionally, if I wanted to display the value in the messagebox how would I go about doing that?
oif2003
Posts: 214
Joined: 17 Oct 2018, 11:43
Contact:

Re: Comparing large list of strings to user input

16 Nov 2018, 13:26

Try this

Code: Select all

;initialize
object := 	{other:"This is a test"
			,another:"This is a different value"}

;iterate through the object
for key, value in object {
	MsgBox [%key%] = %value%
}

;accessing directly:
MsgBox % "One test: " object.other

;another way:
MsgBox % "Another test: " object["another"]
MikeyG12
Posts: 30
Joined: 03 May 2018, 14:21

Re: Comparing large list of strings to user input

16 Nov 2018, 13:48

Ok, perfect!

I'm now trying to tackle the job of feeding a users input and then displaying just that item.

object := {other: "This is a test", another: "This is another test", different: "Totally different one"}
usrinput := "other"

if (Object.HasKey(usrinput) = true){
display := object(usrinput)
MsgBox % display
}else{
MsgBox, It didn't work :(
}
MikeyG12
Posts: 30
Joined: 03 May 2018, 14:21

Re: Comparing large list of strings to user input

16 Nov 2018, 13:52

Omg, I used brackets eg object[usrinput] and it worked *facepalm*
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Comparing large list of strings to user input

16 Nov 2018, 17:19

MikeyG12 wrote:
16 Nov 2018, 13:48
object := {other: "This is a test", another: "This is another test", different: "Totally different one"}
usrinput := "other"

if (Object.HasKey(usrinput) = true){
display := object(usrinput)
MsgBox % display
}else{
MsgBox, It didn't work :(
}

It is normally not worth the trouble to seperately check for the key as long as you are not going to have blank, null, or zero element values, you can do this:

Code: Select all

object := {other: "This is a test", another: "This is another test", different: "Totally different one"}
usrinput := "other"

if (display := object[usrinput])
	MsgBox % display
else
	MsgBox, It didn't work :(
Code that looks like that is pretty common.

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: imstupidpleshelp, JoeWinograd, mikeyww, mmflume, Rohwedder, usser and 196 guests