/
zafoption.bas
763 lines (633 loc) · 31.6 KB
/
zafoption.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
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
Attribute VB_Name = "CodeZAFOPTION"
' (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 tEDSSpectraUseFlag As Integer ' flag from passed sample
Dim ZAFOptionSample(1 To 1) As TypeSample
Dim FormulaTmpSample(1 To 1) As TypeSample
Sub ZAFOptionLoad(sample() As TypeSample)
' Loads the CalcZAF/CalcImage calculation options form
ierror = False
On Error GoTo ZAFOptionLoadError
Dim i As Integer, ip As Integer, ipp As Integer
' Load the sample
ZAFOptionSample(1) = sample(1)
' Save current use EDS flag for OptionSave procedure
tEDSSpectraUseFlag = ZAFOptionSample(1).EDSSpectraUseFlag
' Enable EDS controls if EDS spectra is available (only utilized by CalcImage)
If ZAFOptionSample(1).EDSSpectraFlag Then
FormZAFOPT.CheckUseEDSSpectra.Enabled = True
Else
FormZAFOPT.CheckUseEDSSpectra.Enabled = False
End If
' Load use EDS flag option (only utilized by CalcImage)
If ZAFOptionSample(1).EDSSpectraUseFlag Then
FormZAFOPT.CheckUseEDSSpectra.value = vbChecked
FormZAFOPT.CommandSelectQuantMethodOrProject.Enabled = True
Else
FormZAFOPT.CheckUseEDSSpectra.value = vbUnchecked
FormZAFOPT.CommandSelectQuantMethodOrProject.Enabled = False
End If
' Load quant method or project (only utilized by CalcImage)
FormZAFOPT.LabelQuantMethodOrProject.Caption = ZAFOptionSample(1).EDSSpectraQuantMethodOrProject$
' Load form with calculation options
If ZAFOptionSample(1).OxideOrElemental% = 1 Then
FormZAFOPT.OptionOxide.value = True
Else
FormZAFOPT.OptionElemental.value = True
End If
' Save DisplayAsOxideFlag option
If ZAFOptionSample(1).DisplayAsOxideFlag = True Then
FormZAFOPT.CheckDisplayAsOxide.value = vbChecked
Else
FormZAFOPT.CheckDisplayAsOxide.value = vbUnchecked
End If
If ZAFOptionSample(1).AtomicPercentFlag = True Then
FormZAFOPT.CheckAtomicPercents.value = vbChecked
Else
FormZAFOPT.CheckAtomicPercents.value = vbUnchecked
End If
' Clear and load combo boxes
FormZAFOPT.ComboDifference.Clear
FormZAFOPT.ComboStoichiometry.Clear
FormZAFOPT.ComboRelative.Clear
FormZAFOPT.ComboRelativeTo.Clear
FormZAFOPT.ComboFormula.Clear
' Elements by difference, stoiciometry or relative to must be specified elements
FormZAFOPT.ComboFormula.AddItem "Sum" ' zero index indicates sum all cations
For i% = 1 To ZAFOptionSample(1).LastChan%
If i% > ZAFOptionSample(1).LastElm% Then
FormZAFOPT.ComboDifference.AddItem ZAFOptionSample(1).Elsyms$(i%)
FormZAFOPT.ComboStoichiometry.AddItem ZAFOptionSample(1).Elsyms$(i%)
FormZAFOPT.ComboRelative.AddItem ZAFOptionSample(1).Elsyms$(i%)
End If
FormZAFOPT.ComboRelativeTo.AddItem ZAFOptionSample(1).Elsyms$(i%)
FormZAFOPT.ComboFormula.AddItem ZAFOptionSample(1).Elsyms$(i%)
Next i%
' Load formula by difference
FormZAFOPT.CheckDifference.value = vbUnchecked
If ZAFOptionSample(1).DifferenceElement$ <> vbNullString Then
ip% = IPOS1B(ZAFOptionSample(1).LastElm + 1, ZAFOptionSample(1).LastChan%, ZAFOptionSample(1).DifferenceElement$, ZAFOptionSample(1).Elsyms$())
ip% = ip% - ZAFOptionSample(1).LastElm%
If ip% > 0 Then
FormZAFOPT.CheckDifference.value = vbChecked
FormZAFOPT.ComboDifference.ListIndex = ip% - 1
End If
End If
' Load defaults based on sample setup
If ZAFOptionSample(1).DifferenceFormulaFlag Then
FormZAFOPT.CheckDifferenceFormula.value = vbChecked
Else
FormZAFOPT.CheckDifferenceFormula.value = vbUnchecked
End If
FormZAFOPT.TextDifferenceFormula.Text = ZAFOptionSample(1).DifferenceFormula$
FormZAFOPT.CheckStoichiometry.value = vbUnchecked
If ZAFOptionSample(1).StoichiometryElement$ <> vbNullString Then
ip% = IPOS1B(ZAFOptionSample(1).LastElm + 1, ZAFOptionSample(1).LastChan%, ZAFOptionSample(1).StoichiometryElement$, ZAFOptionSample(1).Elsyms$())
ip% = ip% - ZAFOptionSample(1).LastElm%
If ip% > 0 Then
FormZAFOPT.CheckStoichiometry.value = vbChecked
FormZAFOPT.ComboStoichiometry.ListIndex = ip% - 1
FormZAFOPT.TextStoichiometry.Text = Str$(ZAFOptionSample(1).StoichiometryRatio!)
End If
End If
FormZAFOPT.CheckRelative.value = vbUnchecked
If ZAFOptionSample(1).RelativeElement$ <> vbNullString And ZAFOptionSample(1).RelativeToElement$ <> vbNullString Then
ip% = IPOS1B(ZAFOptionSample(1).LastElm + 1, ZAFOptionSample(1).LastChan%, ZAFOptionSample(1).RelativeElement$, ZAFOptionSample(1).Elsyms$())
ipp% = IPOS1(ZAFOptionSample(1).LastChan, ZAFOptionSample(1).RelativeToElement$, ZAFOptionSample(1).Elsyms$())
ip% = ip% - ZAFOptionSample(1).LastElm% ' the RelativeElement must be specified but the RelativeToElement can be an analyzed or specified element
If ip% > 0 And ipp% > 0 Then
FormZAFOPT.CheckRelative.value = vbChecked
FormZAFOPT.ComboRelative.ListIndex = ip% - 1
FormZAFOPT.ComboRelativeTo.ListIndex = ipp% - 1
FormZAFOPT.TextRelative.Text = Str$(ZAFOptionSample(1).RelativeRatio!)
End If
End If
If CalculateElectronandXrayRangesFlag Then
FormZAFOPT.CheckCalculateElectronandXrayRanges = vbChecked
Else
FormZAFOPT.CheckCalculateElectronandXrayRanges = vbUnchecked
End If
If UseOxygenFromHalogensCorrectionFlag Then
FormZAFOPT.CheckUseOxygenFromHalogensCorrection.value = vbChecked
Else
FormZAFOPT.CheckUseOxygenFromHalogensCorrection.value = vbUnchecked
End If
If UseOxygenFromSulfurCorrectionFlag Then
FormZAFOPT.CheckUseOxygenFromSulfurCorrection.value = vbChecked
Else
FormZAFOPT.CheckUseOxygenFromSulfurCorrection.value = vbUnchecked
End If
If ZAFOptionSample(1).HydrogenStoichiometryFlag Then FormZAFOPT.CheckHydrogenStoichiometry.value = vbChecked
FormZAFOPT.TextHydrogenStoichiometry.Text = MiscAutoFormatN$(ZAFOptionSample(1).HydrogenStoichiometryRatio!, 2)
If UCase$(app.EXEName) = UCase$("CalcImage") And ProbeDataFileVersionNumber! <= 7.22 Then
FormZAFOPT.CheckHydrogenStoichiometry.Enabled = False
FormZAFOPT.TextHydrogenStoichiometry.Enabled = False
End If
' Load ferrous/ferric options
If ZAFOptionSample(1).FerrousFerricCalculationFlag Then
FormZAFOPT.CheckFerrousFerricCalculation.value = vbChecked
Else
FormZAFOPT.CheckFerrousFerricCalculation.value = vbUnchecked
FormZAFOPT.TextFerrousFerricTotalCations.Enabled = False
FormZAFOPT.TextFerrousFerricTotalOxygens.Enabled = False
End If
FormZAFOPT.TextFerrousFerricTotalCations.Text = Format$(ZAFOptionSample(1).FerrousFerricTotalCations!)
FormZAFOPT.TextFerrousFerricTotalOxygens.Text = Format$(ZAFOptionSample(1).FerrousFerricTotalOxygens!)
FormZAFOPT.OptionFerrousFerricOption(ZAFOptionSample(1).FerrousFerricOption%).value = True ' new Droop option for amphiboles (Moy)
' Load formula calculations
If ZAFOptionSample(1).FormulaElementFlag% Then
FormZAFOPT.CheckFormula.value = vbChecked
Else
FormZAFOPT.CheckFormula.value = vbUnchecked
End If
FormZAFOPT.ComboFormula.ListIndex = 0 ' default to sum of cations
If ZAFOptionSample(1).FormulaRatio! > 0# Then FormZAFOPT.TextFormula.Text = Str$(ZAFOptionSample(1).FormulaRatio!)
If ZAFOptionSample(1).FormulaElement$ <> vbNullString Then
ip% = IPOS1(ZAFOptionSample(1).LastChan%, ZAFOptionSample(1).FormulaElement$, ZAFOptionSample(1).Elsyms$())
If ip% > 0 Then
FormZAFOPT.ComboFormula.ListIndex = ip%
End If
End If
' Load unknown coating controls
FormZAFOPT.ComboCoatingElement.Clear
For i% = 0 To MAXELM% - 1
FormZAFOPT.ComboCoatingElement.AddItem Symlo$(i% + 1)
Next i%
If ZAFOptionSample(1).CoatingFlag% = 0 Then ZAFOptionSample(1).CoatingFlag% = DefaultSampleCoatingFlag% ' 0 = not coated, 1 = coated
If ZAFOptionSample(1).CoatingElement% = 0 Then ZAFOptionSample(1).CoatingElement% = DefaultSampleCoatingElement%
If ZAFOptionSample(1).CoatingDensity! = 0# Then ZAFOptionSample(1).CoatingDensity! = DefaultSampleCoatingDensity!
If ZAFOptionSample(1).CoatingThickness! = 0# Then ZAFOptionSample(1).CoatingThickness! = DefaultSampleCoatingThickness!
ZAFOptionSample(1).CoatingSinThickness! = MathCalculateSinThickness!(DefaultSampleCoatingThickness!, DefaultTakeOff!)
If ZAFOptionSample(1).CoatingFlag% = 1 Then
FormZAFOPT.CheckCoatingFlag.value = vbChecked
Else
FormZAFOPT.CheckCoatingFlag.value = vbUnchecked
End If
FormZAFOPT.ComboCoatingElement.Text = Symlo$(ZAFOptionSample(1).CoatingElement%)
FormZAFOPT.TextCoatingDensity.Text = Format$(ZAFOptionSample(1).CoatingDensity!)
FormZAFOPT.TextCoatingThickness.Text = Format$(ZAFOptionSample(1).CoatingThickness!)
' Sample density
If ZAFOptionSample(1).SampleDensity! = 0# Then ZAFOptionSample(1).SampleDensity! = 5#
FormZAFOPT.TextDensity.Text = Format$(ZAFOptionSample(1).SampleDensity!)
' Disable ferric/ferrous if calculating intensities from concentrations from CalcZAF (allow if CalcImage)
If UCase$(app.EXEName) = UCase$("CalcZAF") Then
If CalcZAFMode% = 0 Then
FormZAFOPT.CheckFerrousFerricCalculation.Enabled = False
FormZAFOPT.TextFerrousFerricTotalCations.Enabled = False
FormZAFOPT.TextFerrousFerricTotalOxygens.Enabled = False
FormZAFOPT.OptionFerrousFerricOption(0).Enabled = False
FormZAFOPT.OptionFerrousFerricOption(1).Enabled = False
FormZAFOPT.OptionFerrousFerricOption(2).Enabled = False
FormZAFOPT.OptionFerrousFerricOption(3).Enabled = False
FormZAFOPT.OptionFerrousFerricOption(4).Enabled = False
FormZAFOPT.OptionFerrousFerricOption(5).Enabled = False
FormZAFOPT.OptionFerrousFerricOption(6).Enabled = False
Else
FormZAFOPT.CheckFerrousFerricCalculation.Enabled = True
FormZAFOPT.TextFerrousFerricTotalCations.Enabled = True
FormZAFOPT.TextFerrousFerricTotalOxygens.Enabled = True
FormZAFOPT.OptionFerrousFerricOption(0).Enabled = True
FormZAFOPT.OptionFerrousFerricOption(1).Enabled = True
FormZAFOPT.OptionFerrousFerricOption(2).Enabled = True
FormZAFOPT.OptionFerrousFerricOption(3).Enabled = True
FormZAFOPT.OptionFerrousFerricOption(4).Enabled = True
FormZAFOPT.OptionFerrousFerricOption(5).Enabled = True
FormZAFOPT.OptionFerrousFerricOption(6).Enabled = True
End If
' Check for data file version if CalcImage
Else
If ProbeDataFileVersionNumber! < 12.7 Then
FormZAFOPT.CheckFerrousFerricCalculation.Enabled = False
FormZAFOPT.TextFerrousFerricTotalCations.Enabled = False
FormZAFOPT.TextFerrousFerricTotalOxygens.Enabled = False
End If
If ProbeDataFileVersionNumber! < 12.97 Then
FormZAFOPT.OptionFerrousFerricOption(0).Enabled = False
FormZAFOPT.OptionFerrousFerricOption(1).Enabled = False
FormZAFOPT.OptionFerrousFerricOption(2).Enabled = False
FormZAFOPT.OptionFerrousFerricOption(3).Enabled = False
FormZAFOPT.OptionFerrousFerricOption(4).Enabled = False
FormZAFOPT.OptionFerrousFerricOption(5).Enabled = False
FormZAFOPT.OptionFerrousFerricOption(6).Enabled = False
End If
End If
Exit Sub
' Errors
ZAFOptionLoadError:
MsgBox Error$, vbOKOnly + vbCritical, "ZAFOptionLoad"
ierror = True
Exit Sub
End Sub
Sub ZAFOptionSave()
' Saves the CalcZAF/CalcImage calculation options form
ierror = False
On Error GoTo ZAFOptionSaveError
Dim i As Integer, j As Integer, ip As Integer
Dim chan As Integer, ipp As Integer
Dim sym As String
' Save use EDS flag option (only utilized by CalcImage)
ZAFOptionSample(1).EDSSpectraUseFlag = False
If FormZAFOPT.CheckUseEDSSpectra.value = vbChecked Then
ZAFOptionSample(1).EDSSpectraUseFlag = True
End If
' Save quant method or project (only utilized by CalcImage)
ZAFOptionSample(1).EDSSpectraQuantMethodOrProject$ = Trim$(FormZAFOPT.LabelQuantMethodOrProject.Caption)
' Check if use EDS flag changed by user (only utilized by CalcImage)
If ZAFOptionSample(1).EDSSpectraUseFlag <> tEDSSpectraUseFlag Then
For i% = 1 To ZAFOptionSample(1).LastElm%
If ZAFOptionSample(1).CrystalNames$(i%) = EDS_CRYSTAL$ Then
If ZAFOptionSample(1).EDSSpectraUseFlag Then
ZAFOptionSample(1).DisableQuantFlag(i%) = 0 ' change disable quant flag in sample to be saved below
Else
ZAFOptionSample(1).DisableQuantFlag(i%) = 1 ' change disable quant flag in sample to be saved below
End If
End If
Next i%
AllAnalysisUpdateNeeded = True ' force analysis update if EDS element quant flag changed
AllAFactorUpdateNeeded = True
End If
' Check for proper oxygen flags
If FormZAFOPT.CheckDisplayAsOxide.value = vbChecked Then
Call ZAFOptionCheckForOxygen
If ierror Then Exit Sub
End If
' Init calculation flags
ZAFOptionSample(1).DifferenceElementFlag% = False
ZAFOptionSample(1).StoichiometryElementFlag% = False
ZAFOptionSample(1).RelativeElementFlag% = False
' Save oxide (stoichiometric oxygen) or elemental mode flag
If FormZAFOPT.OptionOxide.value Then
ZAFOptionSample(1).OxideOrElemental% = 1
Else
ZAFOptionSample(1).OxideOrElemental% = 2
End If
' Save DisplayAsOxideFlag options
If FormZAFOPT.CheckDisplayAsOxide.value = vbChecked Then
ZAFOptionSample(1).DisplayAsOxideFlag = True
Else
ZAFOptionSample(1).DisplayAsOxideFlag = False
End If
' Check if oxygen is analyzed for, if changing to oxide calculation
ip% = IPOS1(ZAFOptionSample(1).LastChan%, Symlo$(ATOMIC_NUM_OXYGEN%), ZAFOptionSample(1).Elsyms$())
If ip% > 0 And ip% <= ZAFOptionSample(1).LastElm% And ZAFOptionSample(1).OxideOrElemental% = 1 Then
If ZAFOptionSample(1).DisableQuantFlag%(ip%) = 0 Then
msg$ = "You cannot calculate oxygen by stoichiometry because Oxygen is already an Analyzed Element. "
msg$ = msg$ & "If you want to display the results as oxides, select Display As Oxides. "
MsgBox msg$
FormZAFOPT.OptionElemental.value = True
End If
End If
If FormZAFOPT.CheckAtomicPercents.value = vbChecked Then
ZAFOptionSample(1).AtomicPercentFlag = True
Else
ZAFOptionSample(1).AtomicPercentFlag = False
End If
' Save other calculation options
ZAFOptionSample(1).DifferenceElement$ = vbNullString
If FormZAFOPT.ComboDifference.ListCount > 0 Then
If FormZAFOPT.CheckDifference.value = vbChecked And FormZAFOPT.ComboDifference.ListIndex > -1 Then
i% = ZAFOptionSample(1).LastElm% + FormZAFOPT.ComboDifference.ListIndex + 1
If i% > ZAFOptionSample(1).LastElm% And i% <= ZAFOptionSample(1).LastChan% Then
ZAFOptionSample(1).DifferenceElement$ = ZAFOptionSample(1).Elsyms$(i%)
End If
End If
End If
' Save formula by difference
If FormZAFOPT.CheckDifferenceFormula.value = vbChecked Then
ZAFOptionSample(1).DifferenceFormulaFlag = True
Else
ZAFOptionSample(1).DifferenceFormulaFlag = False
End If
ZAFOptionSample(1).DifferenceFormula$ = Trim$(FormZAFOPT.TextDifferenceFormula.Text)
' Check for both element by difference and formula by difference
If ZAFOptionSample(1).DifferenceElementFlag And ZAFOptionSample(1).DifferenceFormulaFlag Then
msg$ = "You cannot specify both the element by difference and the formula by difference flags at the same time."
MsgBox msg$, vbOKOnly + vbInformation, "ZAFOptionSave"
ierror = True
Exit Sub
End If
' Convert formula by difference string to temp sample and check for errors
If ZAFOptionSample(1).DifferenceFormulaFlag And Trim$(ZAFOptionSample(1).DifferenceFormula$) <> vbNullString Then
Call FormulaFormulaToSample(ZAFOptionSample(1).DifferenceFormula$, FormulaTmpSample())
If ierror Then Exit Sub
' Check if new elements need to be added as specified elements (from formula by difference string)
For chan% = 1 To FormulaTmpSample(1).LastChan%
ip% = IPOS1(ZAFOptionSample(1).LastChan%, FormulaTmpSample(1).Elsyms$(chan%), ZAFOptionSample(1).Elsyms$()) ' check for analyzed or specified
If ip% = 0 And ZAFOptionSample(1).LastChan% + 1 <= MAXCHAN% Then
ZAFOptionSample(1).LastChan% = ZAFOptionSample(1).LastChan% + 1
ZAFOptionSample(1).Elsyms$(ZAFOptionSample(1).LastChan%) = LCase$(FormulaTmpSample(1).Elsyms$(chan%))
ZAFOptionSample(1).Xrsyms$(ZAFOptionSample(1).LastChan%) = vbNullString ' specified only
ipp% = IPOS1(MAXELM%, ZAFOptionSample(1).Elsyms$(chan%), Symlo$())
If ipp% > 0 Then
ZAFOptionSample(1).numcat%(ZAFOptionSample(1).LastChan%) = AllCat%(ipp%) ' specified only
ZAFOptionSample(1).numoxd%(ZAFOptionSample(1).LastChan%) = AllOxd%(ipp%) ' specified only
End If
End If
Next chan%
' Warn user if analyzed element is in formula by difference string
For chan% = 1 To FormulaTmpSample(1).LastChan%
ip% = IPOS1DQ(ZAFOptionSample(1).LastElm%, FormulaTmpSample(1).Elsyms$(chan%), ZAFOptionSample(1).Elsyms$(), ZAFOptionSample(1).DisableQuantFlag%()) ' check for analyzed only
If ip% > 0 Then
msg$ = "An element in the formula by difference string (" & FormulaTmpSample(1).Elsyms$(chan%) & ") is already present as an analyzed element that is not disabled for quant." & vbCrLf & vbCrLf
msg$ = msg$ & "You can not have an analyzed element duplicated in the formula by difference string, unless you first disable the analyzed element for quantification, and then manually add the element as a specified element (see Elements/Cations dialog)."
MsgBox msg$, vbOKOnly + vbInformation, "ZAFOptionSave"
ierror = True
Exit Sub
End If
Next chan%
End If
ZAFOptionSample(1).StoichiometryElement$ = vbNullString
ZAFOptionSample(1).StoichiometryRatio! = 0#
If FormZAFOPT.ComboStoichiometry.ListCount > 0 Then
If FormZAFOPT.CheckStoichiometry.value = vbChecked And FormZAFOPT.ComboStoichiometry.ListIndex > -1 Then
If Val(FormZAFOPT.TextStoichiometry.Text) > 0# Then
i% = ZAFOptionSample(1).LastElm% + FormZAFOPT.ComboStoichiometry.ListIndex + 1
If i% > ZAFOptionSample(1).LastElm% And i% <= ZAFOptionSample(1).LastChan% Then
ZAFOptionSample(1).StoichiometryElement$ = ZAFOptionSample(1).Elsyms$(i%)
ZAFOptionSample(1).StoichiometryRatio! = Val(FormZAFOPT.TextStoichiometry.Text)
End If
End If
End If
End If
ZAFOptionSample(1).RelativeElement$ = vbNullString
ZAFOptionSample(1).RelativeToElement$ = vbNullString
ZAFOptionSample(1).RelativeRatio! = 0#
If FormZAFOPT.ComboRelative.ListCount > 0 And FormZAFOPT.ComboRelativeTo.ListCount > 0 Then
If FormZAFOPT.CheckRelative.value = vbChecked And FormZAFOPT.ComboRelative.ListIndex > -1 And FormZAFOPT.ComboRelativeTo.ListIndex > -1 Then
If Val(FormZAFOPT.TextRelative.Text) > 0# Then
i% = ZAFOptionSample(1).LastElm% + FormZAFOPT.ComboRelative.ListIndex + 1
j% = FormZAFOPT.ComboRelativeTo.ListIndex + 1
If i% > ZAFOptionSample(1).LastElm% And i% <= ZAFOptionSample(1).LastChan% Then
If j% > 0 And j% <= ZAFOptionSample(1).LastChan% Then
ZAFOptionSample(1).RelativeElement$ = ZAFOptionSample(1).Elsyms$(i%)
ZAFOptionSample(1).RelativeToElement$ = ZAFOptionSample(1).Elsyms$(j%)
ZAFOptionSample(1).RelativeRatio! = Val(FormZAFOPT.TextRelative.Text)
End If
End If
End If
End If
End If
If FormZAFOPT.CheckCalculateElectronandXrayRanges = vbChecked Then
CalculateElectronandXrayRangesFlag = True
Else
CalculateElectronandXrayRangesFlag = False
End If
If FormZAFOPT.CheckUseOxygenFromHalogensCorrection.value = vbChecked Then
UseOxygenFromHalogensCorrectionFlag = True
Else
UseOxygenFromHalogensCorrectionFlag = False
End If
If FormZAFOPT.CheckUseOxygenFromSulfurCorrection.value = vbChecked Then
UseOxygenFromSulfurCorrectionFlag = True
Else
UseOxygenFromSulfurCorrectionFlag = False
End If
' Save hydrogen by excess oxygen stroichiometry
If FormZAFOPT.CheckHydrogenStoichiometry.value = vbChecked Then
ZAFOptionSample(1).HydrogenStoichiometryFlag = True
Else
ZAFOptionSample(1).HydrogenStoichiometryFlag = False
End If
If Val(FormZAFOPT.TextHydrogenStoichiometry.Text) < 0# Or Val(FormZAFOPT.TextHydrogenStoichiometry.Text) > 10# Then
msg$ = "Hydrogen stoichiometry out of range for hydrogen stoichiometry to excess oxyegn (must be between 0 and 10)"
MsgBox msg$, vbOKOnly + vbExclamation, "ZAFOptionSave"
Else
ZAFOptionSample(1).HydrogenStoichiometryRatio! = Val(FormZAFOPT.TextHydrogenStoichiometry.Text)
End If
' Save ferrous/ferric options
If FormZAFOPT.CheckFerrousFerricCalculation.value = vbChecked Then
If Val(FormZAFOPT.TextFerrousFerricTotalCations.Text) <= 0# Or Val(FormZAFOPT.TextFerrousFerricTotalOxygens.Text) <= 0# Then GoTo ZAFOptionSaveMineralCationsOrOxygensZeroOrNegative
ZAFOptionSample(1).FerrousFerricCalculationFlag = True
Else
ZAFOptionSample(1).FerrousFerricCalculationFlag = False
End If
ZAFOptionSample(1).FerrousFerricTotalCations! = Val(FormZAFOPT.TextFerrousFerricTotalCations.Text)
ZAFOptionSample(1).FerrousFerricTotalOxygens! = Val(FormZAFOPT.TextFerrousFerricTotalOxygens.Text)
For i% = 0 To 2
If FormZAFOPT.OptionFerrousFerricOption(i%).value = True Then ZAFOptionSample(1).FerrousFerricOption% = i% ' new Droop option for amphiboles (Moy)
Next i%
' Check for stoichiometric oxygen calculations
If FormZAFOPT.CheckFerrousFerricCalculation.value = vbChecked Then
If ZAFOptionSample(1).OxideOrElemental% = 2 Then GoTo ZAFOptionSaveFerrousFerricRequiresOxygenByStoichiometry
' Check for zero formula for mineral calculations
If ZAFOptionSample(1).FerrousFerricOption% = 0 Then
If Val(FormZAFOPT.TextFerrousFerricTotalCations.Text) <= 0# Or Val(FormZAFOPT.TextFerrousFerricTotalOxygens.Text) <= 0# Then GoTo ZAFOptionSaveMineralCationsOrOxygensZeroOrNegative
End If
End If
' Set calculation flags
If ZAFOptionSample(1).DifferenceElement$ <> vbNullString Then ZAFOptionSample(1).DifferenceElementFlag% = True
If ZAFOptionSample(1).StoichiometryElement$ <> vbNullString Then ZAFOptionSample(1).StoichiometryElementFlag% = True
If ZAFOptionSample(1).RelativeElement$ <> vbNullString Then ZAFOptionSample(1).RelativeElementFlag% = True
' Save formula and mineral end member calculation option
ZAFOptionSample(1).FormulaElement$ = vbNullString
ZAFOptionSample(1).FormulaRatio! = 0#
ZAFOptionSample(1).MineralFlag% = 0
If FormZAFOPT.ComboFormula.ListCount > 0 Then
If FormZAFOPT.ComboFormula.ListIndex > -1 Then
If Val(FormZAFOPT.TextFormula.Text) > 0# Then
i% = FormZAFOPT.ComboFormula.ListIndex ' zero index indicates sum all cations
ZAFOptionSample(1).FormulaRatio! = Val(FormZAFOPT.TextFormula.Text)
' If element is greater than zero then it is a specific cation (no element indicates sum all cations)
If i% > 0 And i% <= ZAFOptionSample(1).LastChan% Then
ZAFOptionSample(1).FormulaElement$ = ZAFOptionSample(1).Elsyms$(i%)
End If
End If
End If
End If
If FormZAFOPT.CheckFormula.value = vbChecked Then
ZAFOptionSample(1).FormulaElementFlag% = True
Else
ZAFOptionSample(1).FormulaElementFlag% = False
End If
' Check for no formula atoms
If ZAFOptionSample(1).FormulaElementFlag% And ZAFOptionSample(1).FormulaRatio! = 0# Then GoTo ZAFOptionSaveNoFormulaAtoms
' Warn user if formula option is checked but no atoms is specified
' (no element is ok since that indicates sum all cations)
If FormZAFOPT.CheckFormula.value = vbChecked And ZAFOptionSample(1).FormulaRatio! = 0# Then
msg$ = "Formula option was selected, but no formula atoms were specified"
MsgBox msg$, vbOKOnly + vbExclamation, "ZAFOptionSave"
ierror = True
Exit Sub
End If
' Sample conductive coating
If FormZAFOPT.CheckCoatingFlag.value = vbChecked Then
ZAFOptionSample(1).CoatingFlag% = 1
Else
ZAFOptionSample(1).CoatingFlag% = 0
End If
sym$ = FormZAFOPT.ComboCoatingElement.Text
ip% = IPOS1(MAXELM%, sym$, Symlo$())
If ip% = 0 Then
msg$ = "Not a valid element for the Sample Conductive Coating"
MsgBox msg$, vbOKOnly + vbExclamation, "ZAFOptionSave"
ierror = True
Exit Sub
End If
ZAFOptionSample(1).CoatingElement% = ip%
If Val(FormZAFOPT.TextCoatingDensity.Text) < 0.1 Or Val(FormZAFOPT.TextCoatingDensity.Text) > 50# Then
msg$ = "Density out of range for the Sample Conductive Coating (must be between 0.1 and 50 gm/cm^3)"
MsgBox msg$, vbOKOnly + vbExclamation, "ZAFOptionSave"
Else
ZAFOptionSample(1).CoatingDensity! = Val(FormZAFOPT.TextCoatingDensity.Text)
End If
If Val(FormZAFOPT.TextCoatingThickness.Text) < 1 Or Val(FormZAFOPT.TextCoatingThickness.Text) > 10000# Then
msg$ = "Thickness out of range for the Sample Conductive Coating (must be between 1 and 10,000 angstroms)"
MsgBox msg$, vbOKOnly + vbExclamation, "ZAFOptionSave"
Else
ZAFOptionSample(1).CoatingThickness! = Val(FormZAFOPT.TextCoatingThickness.Text)
End If
' Store changes to sample coating default globals
DefaultSampleCoatingFlag% = ZAFOptionSample(1).CoatingFlag% ' 0 = not coated, 1 = coated
DefaultSampleCoatingElement% = ZAFOptionSample(1).CoatingElement%
DefaultSampleCoatingDensity! = ZAFOptionSample(1).CoatingDensity!
DefaultSampleCoatingThickness! = ZAFOptionSample(1).CoatingThickness!
' Save coating globals (leave commented out so user has to explicitly turn on in Analytical menu)
If ZAFOptionSample(1).CoatingFlag% = 1 Then
'UseConductiveCoatingCorrectionForElectronAbsorption = True
'UseConductiveCoatingCorrectionForXrayTransmission = True
End If
' Sample density
If Val(FormZAFOPT.TextDensity.Text) < 0.1 Or Val(FormZAFOPT.TextDensity.Text) > 50# Then
msg$ = "Sample Density out of range (must be between 0.1 and 50 gm/cm^3)"
MsgBox msg$, vbOKOnly + vbExclamation, "ZAFOptionSave"
Else
ZAFOptionSample(1).SampleDensity! = Val(FormZAFOPT.TextDensity.Text)
End If
Exit Sub
' Errors
ZAFOptionSaveError:
MsgBox Error$, vbOKOnly + vbCritical, "ZAFOptionSave"
ierror = True
Exit Sub
ZAFOptionSaveNoFormulaAtoms:
msg$ = "No formula atoms were specified. Either uncheck the Formula Element checkbox or specify the formula atoms."
MsgBox msg$, vbOKOnly + vbExclamation, "ZAFOptionSave"
ierror = True
Exit Sub
ZAFOptionSaveFerrousFerricRequiresOxygenByStoichiometry:
msg$ = "Ferrous/ferric ratio calculations requires that oxygen be calculated by stoichiometry."
MsgBox msg$, vbOKOnly + vbExclamation, "ZAFOptionSave"
ierror = True
Exit Sub
ZAFOptionSaveMineralCationsOrOxygensZeroOrNegative:
msg$ = "Either the total mineral cations or the total mineral oxygens are zero or negative for ferrous/ferric ratio calculations."
MsgBox msg$, vbOKOnly + vbExclamation, "ZAFOptionSave"
ierror = True
Exit Sub
End Sub
Sub ZAFOptionReturnSample(sample() As TypeSample)
' Returns the modified sample
ierror = False
On Error GoTo ZAFOptionReturnSampleError
sample(1) = ZAFOptionSample(1)
Exit Sub
' Errors
ZAFOptionReturnSampleError:
MsgBox Error$, vbOKOnly + vbCritical, "ZAFOptionReturnSample"
ierror = True
Exit Sub
End Sub
Sub ZAFOptionOxygen()
' Add oxygen an a specified element if Oxide calculation is selected
ierror = False
On Error GoTo ZAFOptionOxygenError
Dim ip As Integer
' Check if oxygen is already present in ZAFOptionsample
ip% = IPOS1(ZAFOptionSample(1).LastChan%, Symlo$(ATOMIC_NUM_OXYGEN%), ZAFOptionSample(1).Elsyms$())
If ip% > 0 Then Exit Sub
' Check if too many elements
If ZAFOptionSample(1).LastChan% > MAXCHAN% Then Exit Sub
ZAFOptionSample(1).LastChan% = ZAFOptionSample(1).LastChan% + 1
ZAFOptionSample(1).Elsyms$(ZAFOptionSample(1).LastChan%) = Symlo$(ATOMIC_NUM_OXYGEN%)
ZAFOptionSample(1).Xrsyms$(ZAFOptionSample(1).LastChan%) = vbNullString
ZAFOptionSample(1).numcat%(ZAFOptionSample(1).LastChan%) = AllCat%(ATOMIC_NUM_OXYGEN%)
ZAFOptionSample(1).numoxd%(ZAFOptionSample(1).LastChan%) = AllOxd%(ATOMIC_NUM_OXYGEN%)
ZAFOptionSample(1).ElmPercents!(ZAFOptionSample(1).LastChan%) = 0#
Exit Sub
' Errors
ZAFOptionOxygenError:
MsgBox Error$, vbOKOnly + vbCritical, "ZAFOptionOxygen"
ierror = True
Exit Sub
End Sub
Sub ZAFOptionCheckForOxygen()
' Routine to check for analyzed or non-zero specified oxygen, if user selects "DisplayAsOxides".
ierror = False
On Error GoTo ZAFOptionCheckForOxygenError
Dim ip As Integer
' Check for calculated oxygen
If ZAFOptionSample(1).LastElm% = 0 Or ZAFOptionSample(1).LastChan% = 0 Then Exit Sub
If FormZAFOPT.OptionOxide.value = True Then Exit Sub
' Check for analyzed oxygen
ip% = IPOS1(ZAFOptionSample(1).LastElm%, Symlo$(ATOMIC_NUM_OXYGEN%), ZAFOptionSample(1).Elsyms$())
If ip% > 0 Then Exit Sub
' Check if non-zero specified oxygen value
ip% = IPOS1(ZAFOptionSample(1).LastChan%, Symlo$(ATOMIC_NUM_OXYGEN%), ZAFOptionSample(1).Elsyms$())
If ip% > 0 Then
If ZAFOptionSample(1).ElmPercents!(ip%) > 0# Then Exit Sub
End If
' Check if oxygen is element by difference
If ZAFOptionSample(1).DifferenceElementFlag% And MiscStringsAreSame(ZAFOptionSample(1).DifferenceElement$, Symlo$(ATOMIC_NUM_OXYGEN%)) Then Exit Sub
' Check if oxygen is element by relative stoichiometry
If ZAFOptionSample(1).RelativeElementFlag% And MiscStringsAreSame(ZAFOptionSample(1).RelativeElement$, Symlo$(ATOMIC_NUM_OXYGEN%)) Then Exit Sub
' Check if sample is a standard, since it will be automatically specified
If ZAFOptionSample(1).Type% = 1 Then Exit Sub
' Oxygen will not be calculated correctly
msg$ = "WARNING: Display As Oxides was selected, but oxygen is not either an "
msg$ = msg$ & "analyzed element or an unanalyzed element specified with a "
msg$ = msg$ & "concentration greater than zero. Therefore, the "
msg$ = msg$ & "analytical calculations will not be correct."
MsgBox msg$, vbOKOnly + vbExclamation, "ZAFOptionCheckForOxygen"
Exit Sub
' Errors
ZAFOptionCheckForOxygenError:
MsgBox Error$, vbOKOnly + vbCritical, "ZAFOptionCheckForOxygen"
ierror = True
Exit Sub
End Sub
Sub ZAFOptionCheckForExcessOxygen()
' Routine to check for analyzed oxygen and specified hydrogen, if user selects "Hydrogen Stoichiometry".
ierror = False
On Error GoTo ZAFOptionCheckForExcessOxygenError
Dim ip As Integer, ipp As Integer
' Check for specified hydrogen (must be present)
ip% = IPOS1(ZAFOptionSample(1).LastChan%, Symlo$(ATOMIC_NUM_HYDROGEN%), ZAFOptionSample(1).Elsyms$())
If ip% = 0 Then GoTo ZAFOptionCheckForExcessOxygenNoHydrogen
' Check for analyzed oxygen (if analyzed, just exit)
ip% = IPOS1(ZAFOptionSample(1).LastElm%, Symlo$(ATOMIC_NUM_OXYGEN%), ZAFOptionSample(1).Elsyms$())
If ip% > 0 Then Exit Sub
' Oxygen is specified or calculated. Check if non-zero specified oxygen value and exit if non-zero
ipp% = IPOS1(ZAFOptionSample(1).LastChan%, Symlo$(ATOMIC_NUM_OXYGEN%), ZAFOptionSample(1).Elsyms$())
If ipp% > ZAFOptionSample(1).LastElm% Then
If ZAFOptionSample(1).ElmPercents!(ipp%) > 0# Then Exit Sub
End If
' Check if oxygen is element by difference
If ZAFOptionSample(1).DifferenceElementFlag% And MiscStringsAreSame(ZAFOptionSample(1).DifferenceElement$, Symlo$(ATOMIC_NUM_OXYGEN%)) Then Exit Sub
' Check if oxygen is element by relative stoichiometry
If ZAFOptionSample(1).RelativeElementFlag% And MiscStringsAreSame(ZAFOptionSample(1).RelativeElement$, Symlo$(ATOMIC_NUM_OXYGEN%)) Then Exit Sub
' Stoichiometric hydrogen will not be calculated correctly
msg$ = "WARNING: Hydrogen by Stoichiometry was selected, but oxygen is either not an analyzed "
msg$ = msg$ & "element or an unanalyzed element with a specified concentration greater than zero "
msg$ = msg$ & "a calculated element by difference or by relative stoichiometry. Therefore, the "
msg$ = msg$ & "hydrogen stoichiometry calculations will not be correct."
MsgBox msg$, vbOKOnly + vbExclamation, "ZAFOptionCheckForExcessOxygen"
Exit Sub
' Errors
ZAFOptionCheckForExcessOxygenError:
MsgBox Error$, vbOKOnly + vbCritical, "ZAFOptionCheckForExcessOxygen"
ierror = True
Exit Sub
ZAFOptionCheckForExcessOxygenNoHydrogen:
msg$ = "Hydrogen must be a specified element for calculating hydrogen by stoichiometry. See the Elements/Cations button in the Analyze! window."
MsgBox msg$, vbOKOnly + vbExclamation, "ZAFOptionCheckForExcessOxygen"
ierror = True
Exit Sub
End Sub