forked from KPatel008/ScoutingPass
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQRReader.bas
More file actions
120 lines (101 loc) · 3.18 KB
/
QRReader.bas
File metadata and controls
120 lines (101 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Attribute VB_Name = "QRReader"
Sub process1QRCodeInput()
saveData (getInput())
End Sub
Sub process6QRCodeInput()
saveData (getInput())
saveData (getInput())
saveData (getInput())
saveData (getInput())
saveData (getInput())
saveData (getInput())
End Sub
Public Function getInput()
getInput = InputBox("Scan QR Code", "Match Scouting Input")
End Function
Sub testSaveData()
saveData ("s=fff;e=1234;l=qm;m=1234;r=r1;t=1234;as=;ae=Y;al=2;ao=2;ai=1;aa=Y;at=N;ax=Y;lp=2;op=1;ip=3;rc=pass;f=0;pc=pass;ss=;c=pass;b=N;ca=x;cb=x;cs=slow;p=N;ds=x;dr=x;pl=x;tr=N;wd=N;if=N;d=N;to=N;be=N;cf=N")
End Sub
Public Function ArrayLen(arr As Variant) As Integer
ArrayLen = UBound(arr) - LBound(arr) + 1
End Function
Sub saveData(inp As String)
Dim fields
Dim par
Dim value
Dim key
Dim table As ListObject
Dim ws As Worksheet
Set ws = ActiveSheet
Dim mapper
Set mapper = CreateObject("Scripting.Dictionary")
Dim data
Set data = CreateObject("Scripting.Dictionary")
Dim tableName As String
tableName = "ScoutingData"
' Set up map
' Fields for every year
mapper.Add "s", "scouter"
mapper.Add "e", "eventCode"
mapper.Add "l", "matchLevel"
mapper.Add "m", "matchNumber"
mapper.Add "r", "robot"
mapper.Add "t", "teamNumber"
' Additional custom mapping
'mapper.Add "f", "fouls"
'mapper.Add "c", "climb"
'mapper.Add "dr", "defenseRating"
'mapper.Add "d", "died"
'mapper.Add "to", "tippedOver"
'mapper.Add "cf", "cardFouls"
'mapper.Add "co", "comments"
If inp = "" Then
Exit Sub
End If
'MsgBox (inp)
fields = Split(inp, ";")
If ArrayLen(fields) > 0 Then
Dim i As Integer
Dim str
i = 0
For Each str In fields
par = Split(str, "=")
key = par(0)
value = par(1)
If mapper.Exists(key) Then
key = mapper(key)
End If
data.Add key, value
Next
tableexists = False
Dim tbl As ListObject
Dim sht As Worksheet
'Loop through each sheet and table in the workbook
For Each sht In ThisWorkbook.Worksheets
For Each tbl In sht.ListObjects
If tbl.Name = tableName Then
tableexists = True
Set table = tbl
Set ws = sht
End If
Next tbl
Next sht
If tableexists Then
'Set table = ws.ListObjects(tableName)
Else
Dim tablerange As Range
ws.ListObjects.Add(xlSrcRange, Range("A1:AO1"), , xlYes).Name = tableName
i = 0
Set table = ws.ListObjects(tableName)
For Each key In data.Keys
table.Range(i + 1) = key
i = i + 1
Next
End If
Dim newrow As ListRow
Set newrow = table.ListRows.Add
For Each str In data.Keys
newrow.Range(table.ListColumns(str).Index) = data(str)
Next
End If
End Sub