-
Notifications
You must be signed in to change notification settings - Fork 2
/
cond22.bas
259 lines (193 loc) · 7.67 KB
/
cond22.bas
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
Attribute VB_Name = "CodeCOND2"
' (c) Copyright 1995-2024 by John J. Donovan
Option Explicit
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
' FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
' IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Dim CondTmpSample(1 To 1) As TypeSample
Sub Cond2Load(sample() As TypeSample)
' Loads the analytical condition defaults for user to change (for single element only for combined conditions)
ierror = False
On Error GoTo Cond2LoadError
Dim i As Integer
' Load sample into module level array
CondTmpSample(1) = sample(1)
' Load element list
FormCOND2.ComboElementXraySpectrometerCrystal.Clear
For i% = 1 To CondTmpSample(1).LastElm%
msg$ = CondTmpSample(1).Elsyms$(i%) & " " & CondTmpSample(1).Xrsyms$(i%) & ", Takeoff " & Str$(CondTmpSample(1).TakeoffArray!(i%)) & ", Kilovolts " & CondTmpSample(1).KilovoltsArray!(i%)
FormCOND2.ComboElementXraySpectrometerCrystal.AddItem msg$
FormCOND2.ComboElementXraySpectrometerCrystal.ItemData(FormCOND2.ComboElementXraySpectrometerCrystal.NewIndex) = i%
Next i%
' Load element list for channel order operations
Call Cond2LoadChannels
If ierror Then Exit Sub
' Select first element
If FormCOND2.ComboElementXraySpectrometerCrystal.ListCount > 0 Then
FormCOND2.ComboElementXraySpectrometerCrystal.ListIndex = 0
FormCOND2.ListElements.Selected(0) = True
End If
' Realtime modifications
If OperatingVoltagePresent Then
FormCOND2.TextKiloVolts.Enabled = True
Else
FormCOND2.TextKiloVolts.Enabled = False
End If
Exit Sub
' Errors
Cond2LoadError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2Load"
ierror = True
Exit Sub
End Sub
Sub Cond2SaveField()
' Save changed conditions to defaults (analytical condition for a single element)
ierror = False
On Error GoTo Cond2SaveFieldError
Dim i As Integer
If Val(FormCOND2.TextTakeOff.Text) < 1# Or Val(FormCOND2.TextTakeOff.Text) > 90# Then
msg$ = FormCOND2.TextTakeOff.Text & " for TakeOff is out of range!"
MsgBox msg$, vbOKOnly + vbExclamation, "Cond2SaveField"
ierror = True
Exit Sub
End If
If Val(FormCOND2.TextKiloVolts.Text) < MINKILOVOLTS! Or Val(FormCOND2.TextKiloVolts.Text) > MAXKILOVOLTS! Then
msg$ = FormCOND2.TextKiloVolts.Text & " for Kilovolts is out of range!"
MsgBox msg$, vbOKOnly + vbExclamation, "Cond2SaveField"
ierror = True
Exit Sub
End If
' Get selected element channel
If FormCOND2.ComboElementXraySpectrometerCrystal.ListCount < 1 Then Exit Sub
If FormCOND2.ComboElementXraySpectrometerCrystal.ListIndex < 0 Then Exit Sub
i% = FormCOND2.ComboElementXraySpectrometerCrystal.ItemData(FormCOND2.ComboElementXraySpectrometerCrystal.ListIndex)
CondTmpSample(1).TakeoffArray!(i%) = Val(FormCOND2.TextTakeOff.Text)
CondTmpSample(1).KilovoltsArray!(i%) = Val(FormCOND2.TextKiloVolts.Text)
' Check if sample is still combined
CondTmpSample(1).CombinedConditionsFlag = False
If MiscIsDifferent3(CondTmpSample(1).LastElm%, CondTmpSample(1).TakeoffArray!()) Then CondTmpSample(1).CombinedConditionsFlag = True
If MiscIsDifferent3(CondTmpSample(1).LastElm%, CondTmpSample(1).KilovoltsArray!()) Then CondTmpSample(1).CombinedConditionsFlag = True
' Force reload of afactor arrays in case conditions change
AllAnalysisUpdateNeeded = True
AllAFactorUpdateNeeded = True
Exit Sub
' Errors
Cond2SaveFieldError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2SaveField"
ierror = True
Exit Sub
End Sub
Sub Cond2Return(sample() As TypeSample)
' Return the modified sample for other code modules (AcquireChangeConditions2)
ierror = False
On Error GoTo Cond2ReturnError
sample(1) = CondTmpSample(1)
Exit Sub
' Errors
Cond2ReturnError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2Return"
ierror = True
Exit Sub
End Sub
Sub Cond2LoadField()
' Load the fields
ierror = False
On Error GoTo Cond2LoadFieldError
Dim i As Integer
If FormCOND2.ComboElementXraySpectrometerCrystal.ListCount < 1 Then Exit Sub
If FormCOND2.ComboElementXraySpectrometerCrystal.ListIndex < 0 Then Exit Sub
i% = FormCOND2.ComboElementXraySpectrometerCrystal.ItemData(FormCOND2.ComboElementXraySpectrometerCrystal.ListIndex)
' Load defaults if necessary
If CondTmpSample(1).KilovoltsArray!(i%) = 0# Then CondTmpSample(1).KilovoltsArray!(i%) = CondTmpSample(1).kilovolts!
If CondTmpSample(1).TakeoffArray!(i%) = 0# Then CondTmpSample(1).TakeoffArray!(i%) = CondTmpSample(1).takeoff!
' Load fields
FormCOND2.TextKiloVolts.Text = Format$(CondTmpSample(1).KilovoltsArray!(i%))
FormCOND2.TextTakeOff.Text = Format$(CondTmpSample(1).TakeoffArray!(i%))
Exit Sub
' Errors
Cond2LoadFieldError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2LoadField"
ierror = True
Exit Sub
End Sub
Sub Cond2Sort(upordown As Integer)
' Save new channel order (channel up or down)
' chan = channel to be re-sorted
' upordown 1 = up, 2 = down
ierror = False
On Error GoTo Cond2SortError
Dim chan As Integer, chan2 As Integer
' Get selected channel
If FormCOND2.ListElements.ListCount < 1 Then Exit Sub
If FormCOND2.ListElements.ListIndex < 0 Then Exit Sub
chan% = FormCOND2.ListElements.ListIndex + 1
' Get new channel
If upordown = 1 Then
chan2% = chan% + 1
If chan2% > CondTmpSample(1).LastElm% Then Exit Sub
End If
If upordown = 2 Then
chan2% = chan% - 1
If chan2% < 1 Then Exit Sub
End If
' Sort new sample
Call GetElmSaveSampleOnly(Int(0), CondTmpSample(), chan%, chan2%)
If ierror Then Exit Sub
' Reload the form
Call Cond2Load(CondTmpSample())
If ierror Then Exit Sub
Call Cond2LoadField
If ierror Then Exit Sub
' Reselect channel
FormCOND2.ListElements.Selected(chan2% - 1) = True
Exit Sub
' Errors
Cond2SortError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2Sort"
ierror = True
Exit Sub
End Sub
Sub Cond2Apply()
' Save condition changes and update form
ierror = False
On Error GoTo Cond2ApplyError
Call Cond2SaveField
If ierror Then Exit Sub
' Update channel order list
Call Cond2LoadChannels
If ierror Then Exit Sub
Call Cond2LoadField
If ierror Then Exit Sub
Exit Sub
' Errors
Cond2ApplyError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2Apply"
ierror = True
Exit Sub
End Sub
Sub Cond2LoadChannels()
' Load the chanel order list
ierror = False
On Error GoTo Cond2LoadChannelsError
Dim i As Integer
FormCOND2.ListElements.Clear
For i% = 1 To CondTmpSample(1).LastElm%
msg$ = Format$(CondTmpSample(1).Elsyms$(i%) & " " & CondTmpSample(1).Xrsyms$(i%), a50$) & vbTab
msg$ = msg$ & " TakeOff" & Str$(CondTmpSample(1).TakeoffArray!(i%)) & vbTab
msg$ = msg$ & " KeV" & Str$(CondTmpSample(1).KilovoltsArray!(i%))
FormCOND2.ListElements.AddItem msg$
FormCOND2.ListElements.ItemData(FormCOND2.ListElements.NewIndex) = i%
Next i%
Exit Sub
' Errors
Cond2LoadChannelsError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2LoadChannels"
Call IOStatusAuto(vbNullString)
ierror = True
Exit Sub
End Sub