-
Notifications
You must be signed in to change notification settings - Fork 1
/
SysExtensions.vb
3567 lines (3106 loc) · 147 KB
/
SysExtensions.vb
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
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports System.Drawing
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Windows.Forms
Public Module SYS
''' <summary>
''' Writes the contents of an embedded resource embedded as Bytes to disk.
''' </summary>
''' <param name="BytesToWrite">Embedded resource</param>
''' <param name="FileName"> Save to file</param>
''' <remarks></remarks>
<System.Runtime.CompilerServices.Extension()>
Public Sub ResourceFileSave(ByVal BytesToWrite() As Byte, ByVal FileName As String)
If IO.File.Exists(FileName) Then
IO.File.Delete(FileName)
End If
Dim FileStream As New System.IO.FileStream(FileName, System.IO.FileMode.OpenOrCreate)
Dim BinaryWriter As New System.IO.BinaryWriter(FileStream)
BinaryWriter.Write(BytesToWrite)
BinaryWriter.Close()
FileStream.Close()
End Sub
Public ReadOnly QuestionTable As String = "Questions"
Public ReadOnly SemanticPatternTable As String = "SemanticPatterns"
Public ReadOnly CeptDataTable As String = "Cept_Data"
Public ReadOnly NymListTable As String = "Nymlist"
Public InstalledApplicationPath As String = Application.StartupPath
Public StopWords As New List(Of String)
'Morse Code
Private MorseCode() As String = {".", "-"}
Enum CorrelationResult
Positive = 1
PositiveHigh = 0.9
PositiveLow = 0.5
None = 0
NegativeLow = -0.5
NegativeHigh = -0.9
Negative = -1
End Enum
Public Enum TextPreProcessingTasks
Space_Punctuation
To_Upper
To_Lower
Lemmatize_Text
Tokenize_Characters
Remove_Stop_Words
Tokenize_Words
Tokenize_Sentences
Remove_Symbols
Remove_Brackets
Remove_Maths_Symbols
Remove_Punctuation
AlphaNumeric_Only
End Enum
''' <summary>
''' Add full stop to end of String
''' </summary>
''' <param name="MESSAGE"></param>
''' <returns></returns>
<System.Runtime.CompilerServices.Extension()>
Public Function AddFullStop(ByRef MESSAGE As String) As String
AddFullStop = MESSAGE
If MESSAGE = "" Then Exit Function
MESSAGE = Trim(MESSAGE)
If MESSAGE Like "*." Then Exit Function
AddFullStop = MESSAGE + "."
End Function
''' <summary>
''' Adds string to end of string (no spaces)
''' </summary>
''' <param name="Str">base string</param>
''' <param name="Prefix">Add before (no spaces)</param>
''' <returns></returns>
<System.Runtime.CompilerServices.Extension()>
Public Function AddPrefix(ByRef Str As String, ByVal Prefix As String) As String
Return Prefix & Str
End Function
''' <summary>
''' Adds Suffix to String (No Spaces)
''' </summary>
''' <param name="Str">Base string</param>
''' <param name="Suffix">To be added After</param>
''' <returns></returns>
<System.Runtime.CompilerServices.Extension()>
Public Function AddSuffix(ByRef Str As String, ByVal Suffix As String) As String
Return Str & Suffix
End Function
''' <summary>
''' GO THROUGH EACH CHARACTER AND ' IF PUNCTUATION IE .!?,:'"; REPLACE WITH A SPACE ' IF ,
''' OR . THEN CHECK IF BETWEEN TWO NUMBERS, IF IT IS ' THEN LEAVE IT, ELSE REPLACE IT WITH A
''' SPACE '
''' </summary>
''' <param name="STRINPUT">String to be formatted</param>
''' <returns></returns>
''' <remarks></remarks>
<System.Runtime.CompilerServices.Extension()>
Public Function AlphaNumericalOnly(ByRef STRINPUT As String) As String
Dim A As Short
For A = 1 To Len(STRINPUT)
If Mid(STRINPUT, A, 1) = "." Or
Mid(STRINPUT, A, 1) = "!" Or
Mid(STRINPUT, A, 1) = "?" Or
Mid(STRINPUT, A, 1) = "," Or
Mid(STRINPUT, A, 1) = ":" Or
Mid(STRINPUT, A, 1) = "'" Or
Mid(STRINPUT, A, 1) = "[" Or
Mid(STRINPUT, A, 1) = """" Or
Mid(STRINPUT, A, 1) = ";" Then
' BEGIN CHECKING PERIODS AND COMMAS THAT ARE IN BETWEEN NUMBERS '
If Mid(STRINPUT, A, 1) = "." Or Mid(STRINPUT, A, 1) = "," Then
If Not (A - 1 = 0 Or A = Len(STRINPUT)) Then
If Not (IsNumeric(Mid(STRINPUT, A - 1, 1)) Or IsNumeric(Mid(STRINPUT, A + 1, 1))) Then
STRINPUT = Mid(STRINPUT, 1, A - 1) & " " & Mid(STRINPUT, A + 1, Len(STRINPUT) - A)
End If
Else
STRINPUT = Mid(STRINPUT, 1, A - 1) & " " & Mid(STRINPUT, A + 1, Len(STRINPUT) - A)
End If
Else
STRINPUT = Mid(STRINPUT, 1, A - 1) & " " & Mid(STRINPUT, A + 1, Len(STRINPUT) - A)
End If
' END CHECKING PERIODS AND COMMAS IN BETWEEN NUMBERS '
End If
Next A
' RETURN PUNCTUATION STRIPPED STRING '
AlphaNumericalOnly = STRINPUT.Replace(" ", " ")
End Function
<Runtime.CompilerServices.Extension()>
Public Sub AppendTextFile(ByRef Text As String, ByRef FileName As String)
UpdateTextFileAs(FileName, Text)
End Sub
''' <summary>
''' COMMENTS : RETURNS THE INVERSE COSECANT OF THE SUPPLIED NUMBER '
''' PARAMETERS: DBLIN - VALUE TO CALCULATE ' RETURNS : INVERSE COSECANT AS A DOUBLE
''' </summary>
''' <param name="DBLIN"></param>
''' <returns>DBLIN - VALUE TO CALCULATE ' RETURNS : INVERSE COSECANT AS A DOUBLE</returns>
<Runtime.CompilerServices.Extension()>
Public Function ARCCOSECANT(ByVal DBLIN As Double) As Double
' '
Const CDBLPI As Double = 3.14159265358979
On Error GoTo PROC_ERR
ARCCOSECANT = Math.Atan(DBLIN / Math.Sqrt(DBLIN * DBLIN - 1)) +
(Math.Sign(DBLIN) - 1) * CDBLPI / 2
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("ERROR: " & Err.Number & ". " & Err.Description, ,
NameOf(ARCCOSECANT))
Resume PROC_EXIT
End Function
'Math Functions
''' <summary>
''' COMMENTS: RETURNS THE ARC COSINE OF THE SUPPLIED NUMBER '
''' PARAMETERS: DBLIN -Number TO RUN ON ' RETURNS : ARC COSINE AS A DOUBLE
''' </summary>
''' <param name="DBLIN"></param>
''' <returns>DBLIN -Number TO RUN ON ' RETURNS : ARC COSINE AS A DOUBLE</returns>
<Runtime.CompilerServices.Extension()>
Public Function ARCCOSINE(ByVal DBLIN As Double) As Double
Const CDBLPI As Double = 3.14159265358979
On Error GoTo PROC_ERR
Select Case DBLIN
Case 1
ARCCOSINE = 0
Case -1
ARCCOSINE = -CDBLPI
Case Else
ARCCOSINE = Math.Atan(DBLIN / Math.Sqrt(-DBLIN * DBLIN + 1)) + CDBLPI / 2
End Select
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("ERROR: " & Err.Number & ". " & Err.Description, ,
NameOf(ARCCOSINE))
Resume PROC_EXIT
End Function
''' <summary>
''' COMMENTS: RETURNS THE INVERSE COTANGENT Of THE SUPPLIED NUMBER '
''' PARAMETERS: DBLIN -VALUE TO CALCULATE ' RETURNS : INVERSE COTANGENT AS A DOUBLE
''' </summary>
''' <param name="DBLIN"></param>
''' <returns>INVERSE COTANGENT AS A DOUBLE</returns>
<Runtime.CompilerServices.Extension()>
Public Function ARCCOTANGENT(ByVal DBLIN As Double) As Double
Const CDBLPI As Double = 3.14159265358979
On Error GoTo PROC_ERR
ARCCOTANGENT = Math.Atan(DBLIN) + CDBLPI / 2
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("ERROR: " & Err.Number & ". " & Err.Description, ,
NameOf(ARCCOTANGENT))
Resume PROC_EXIT
End Function
''' <summary>
''' COMMENTS : RETURNS THE INVERSE SECANT OF THE SUPPLIED NUMBER '
''' PARAMETERS: DBLIN - VALUE TO CALCULATE ' RETURNS : INVERSE SECANT AS A DOUBLE ' '
''' </summary>
''' <param name="DBLIN"></param>
''' <returns>DBLIN - VALUE TO CALCULATE ' RETURNS : INVERSE SECANT AS A DOUBLE</returns>
<Runtime.CompilerServices.Extension()>
Public Function ARCSECANT(ByVal DBLIN As Double) As Double
Const CDBLPI As Double = 3.14159265358979
On Error GoTo PROC_ERR
ARCSECANT = Math.Atan(DBLIN / Math.Sqrt(DBLIN * DBLIN - 1)) +
Math.Sign(Math.Sign(DBLIN) - 1) * CDBLPI / 2
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("ERROR: " & Err.Number & ". " & Err.Description, ,
NameOf(ARCSECANT))
Resume PROC_EXIT
End Function
''' <summary>
''' COMMENTS : RETURNS THE INVERSE SINE OF THE SUPPLIED NUMBER '
''' PARAMETERS: ' '
''' </summary>
''' <param name="DBLIN"></param>
''' <returns>DBLIN - VALUE TO CALCULATE ' RETURNS : INVERSE SINE AS A DOUBLE</returns>
<Runtime.CompilerServices.Extension()>
Public Function ARCSINE(ByVal DBLIN As Double) As Double
Const CDBLPI As Double = 3.14159265358979
On Error GoTo PROC_ERR
Select Case DBLIN
Case 1
ARCSINE = CDBLPI / 2
Case -1
ARCSINE = -CDBLPI / 2
Case Else
ARCSINE = Math.Atan(DBLIN / Math.Sqrt(-DBLIN ^ 2 + 1))
End Select
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("ERROR: " & Err.Number & ". " & Err.Description, ,
NameOf(ARCSINE))
Resume PROC_EXIT
End Function
''' <summary>
''' COMMENTS : RETURNS THE INVERSE TANGENT OF THE SUPPLIED NUMBERS. ' NOTE THAT BOTH VALUES
''' CANNOT BE ZERO. '
''' PARAMETERS: DBLIN - FIRST VALUE ' DBLIN2 - SECOND VALUE ' RETURNS : INVERSE TANGENT AS A
''' DOUBLE ' '
''' </summary>
''' <param name="DBLIN"></param>
''' <param name="DBLIN2"></param>
''' <returns>RETURNS : INVERSE TANGENT AS A DOUBLE</returns>
<Runtime.CompilerServices.Extension()>
Public Function ARCTANGENT(ByVal DBLIN As Double, ByVal DBLIN2 As Double) As Double
Const CDBLPI As Double = 3.14159265358979
On Error GoTo PROC_ERR
Select Case DBLIN
Case 0
Select Case DBLIN2
Case 0
' UNDEFINED '
ARCTANGENT = 0
Case Is > 0
ARCTANGENT = CDBLPI / 2
Case Else
ARCTANGENT = -CDBLPI / 2
End Select
Case Is > 0
ARCTANGENT = If(DBLIN2 = 0, 0, Math.Atan(DBLIN2 / DBLIN))
Case Else
ARCTANGENT = If(DBLIN2 = 0, CDBLPI, (CDBLPI - Math.Atan(Math.Abs(DBLIN2 / DBLIN))) * Math.Sign(DBLIN2))
End Select
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("ERROR: " & Err.Number & ". " & Err.Description, ,
NameOf(ARCTANGENT))
Resume PROC_EXIT
End Function
''' <summary>
''' Comments : Returns the area of a circle
''' </summary>
''' <param name="dblRadius">dblRadius - radius of circle</param>
''' <returns>Returns : area (Double)</returns>
''' <remarks></remarks>
<Runtime.CompilerServices.Extension()>
Public Function AreaOfCircle(ByVal dblRadius As Double) As Double
Const PI = 3.14159265358979
On Error GoTo PROC_ERR
AreaOfCircle = PI * dblRadius ^ 2
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("Error: " & Err.Number & ". " & Err.Description, ,
NameOf(AreaOfCircle))
Resume PROC_EXIT
End Function
<Runtime.CompilerServices.Extension()>
Public Function AreaOfElipse(ByRef Radius1 As Double, ByRef Radius2 As Double) As Double
'Ellipse Formula : Area of Ellipse = πr1r2
'Case 1:
'Find the area and perimeter of an ellipse with the given radii 3, 4.
'Step 1:
'Find the area.
'Area = πr1r2 = 3.14 * 3 * 4 = 37.68 .
AreaOfElipse = Math.PI * Radius1 * Radius2
End Function
''' <summary>
''' Returns the area of a rectangle
''' </summary>
''' <param name="dblLength">dblLength - length of rectangle</param>
''' <param name="dblWidth">width of rectangle</param>
''' <returns></returns>
''' <remarks></remarks>
<Runtime.CompilerServices.Extension()>
Public Function AreaOfRectangle(
ByVal dblLength As Double,
ByVal dblWidth As Double) _
As Double
On Error GoTo PROC_ERR
AreaOfRectangle = dblLength * dblWidth
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("Error: " & Err.Number & ". " & Err.Description, ,
NameOf(AreaOfRectangle))
Resume PROC_EXIT
End Function
<Runtime.CompilerServices.Extension()>
Public Function AreaOFRhombusMethod1(ByRef base As Double, ByRef height As Double) As Double
'Case 1:
'Find the area of a rhombus with the given base 3 and height 4 using Base Times Height Method.
'Step 1:
'Find the area.
'Area = b * h = 3 * 4 = 12.
AreaOFRhombusMethod1 = base * height
End Function
<Runtime.CompilerServices.Extension()>
Public Function AreaOFRhombusMethod2(ByRef Diagonal1 As Double, ByRef Diagonal2 As Double) As Double
'Case 2:
'Find the area of a rhombus with the given diagonals 2, 4 using Diagonal Method.
'Step 1:
'Find the area.
' Area = ½ * d1 * d2 = 0.5 * 2 * 4 = 4.
AreaOFRhombusMethod2 = 0.5 * Diagonal1 * Diagonal2
End Function
<Runtime.CompilerServices.Extension()>
Public Function AreaOFRhombusMethod3(ByRef Side As Double) As Double
'Case 3:
'Find the area of a rhombus with the given side 2 using Trigonometry Method.
'Step 1:
'Find the area.
'Area = a² * SinA = 2² * Sin(33) = 4 * 1 = 4.
AreaOFRhombusMethod3 = (Side * Side) * Math.Sin(33)
End Function
''' <summary>
''' Returns the area of a ring
''' </summary>
''' <param name="dblInnerRadius">dblInnerRadius - inner radius of the ring</param>
''' <param name="dblOuterRadius">outer radius of the ring</param>
''' <returns>area</returns>
''' <remarks></remarks>
<Runtime.CompilerServices.Extension()>
Public Function AreaOfRing(
ByVal dblInnerRadius As Double,
ByVal dblOuterRadius As Double) _
As Double
On Error GoTo PROC_ERR
AreaOfRing = AreaOfCircle(dblOuterRadius) -
AreaOfCircle(dblInnerRadius)
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("Error: " & Err.Number & ". " & Err.Description, ,
NameOf(AreaOfRing))
Resume PROC_EXIT
End Function
''' <summary>
''' Returns the area of a sphere
''' </summary>
''' <param name="dblRadius">dblRadius - radius of the sphere</param>
''' <returns>area</returns>
''' <remarks></remarks>
<Runtime.CompilerServices.Extension()>
Public Function AreaOfSphere(ByVal dblRadius As Double) As Double
Const cdblPI As Double = 3.14159265358979
On Error GoTo PROC_ERR
AreaOfSphere = 4 * cdblPI * dblRadius ^ 2
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("Error: " & Err.Number & ". " & Err.Description, ,
NameOf(AreaOfSphere))
Resume PROC_EXIT
End Function
''' <summary>
''' Returns the area of a square
''' </summary>
''' <param name="dblSide">dblSide - length of a side of the square</param>
''' <returns>area</returns>
''' <remarks></remarks>
<Runtime.CompilerServices.Extension()>
Public Function AreaOfSquare(ByVal dblSide As Double) As Double
On Error GoTo PROC_ERR
AreaOfSquare = dblSide ^ 2
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("Error: " & Err.Number & ". " & Err.Description, ,
NameOf(AreaOfSquare))
Resume PROC_EXIT
End Function
''' <summary>
''' Returns the area of a square
''' </summary>
''' <param name="dblDiag">dblDiag - length of the square's diagonal</param>
''' <returns>area</returns>
''' <remarks></remarks>
<Runtime.CompilerServices.Extension()>
Public Function AreaOfSquareDiag(ByVal dblDiag As Double) As Double
On Error GoTo PROC_ERR
AreaOfSquareDiag = (dblDiag ^ 2) / 2
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("Error: " & Err.Number & ". " & Err.Description, ,
NameOf(AreaOfSquareDiag))
Resume PROC_EXIT
End Function
''' <summary>
''' Returns the area of a trapezoid
''' </summary>
''' <param name="dblHeight">dblHeight - height</param>
''' <param name="dblLength1">length of first side</param>
''' <param name="dblLength2">length of second side</param>
''' <returns>area</returns>
''' <remarks></remarks>
<Runtime.CompilerServices.Extension()>
Public Function AreaOfTrapezoid(
ByVal dblHeight As Double,
ByVal dblLength1 As Double,
ByVal dblLength2 As Double) _
As Double
On Error GoTo PROC_ERR
AreaOfTrapezoid = dblHeight * (dblLength1 + dblLength2) / 2
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("Error: " & Err.Number & ". " & Err.Description, ,
NameOf(AreaOfTrapezoid))
Resume PROC_EXIT
End Function
''' <summary>
''' returns the area of a triangle
''' </summary>
''' <param name="dblLength">dblLength - length of a side</param>
''' <param name="dblHeight">perpendicular height</param>
''' <returns></returns>
''' <remarks>area</remarks>
<Runtime.CompilerServices.Extension()>
Public Function AreaOfTriangle(
ByVal dblLength As Double,
ByVal dblHeight As Double) _
As Double
On Error GoTo PROC_ERR
AreaOfTriangle = dblLength * dblHeight / 2
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("Error: " & Err.Number & ". " & Err.Description, ,
NameOf(AreaOfTriangle))
Resume PROC_EXIT
End Function
''' <summary>
''' </summary>
''' <param name="dblSideA">dblSideA - length of first side</param>
''' <param name="dblSideB">dblSideB - length of second side</param>
''' <param name="dblSideC">dblSideC - length of third side</param>
''' <returns>the area of a triangle</returns>
''' <remarks></remarks>
<Runtime.CompilerServices.Extension()>
Public Function AreaOfTriangle2(
ByVal dblSideA As Double,
ByVal dblSideB As Double,
ByVal dblSideC As Double) As Double
Dim dblCosine As Double
On Error GoTo PROC_ERR
dblCosine = (dblSideA + dblSideB + dblSideC) / 2
AreaOfTriangle2 = Math.Sqrt(dblCosine * (dblCosine - dblSideA) *
(dblCosine - dblSideB) *
(dblCosine - dblSideC))
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("Error: " & Err.Number & ". " & Err.Description, ,
NameOf(AreaOfTriangle2))
Resume PROC_EXIT
End Function
'Numerical
<Runtime.CompilerServices.Extension()>
Public Function ArithmeticMean(ByRef Elements() As Integer) As Double
Dim NumberofElements As Integer = 0
Dim sum As Integer = 0
'Formula:
'Mean = sum of elements / number of elements = a1+a2+a3+.....+an/n
For Each value As Integer In Elements
NumberofElements = NumberofElements + 1
sum = value + value
Next
ArithmeticMean = sum / NumberofElements
End Function
<Runtime.CompilerServices.Extension()>
Public Function ArithmeticMedian(ByRef Elements() As Integer) As Double
Dim NumberofElements As Integer = 0
Dim Position As Integer = 0
Dim P1 As Integer = 0
Dim P2 As Integer = 0
'Count the total numbers given.
NumberofElements = Elements.Length
'Arrange the numbers in ascending order.
Array.Sort(Elements)
'Formula:Calculate Middle Position
'Check Odd Even
If NumberofElements Mod 2 = 0 Then
'Even:
'For even average of number at P1 = n/2 and P2= (n/2)+1
'Then: (P1+P2) / 2
P1 = NumberofElements / 2
P2 = (NumberofElements / 2) + 1
ArithmeticMedian = (Elements(P1) + Elements(P2)) / 2
Else
'Odd:
'For odd (NumberofElements+1)/2
Position = (NumberofElements + 1) / 2
ArithmeticMedian = Elements(Position)
End If
End Function
<Runtime.CompilerServices.Extension()>
Public Function Average(ByVal x As List(Of Double)) As Double
'Takes an average in absolute terms
Dim result As Double
For i = 0 To x.Count - 1
result += x(i)
Next
Return result / x.Count
End Function
''' <summary>
''' Calculating Average Growth Rate Over Regular Time Intervals
''' </summary>
''' <param name="Series"></param>
''' <returns></returns>
<Runtime.CompilerServices.Extension()>
Public Function AverageGrowth(ByRef Series As List(Of Double)) As Double
'GrowthRate = Present / Past / Past
' formula: (present) = (past) * (1 + growth rate)n where n = number of time periods.
'The Average Annual Growth Rate over a number Of years
'means the average Of the annual growth rates over that number Of years.
'For example, assume that In 2005, the price has increased over 2004 by 10%, 2004 over 2003 by 15%, And 2003 over 2002 by 5%,
'then the average annual growth rate from 2002 To 2005 Is (10% + 15% + 5%) / 3 = 10%
Dim NewSeries As New List(Of Double)
For i = 1 To Series.Count
'Calc Each Growth rate
NewSeries.Add(Growth(Series(i - 1), Series(i)))
Next
Return Mean(NewSeries)
End Function
'Text
<Runtime.CompilerServices.Extension()>
Public Function Capitalise(ByRef MESSAGE As String) As String
Dim FirstLetter As String
Capitalise = ""
If MESSAGE = "" Then Exit Function
FirstLetter = Left(MESSAGE, 1)
FirstLetter = UCase(FirstLetter)
MESSAGE = Right(MESSAGE, Len(MESSAGE) - 1)
Capitalise = (FirstLetter + MESSAGE)
End Function
''' <summary>
''' Capitalizes the text
''' </summary>
''' <param name="MESSAGE"></param>
''' <returns></returns>
<System.Runtime.CompilerServices.Extension()>
Public Function CapitaliseTEXT(ByVal MESSAGE As String) As String
Dim FirstLetter As String = ""
CapitaliseTEXT = ""
If MESSAGE = "" Then Exit Function
FirstLetter = Left(MESSAGE, 1)
FirstLetter = UCase(FirstLetter)
MESSAGE = Right(MESSAGE, Len(MESSAGE) - 1)
CapitaliseTEXT = (FirstLetter + MESSAGE)
End Function
''' <summary>
''' Capitalise the first letter of each word / Tilte Case
''' </summary>
''' <param name="words">A string - paragraph or sentence</param>
''' <returns>String</returns>
<Runtime.CompilerServices.Extension()>
Public Function CapitalizeWords(ByVal words As String)
Dim output As System.Text.StringBuilder = New System.Text.StringBuilder()
Dim exploded = words.Split(" ")
If (exploded IsNot Nothing) Then
For Each word As String In exploded
If word IsNot Nothing Then
output.Append(word.Substring(0, 1).ToUpper).Append(word.Substring(1, word.Length - 1)).Append(" ")
End If
Next
End If
Return output.ToString()
End Function
''' <summary>
''' converts charactert to Morse code
''' </summary>
''' <param name="Ch"></param>
''' <returns></returns>
<Runtime.CompilerServices.Extension()>
Public Function CharToMorse(ByRef Ch As String) As String
Select Case Ch
Case "A", "a"
CharToMorse = ".-"
Case "B", "b"
CharToMorse = "-..."
Case "C", "c"
CharToMorse = "-.-."
Case "D", "d"
CharToMorse = "-.."
Case "E", "e"
CharToMorse = "."
Case "F", "f"
CharToMorse = "..-."
Case "G", "g"
CharToMorse = "--."
Case "H", "h"
CharToMorse = "...."
Case "I", "i"
CharToMorse = ".."
Case "J", "j"
CharToMorse = ".---"
Case "K", "k"
CharToMorse = "-.-"
Case "L", "l"
CharToMorse = ".-.."
Case "M", "m"
CharToMorse = "--"
Case "N", "n"
CharToMorse = "-."
Case "O", "o"
CharToMorse = "---"
Case "P", "p"
CharToMorse = ".--."
Case "Q", "q"
CharToMorse = "--.-"
Case "R", "r"
CharToMorse = ".-."
Case "S", "s"
CharToMorse = "..."
Case "T", "t"
CharToMorse = "-"
Case "U", "u"
CharToMorse = "..-"
Case "V", "v"
CharToMorse = "...-"
Case "W", "w"
CharToMorse = ".--"
Case "X", "x"
CharToMorse = "-..-"
Case "Y", "y"
CharToMorse = "-.--"
Case "Z", "z"
CharToMorse = "--.."
Case "1"
CharToMorse = ".----"
Case "2"
CharToMorse = "..---"
Case "3"
CharToMorse = "...--"
Case "4"
CharToMorse = "....-"
Case "5"
CharToMorse = "....."
Case "6"
CharToMorse = "-...."
Case "7"
CharToMorse = "--..."
Case "8"
CharToMorse = "---.."
Case "9"
CharToMorse = "----."
Case "0"
CharToMorse = "-----"
Case " "
CharToMorse = " "
Case "."
CharToMorse = "^"
Case "-"
CharToMorse = "~"
Case Else
CharToMorse = Ch
End Select
End Function
''' <summary>
''' Checks if directory exists If it does not then it is created
''' </summary>
''' <param name="YourPath"></param>
Public Sub ChkDir(ByRef YourPath As String)
If (System.IO.Directory.Exists(YourPath)) = True Then
Else
System.IO.Directory.CreateDirectory(YourPath)
End If
End Sub
''' <summary>
''' FUNCTION: CELSIUSTOFAHRENHEIT '
''' DESCRIPTION: CONVERTS CELSIUS DEGREES TO FAHRENHEIT DEGREES ' WHERE TO PLACE CODE:
''' MODULE '
''' NOTES: THE LARGEST NUMBER CELSIUSTOFAHRENHEIT WILL CONVERT IS 32,767
''' </summary>
''' <param name="intCelsius"></param>
''' <returns></returns>
''' <remarks></remarks>
<Runtime.CompilerServices.Extension()>
Public Function CnvCelsiusToFahrenheit(intCelsius As Integer) As Integer
CnvCelsiusToFahrenheit = (9 / 5) * intCelsius + 32
End Function
'Temperture
''' <summary>
''' FUNCTION: FAHRENHEITTOCELSIUS '
''' DESCRIPTION: CONVERTS FAHRENHEIT DEGREES TO CELSIUS DEGREES '
''' NOTES: THE LARGEST NUMBER FAHRENHEITTOCELSIUS WILL CONVERT IS 32,767 '
''' </summary>
''' <param name="intFahrenheit"></param>
''' <returns></returns>
''' <remarks></remarks>
<Runtime.CompilerServices.Extension()>
Public Function CnvFahrenheitToCelsius(intFahrenheit As Integer) As Integer
CnvFahrenheitToCelsius = (5 / 9) * (intFahrenheit - 32)
End Function
' ***************************** '
' ** SPYDAZ AI MATRIX ** '
' ***************************** '
':FLIUD VOL:
<Runtime.CompilerServices.Extension()>
Public Sub CnvGallonToALL(ByRef GALLON As Integer, ByRef LITRE As Integer, ByRef PINT As Integer)
LITRE = Val(GALLON * 3.79)
PINT = Val(GALLON * 8)
End Sub
':WEIGHT:
<Runtime.CompilerServices.Extension()>
Public Sub CnvGramsTOALL(ByRef GRAM As Integer, ByRef KILO As Integer, ByRef OUNCE As Integer, ByRef POUNDS As Integer)
KILO = Val(GRAM * 0.001)
OUNCE = Val(GRAM * 0.03527337)
POUNDS = Val(GRAM * 0.002204634)
End Sub
<Runtime.CompilerServices.Extension()>
Public Sub CnvkilosTOALL(ByRef KILO As Integer, ByRef GRAM As Integer, ByRef OUNCE As Integer, ByRef POUNDS As Integer)
GRAM = Val(KILO * 1000)
OUNCE = Val(KILO * 35.27337)
POUNDS = Val(KILO * 2.204634141)
End Sub
<Runtime.CompilerServices.Extension()>
Public Sub CnvLitreToALL(ByRef LITRE As Integer, ByRef PINT As Integer, ByRef GALLON As Integer)
PINT = Val(LITRE * 2.113427663)
GALLON = Val(LITRE * 0.263852243)
End Sub
<Runtime.CompilerServices.Extension()>
Public Sub CnvOunceToALL(ByRef OUNCE As Integer, ByRef GRAM As Integer, ByRef KILO As Integer, ByRef POUNDS As Integer)
GRAM = Val(OUNCE * 28.349)
KILO = Val(OUNCE * 0.028349)
POUNDS = Val(OUNCE * 0.0625)
End Sub
<Runtime.CompilerServices.Extension()>
Public Sub CnvPintToALL(ByRef PINT As Integer, ByRef GALLON As Integer, ByRef LITRE As Integer)
LITRE = Val(PINT * 0.473165)
GALLON = Val(PINT * 0.1248455)
End Sub
''' <summary>
''' Checks if String Contains Letters
''' </summary>
''' <param name="str"></param>
''' <returns></returns>
<Runtime.CompilerServices.Extension()>
Public Function ContainsLetters(ByVal str As String) As Boolean
For i = 0 To str.Length - 1
If Char.IsLetter(str.Chars(i)) Then
Return True
End If
Next
Return False
End Function
''' <summary>
''' When two sets of data are strongly linked together we say they have a High Correlation.
''' Correlation is Positive when the values increase together, and Correlation is Negative
''' when one value decreases as the other increases 1 is a perfect positive correlation 0 Is
''' no correlation (the values don't seem linked at all)
''' -1 Is a perfect negative correlation
''' </summary>
''' <param name="X_Series"></param>
''' <param name="Y_Series"></param>
<Runtime.CompilerServices.Extension()>
Public Function Correlation(ByRef X_Series As List(Of Double), ByRef Y_Series As List(Of Double)) As Double
'Step 1 Find the mean Of x, And the mean of y
'Step 2: Subtract the mean of x from every x value (call them "a"), do the same for y (call them "b")
'Results
Dim DifferenceX As List(Of Double) = Difference(X_Series)
Dim DifferenceY As List(Of Double) = Difference(Y_Series)
'Step 3: Calculate : a*b, XSqu And YSqu for every value
'Step 4: Sum up ab, sum up a2 And sum up b2
'Results
Dim SumXSqu As Double = Sum(Square(DifferenceX))
Dim SumYSqu As Double = Sum(Square(DifferenceY))
Dim SumX_Y As Double = Sum(Multiply(X_Series, Y_Series))
'Step 5: Divide the sum of a*b by the square root of [(SumXSqu) × (SumYSqu)]
'Results
Dim Answer As Double = SumX_Y / Math.Sqrt(SumXSqu * SumYSqu)
Return Answer
End Function
''' <summary>
''' COMMENTS : RETURNS THE COSECANT OF THE SUPPLIED NUMBER. ' NOTE THAT SIN(DBLIN) CANNOT
''' EQUAL ZERO. THIS CAN ' HAPPEN IF DBLIN IS A MULTIPLE OF CDBLPI. '
''' PARAMETERS: DBLIN - VALUE TO CALCULATE ' RETURNS : COSECANT AS A DOUBLE ' '
''' </summary>
''' <param name="DBLIN"></param>
''' <returns>DBLIN - VALUE TO CALCULATE ' RETURNS : COSECANT AS A DOUBLE</returns>
<Runtime.CompilerServices.Extension()>
Public Function COSECANT(ByVal DBLIN As Double) As Double
On Error GoTo PROC_ERR
COSECANT = If(Math.Sin(DBLIN) = 0, 0, 1 / Math.Sin(DBLIN))
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("ERROR: " & Err.Number & ". " & Err.Description, ,
NameOf(COSECANT))
Resume PROC_EXIT
End Function
''' <summary>
''' COMMENTS : RETURNS THE COTANGENT OF THE SUPPLIED NUMBER ' FUNCTION IS UNDEFINED IF INPUT
''' VALUE IS A MULTIPLE OF CDBLPI. '
''' PARAMETERS: DBLIN - VALUE TO CALCULATE ' RETURNS : COTANGENT AS A DOUBLE
''' </summary>
''' <param name="DBLIN"></param>
''' <returns>COTANGENT AS A DOUBLE</returns>
<Runtime.CompilerServices.Extension()>
Public Function COTANGENT(ByVal DBLIN As Double) As Double
On Error GoTo PROC_ERR
COTANGENT = If(Math.Tan(DBLIN) = 0, 0, 1 / Math.Tan(DBLIN))
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox("ERROR: " & Err.Number & ". " & Err.Description, ,
NameOf(COTANGENT))
Resume PROC_EXIT
End Function