-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddstd.bas
611 lines (461 loc) · 16.9 KB
/
addstd.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
Attribute VB_Name = "CodeADDSTD"
' (c) Copyright 1995-2025 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 AddStdNumberToAdd As Integer
Dim AddStdStandardsToAdd(1 To MAXSTD%) As Integer
Dim tNumberofStandards As Integer
Dim tStandardNumbers(1 To MAXSTD%) As Integer
Const MAXMATERIALTYPES% = 30
Sub AddStdAdd()
' Routine to add selected standard(s) to the "add to" list
ierror = False
On Error GoTo AddStdAddError
Dim i As Integer, number As Integer
' Get the selected standard(s)
For i% = 0 To FormADDSTD.ListAvailableStandards.ListCount - 1
' Check to see if standard is selected
If FormADDSTD.ListAvailableStandards.Selected(i%) Then
' See if standard is already in the run and add to "add to" list if not
number% = FormADDSTD.ListAvailableStandards.ItemData(i%)
Call AddStdCheck(number%)
If ierror Then Exit Sub
End If
Next i%
Exit Sub
' Errors
AddStdAddError:
MsgBox Error$, vbOKOnly + vbCritical, "AddStdAdd"
ierror = True
Exit Sub
End Sub
Sub AddStdAddToList(number As Integer)
' Add standard to "current" list box
ierror = False
On Error GoTo AddStdAddToListError
Dim ip As Integer
' Check for standard in available standards index
ip% = StandardGetRow%(number%)
If ip% = 0 Then GoTo AddStdAddToListNotFound
msg$ = Format$(StandardIndexNumbers%(ip%), a40) & " " & StandardIndexNames$(ip%)
FormADDSTD.ListCurrentStandards.AddItem msg$
FormADDSTD.ListCurrentStandards.ItemData(FormADDSTD.ListCurrentStandards.NewIndex) = number%
' Update label field
FormADDSTD.LabelNumberOfStds.Caption = Format$(FormADDSTD.ListCurrentStandards.ListCount)
Exit Sub
' Errors
AddStdAddToListError:
MsgBox Error$, vbOKOnly + vbCritical, "AddStdAddToList"
ierror = True
Exit Sub
AddStdAddToListNotFound:
msg$ = "Standard number " & Format$(number%) & " was not found in " & StandardDataFile$
MsgBox msg$, vbOKOnly + vbExclamation, "AddStdAddToList"
ierror = True
Exit Sub
End Sub
Sub AddStdCheck(number As Integer)
' Check if a standard can be added to the run
ierror = False
On Error GoTo AddStdCheckError
Dim ip As Integer
' Check if standard is already in the run
ip% = IPOS2(NumberofStandards%, number%, StandardNumbers%())
If ip% > 0 Then GoTo AddStdCheckAlreadyAdded
' Check if standard is already in AddStdStandardsToAdd array
ip% = IPOS2(AddStdNumberToAdd%, number%, AddStdStandardsToAdd%())
If ip% > 0 Then GoTo AddStdCheckAlreadyAdded
' Check for standard in available standards index
ip% = StandardGetRow%(number%)
If ip% = 0 Then GoTo AddStdCheckNotFound
' Check if too many standards
If NumberofStandards% + AddStdNumberToAdd% + 1 > MAXSTD% Then GoTo AddStdCheckTooMany
' Add to "add to" list
AddStdNumberToAdd% = AddStdNumberToAdd% + 1
AddStdStandardsToAdd%(AddStdNumberToAdd%) = number%
' Add to "current" list box
Call AddStdAddToList(number%)
If ierror Then Exit Sub
Exit Sub
' Errors
AddStdCheckError:
MsgBox Error$, vbOKOnly + vbCritical, "AddStdCheck"
ierror = True
Exit Sub
AddStdCheckAlreadyAdded:
msg$ = "Standard number " & Format$(number%) & " is already in the run"
MsgBox msg$, vbOKOnly + vbExclamation, "AddStdCheck"
ierror = True
Exit Sub
AddStdCheckTooMany:
msg$ = "Too many standards (" & Format$(NumberofStandards% + AddStdNumberToAdd%) & ") are already in the run"
MsgBox msg$, vbOKOnly + vbExclamation, "AddStdCheck"
ierror = True
Exit Sub
AddStdCheckNotFound:
msg$ = "Standard number " & Format$(number%) & " was not found in " & StandardDataFile$
MsgBox msg$, vbOKOnly + vbExclamation, "AddStdCheck"
ierror = True
Exit Sub
End Sub
Sub AddStdLoad()
' Routine to load the ADDSTD form
ierror = False
On Error GoTo AddStdLoadError
Dim i As Integer
' List the current standards in the run
FormADDSTD.ListCurrentStandards.Clear
tNumberofStandards% = NumberofStandards%
For i% = 1 To NumberofStandards%
tStandardNumbers%(i%) = StandardNumbers%(i%) ' save in case user clicks cancel
Call AddStdAddToList(StandardNumbers%(i%))
If ierror Then Exit Sub
Next i%
' Get available standard names and numbers from database
Call StandardGetMDBIndex
If ierror Then Exit Sub
' List the available standards
Call StandardLoadList(FormADDSTD.ListAvailableStandards)
If ierror Then Exit Sub
' Zero add to list (for new standards)
AddStdNumberToAdd% = 0
For i% = 1 To MAXSTD%
AddStdStandardsToAdd%(i%) = 0
Next i%
' Load material types
Call AddStdMaterialTypeLoad
If ierror Then Exit Sub
Exit Sub
' Errors
AddStdLoadError:
MsgBox Error$, vbOKOnly + vbCritical, "AddStdLoad"
ierror = True
Exit Sub
End Sub
Sub AddStdSave()
' Add standards in "add to" list to the run
ierror = False
On Error GoTo AddStdSaveError
Dim i As Integer, number As Integer
' Loop on each standard to add
For i% = 1 To AddStdNumberToAdd%
number% = AddStdStandardsToAdd%(i%)
If number% > 0 Then
Call AddStdSaveStd(number%)
If ierror Then Exit Sub
End If
Next i%
' Zero add to list (for new standards)
AddStdNumberToAdd% = 0
For i% = 1 To MAXSTD%
AddStdStandardsToAdd%(i%) = 0
Next i%
Exit Sub
' Errors
AddStdSaveError:
MsgBox Error$, vbOKOnly + vbCritical, "AddStdSave"
ierror = True
Exit Sub
End Sub
Sub AddStdSaveStd(number As Integer)
' Add a single standard to the run
ierror = False
On Error GoTo AddStdSaveStdError
Dim ip As Integer
' See if standard is already added
ip% = IPOS2(NumberofStandards%, number%, StandardNumbers%())
If ip% > 0 Then GoTo AddStdSaveStdAlreadyAdded
' Find standard in available standard.mdb index
ip% = StandardGetRow%(number%)
If ip% = 0 Then GoTo AddStdSaveStdNotFound
If NumberofStandards% + 1 > MAXSTD% Then GoTo AddStdSaveStdTooMany
NumberofStandards% = NumberofStandards% + 1
StandardNumbers%(NumberofStandards%) = StandardIndexNumbers%(ip%)
StandardNames$(NumberofStandards%) = StandardIndexNames$(ip%)
StandardDescriptions$(NumberofStandards%) = StandardIndexDescriptions$(ip%)
StandardDensities!(NumberofStandards%) = StandardIndexDensities!(ip%)
StandardCoatingFlag%(NumberofStandards%) = DefaultStandardCoatingFlag% ' 0 = not coated, 1 = coated
StandardCoatingElement%(NumberofStandards%) = DefaultStandardCoatingElement%
StandardCoatingDensity!(NumberofStandards%) = DefaultStandardCoatingDensity!
StandardCoatingThickness!(NumberofStandards%) = DefaultStandardCoatingThickness! ' in angstroms
Exit Sub
' Errors
AddStdSaveStdError:
Screen.MousePointer = vbDefault
MsgBox Error$, vbOKOnly + vbCritical, "AddStdSaveStd"
ierror = True
Exit Sub
AddStdSaveStdAlreadyAdded:
Screen.MousePointer = vbDefault
msg$ = "Standard number " & Format$(number%) & " is already in the run"
MsgBox msg$, vbOKOnly + vbExclamation, "AddStdSaveStd"
ierror = True
Exit Sub
AddStdSaveStdTooMany:
Screen.MousePointer = vbDefault
msg$ = "Too many standards are already in the run"
MsgBox msg$, vbOKOnly + vbExclamation, "AddStdSaveStd"
ierror = True
Exit Sub
AddStdSaveStdNotFound:
Screen.MousePointer = vbDefault
msg$ = "Standard number " & Format$(number%) & " was not found in " & StandardDataFile$
MsgBox msg$, vbOKOnly + vbExclamation, "AddStdSaveStd"
Call IOStatusAuto(vbNullString)
ierror = True
Exit Sub
End Sub
Sub AddStdRemove()
' Remove the selected standard if it is not already acquired
ierror = False
On Error GoTo AddStdRemoveError
Dim ip As Integer, number As Integer
Dim i As Integer
ReDim tstdnums(1 To MAXSTD%) As Integer
' Get the selected standard(s)
If FormADDSTD.ListCurrentStandards.ListIndex < 0 Then Exit Sub
If FormADDSTD.ListCurrentStandards.ListCount < 1 Then Exit Sub
number% = FormADDSTD.ListCurrentStandards.ItemData(FormADDSTD.ListCurrentStandards.ListIndex)
' See if standard is just in the add to list, if so just zero and exit
ip% = IPOS2(AddStdNumberToAdd%, number%, AddStdStandardsToAdd%())
If ip% > 0 Then
AddStdStandardsToAdd%(ip%) = 0
FormADDSTD.ListCurrentStandards.RemoveItem FormADDSTD.ListCurrentStandards.ListIndex
' Update label field
FormADDSTD.LabelNumberOfStds.Caption = Format$(FormADDSTD.ListCurrentStandards.ListCount)
Exit Sub
End If
' Now check if the standard is acquired in current run
ip% = SampleGetRow2(number%, Int(1), Int(1))
If ip% > 0 Then GoTo AddStdRemoveAlreadyAcquired
' Warn user if probe data file is open (not Stage.exe)
If ProbeDataFile$ <> vbNullString Then
msg$ = "Although standard " & Format$(number%) & " can be removed from the "
msg$ = msg$ & "standard list, the user should be aware that if this standard "
msg$ = msg$ & "is referenced in the current probe database, those references "
msg$ = msg$ & "must be changed to another suitable standard. This includes "
msg$ = msg$ & "assignments for standards, interference standards and MAN (mean "
msg$ = msg$ & "atomic number) background standards."
MsgBox msg$, vbOKOnly + vbInformation, "AddStdRemove"
End If
' Remove from list
FormADDSTD.ListCurrentStandards.RemoveItem FormADDSTD.ListCurrentStandards.ListIndex
' Update label field
FormADDSTD.LabelNumberOfStds.Caption = Format$(FormADDSTD.ListCurrentStandards.ListCount)
' Remove from standard numbers
For i% = 1 To NumberofStandards%
If StandardNumbers%(i%) <> number% Then
tstdnums%(i%) = StandardNumbers%(i%)
End If
Next i%
' Zero standards
Call InitStandard
If ierror Then Exit Sub
' Reload
For i% = 1 To MAXSTD%
If tstdnums%(i%) <> 0 Then
Call AddStdSaveStd(tstdnums%(i%))
End If
Next i%
Exit Sub
' Errors
AddStdRemoveError:
MsgBox Error$, vbOKOnly + vbCritical, "AddStdRemove"
ierror = True
Exit Sub
AddStdRemoveAlreadyAcquired:
msg$ = "Standard " & Format$(number%) & " cannot be removed from the standard list because it is already referenced in the current probe database"
MsgBox msg$, vbOKOnly + vbExclamation, "AddStdRemove"
ierror = True
Exit Sub
End Sub
Sub AddStdCancel()
' Reload the original standards
ierror = False
On Error GoTo AddStdCancelError
Dim i As Integer
' Zero standards
Call InitStandard
If ierror Then Exit Sub
' Reload from temporary list
For i% = 1 To tNumberofStandards%
Call AddStdSaveStd(tStandardNumbers%(i%))
Next i%
Exit Sub
' Errors
AddStdCancelError:
MsgBox Error$, vbOKOnly + vbCritical, "AddStdCancel"
ierror = True
Exit Sub
End Sub
Sub AddStdMaterialTypeLoad()
' Load the checkboxes based on the material types in the standard database
ierror = False
On Error GoTo AddStdMaterialTypeLoadError
Dim n As Integer, ip As Integer
Dim tt As Integer
Dim tMaterialTypes() As String
' Find unique strings
For n% = 1 To NumberOfAvailableStandards%
If StandardIndexMaterialTypes$(n%) <> vbNullString Then
ip% = IPOS1%(tt%, StandardIndexMaterialTypes$(n%), tMaterialTypes$())
If ip% = 0 Then
tt% = tt% + 1
ReDim Preserve tMaterialTypes(1 To tt%) As String
tMaterialTypes$(tt%) = StandardIndexMaterialTypes$(n%)
End If
End If
Next n%
' Only list for the number of controls
If tt% > MAXMATERIALTYPES% Then
tt% = MAXMATERIALTYPES%
Call IOWriteLog("AddStdMaterialTypeLoad: Warning, too many material types to display")
End If
' Load unique strings into check boxes
For n% = 1 To tt%
If tMaterialTypes$(n%) <> vbNullString Then
FormADDSTD.CheckMaterialType(n% - 1).Caption = tMaterialTypes$(n%)
End If
Next n%
' Disable remaining check boxes
For n% = tt% + 1 To MAXMATERIALTYPES%
FormADDSTD.CheckMaterialType(n% - 1).Enabled = False
Next n%
Exit Sub
' Errors
AddStdMaterialTypeLoadError:
MsgBox Error$, vbOKOnly + vbCritical, "AddStdMaterialTypeLoad"
ierror = True
Exit Sub
End Sub
Sub AddStdMaterialTypeFilter()
' Filter the available standard list based on checked material types
ierror = False
On Error GoTo AddStdMaterialTypeFilterError
Dim n As Integer, ip As Integer
Dim tt As Integer
Dim tMaterialTypes() As String
' Load material types that are checked
tt% = 0
For n% = 1 To MAXMATERIALTYPES%
If FormADDSTD.CheckMaterialType(n% - 1).value = vbChecked Then
tt% = tt% + 1
ReDim Preserve tMaterialTypes(1 To tt%) As String
tMaterialTypes$(tt%) = FormADDSTD.CheckMaterialType(n% - 1).Caption
End If
Next n%
' Check if any checked. If not, load all standards and exit
If tt% = 0 Then
Call StandardLoadList(FormADDSTD.ListAvailableStandards)
If ierror Then Exit Sub
Exit Sub
End If
' Load available list based on check boxes
FormADDSTD.ListAvailableStandards.Clear
For n% = 1 To NumberOfAvailableStandards%
If StandardIndexMaterialTypes$(n%) <> vbNullString Then
ip% = IPOS1%(tt%, StandardIndexMaterialTypes$(n%), tMaterialTypes$())
If ip% > 0 Then
FormADDSTD.ListAvailableStandards.AddItem StandardGetString$(n%)
FormADDSTD.ListAvailableStandards.ItemData(FormADDSTD.ListAvailableStandards.NewIndex) = StandardIndexNumbers%(n%)
End If
End If
Next n%
Exit Sub
' Errors
AddStdMaterialTypeFilterError:
MsgBox Error$, vbOKOnly + vbCritical, "AddStdMaterialTypeFilter"
ierror = True
Exit Sub
End Sub
Sub AddStdImportPOS()
' Import standard names (numbers) from POS file
ierror = False
On Error GoTo AddStdImportPOSError
Dim tfilename As String
Dim temp1 As Single, temp2 As Single, temp3 As Single, temp4 As Single
Dim pxdata As Single, pydata As Single, pzdata As Single
Dim ptyp As Integer, pnum As Integer, pgnum As Integer, pauto As Integer, psetup As Integer
Dim pnam As String, pfile As String
Dim tpos As Single
Dim lastpnum As Integer
' Get POS file from user
Call IOGetFileName(Int(2), "POS", tfilename$, FormADDSTD)
If ierror Then Exit Sub
' Open import file, see exit on error below
Call IOStatusAuto(vbNullString)
Open tfilename$ For Input As #Position1FileNumber%
' Import fiducials
Input #Position1FileNumber%, temp1!, temp2!, temp3!, temp4!
Input #Position1FileNumber%, temp1!, temp2!, temp3!, temp4!
Input #Position1FileNumber%, temp1!, temp2!, temp3!, temp4!
' Loop on import position samples
Call IOStatusAuto(vbNullString)
Do Until EOF(Position1FileNumber%)
' Read data from file
If PositionImportExportFileType% = 1 Then
Input #Position1FileNumber%, ptyp%, pnum%, pnam$, pxdata!, pydata!, pzdata!, tpos!, pgnum%
' With setup number, etc
ElseIf PositionImportExportFileType% = 2 Then
Input #Position1FileNumber%, ptyp%, pnum%, pnam$, pxdata!, pydata!, pzdata!, tpos!, pgnum%, pauto%, psetup%, pfile$
End If
' See if standard is already in the run and add to "add to" list if not
If ptyp% = 1 And pnum% <> lastpnum% Then
Call AddStdCheck(pnum%)
If ierror Then
Close #Position1FileNumber%
Call IOStatusAuto(vbNullString)
ierror = True
Exit Sub
End If
End If
' Save last std number to skip multiple points
lastpnum% = pnum%
Loop
Close #Position1FileNumber%
Call IOStatusAuto(vbNullString)
Exit Sub
' Errors
AddStdImportPOSError:
MsgBox Error$ & ". (check that correct PositionImportExportFileType is defined in the [software] section of the PFE configuration file " & ProbeWinINIFile$ & ")", vbOKOnly + vbCritical, "AddStdImportPOS"
Close #Position1FileNumber%
Call IOStatusAuto(vbNullString)
ierror = True
Exit Sub
End Sub
Sub AddStdMountNamesFilter()
' Filter the available standard list based on the standard mount name entered
ierror = False
On Error GoTo AddStdMountNamesFilterError
Dim n As Integer, ip As Integer
Dim mstring As String
' Load mount name (assume only one standard mount entered at a time)
mstring$ = Trim$(FormADDSTD.TextMountNames.Text)
' Check if any characters entered. If not, load all standards and exit
If mstring$ = vbNullString Then
Call StandardLoadList(FormADDSTD.ListAvailableStandards)
If ierror Then Exit Sub
Exit Sub
End If
' Load available list based on mount name string entered by user
FormADDSTD.ListAvailableStandards.Clear
For n% = 1 To NumberOfAvailableStandards%
If InStr(UCase$(StandardIndexMountNames$(n%)), UCase$(mstring$)) Then
FormADDSTD.ListAvailableStandards.AddItem StandardGetString$(n%)
FormADDSTD.ListAvailableStandards.ItemData(FormADDSTD.ListAvailableStandards.NewIndex) = StandardIndexNumbers%(n%)
End If
Next n%
Exit Sub
' Errors
AddStdMountNamesFilterError:
MsgBox Error$, vbOKOnly + vbCritical, "AddStdMountNamesFilter"
ierror = True
Exit Sub
End Sub