home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD100309202000.psc / Misc.bas < prev    next >
Encoding:
BASIC Source File  |  2000-09-21  |  9.6 KB  |  291 lines

  1. Attribute VB_Name = "Misc"
  2. Option Explicit
  3.  
  4. ''''''''''''''''''''''''''''''''''''''''''''''''''''''
  5. ' Sorry, I couldn't come up with a good solution for '
  6. ' scientific notation (see "Exponential_validation").'
  7. ' That's why this module has so much code. If anyone '
  8. ' has a better solution to this module, please send  '
  9. ' it to me at foxdetective007@mailcity.com           '
  10. ''''''''''''''''''''''''''''''''''''''''''''''''''''''
  11.  
  12. Public Exponent As Boolean
  13. Public New_dot_position As Integer
  14. Public Initial_length As Integer
  15. Public Exponential_minus As Boolean
  16. Public Minus As Boolean
  17. Public Sign As Boolean
  18. Public First_digit As Boolean
  19. Public Value1, Value2 As String
  20. Public Result As Double
  21. Public Dot As Boolean
  22. Public x As String
  23. Public Loop_counter As Integer
  24. Public Mode_value As Boolean
  25. Global Memory_register As Double
  26. Public Const E = 2.71828182846
  27. Public Whole_portion As Integer
  28.  
  29. Public Sub Change_sign()
  30. Dim Length As Integer
  31.  
  32. With frmMain
  33.  
  34.    Length = Len(.Number_space.Text) - 1 'program identifies "-" sign
  35.  
  36.     'If "0" is displayed do not print "-" sign
  37.  
  38.     If .Number_space.Text = "0" Then
  39.  
  40.     ElseIf .Number_space.Text <> "0" Then
  41.             
  42.         'If minus is allowed then print it, otherwise hide it
  43.  
  44.         If Minus = False Then
  45.             .Number_space.Text = "-" & .Number_space.Text
  46.             Minus = True
  47.         ElseIf Minus = True Then
  48.             .Number_space.Text = Right(.Number_space.Text, Length) 'program hides "-" sign
  49.             Minus = False 'minus is allowed again
  50.         End If
  51.         
  52.     End If
  53.         
  54. End With
  55.  
  56. End Sub
  57.  
  58. Public Sub Reset()
  59.     
  60.     With frmMain
  61.         Format .Number_space.Text, "######0.##########"
  62.         Sign = False
  63.         First_digit = False
  64.         .Number_space.Text = "0"
  65.         .Function.Text = " "
  66.         .Percentage_indicator.Text = " "
  67.         Value1 = ""
  68.         Value2 = ""
  69.         .Memory_indicator.Text = " "
  70.         Result = 0
  71.         x = 0
  72.         Loop_counter = 0
  73.         Whole_portion = 0
  74.         Dot = False  'decimal point is allowed
  75.         Minus = False 'minus is allowed
  76.         Exponential_minus = False
  77.         Mode_value = False
  78.         .Mode_indicator.Text = ""
  79.         S_S_D = 0
  80.         P_S_D = 0
  81.         Arithmetic_Mean = 0
  82.     End With
  83.     
  84. End Sub
  85.  
  86. Public Sub Square_root()
  87. Dim Square_root As Double
  88. Dim Argument As Double
  89.  
  90. With frmMain
  91.     
  92.     Argument = CDbl(.Number_space.Text)
  93.     If Argument >= 0 Then
  94.         Square_root = Sqr(CDbl(.Number_space.Text))
  95.         .Number_space.Text = Square_root
  96.     Else
  97.         .Number_space.Text = "-ERROR-"
  98.         .Function.Text = " "
  99.         MsgBox "Square root of a negative number is not a real number", _
  100.         vbCritical + vbOKOnly, "Error"
  101.         .Number_space.Text = "0"
  102.         Minus = False
  103.     End If
  104.  
  105. End With
  106.  
  107. End Sub
  108.  
  109. Public Sub Reciprocal()
  110. Dim Original_value As Double
  111.  
  112. With frmMain
  113.     On Error GoTo solution
  114.     Original_value = CDbl(.Number_space.Text)
  115.     If Original_value <> 0 Then
  116.         .Number_space.Text = 1 / Original_value
  117.     Else
  118.         .Number_space.Text = "-ERROR-"
  119.         MsgBox "There is no reciprocal value of 0.", vbCritical + vbOKOnly, "Error"
  120.         .Number_space.Text = "0"
  121.     End If
  122.     Exit Sub
  123. solution:
  124.     Call Misc.solution
  125. End With
  126.  
  127. End Sub
  128.  
  129. Public Sub N_root()
  130.  
  131. With frmMain
  132.     Power = CDbl(.Number_space.Text)
  133.         If Power = 0 Then
  134.             .Number_space.Text = "-ERROR-"
  135.             MsgBox "Zero root of a number doesn't exist", vbCritical + vbOKOnly, _
  136.             "Error"
  137.             .Number_space.Text = "0"
  138.         Else
  139.             If Base < 0 And Power Mod 2 = 0 Then
  140.                 .Number_space.Text = "-ERROR-"
  141.                 MsgBox "nth root of a negative number when n is even, is not a real number", _
  142.                 vbCritical + vbOKOnly, "Error"
  143.                 .Number_space.Text = "0"
  144.             ElseIf Base < 0 And Power Mod 2 <> 0 Then
  145.                  Result = -(Abs(Base) ^ (1 / Power))
  146.                 .Number_space.Text = Result
  147.             Else
  148.                 Result = Base ^ (1 / Power)
  149.                 .Number_space.Text = Result
  150.             End If
  151.         End If
  152. End With
  153.  
  154. End Sub
  155.  
  156. Public Function LogN(x As Double, N As Double) As Double
  157.    LogN = Log(x) / Log(N)
  158. End Function
  159.  
  160. Public Function LgN(x As Double) As Double
  161.    LgN = Log(x) / Log(E)
  162. End Function
  163.  
  164. Public Sub solution()
  165.     With frmMain
  166.         .Number_space.Text = "-ERROR-"
  167.         .EXP.Text = ""
  168.         MsgBox "An error has occurred in the calculation. Clear all and try again.", _
  169.         vbCritical + vbOKOnly, "Error"
  170.         .Number_space.Text = "0"
  171.     End With
  172. End Sub
  173.  
  174. Public Sub Change_exponential_sign()
  175. Dim Length As Integer
  176.  
  177. With frmMain
  178.  
  179.    Length = Len(.EXP.Text) - 1 'program identifies "-" sign
  180.  
  181.     'If "00" is displayed do not print "-" sign
  182.  
  183.     If .EXP.Text = "00" Then
  184.  
  185.     ElseIf .EXP.Text <> "00" Then
  186.         'If exponential minus is allowed then print it, otherwise hide it
  187.         
  188.         If Exponential_minus = False Then
  189.             .EXP.Text = "-" & .EXP.Text
  190.             Exponential_minus = True
  191.         ElseIf Exponential_minus = True Then
  192.             .EXP.Text = Right(.EXP.Text, Length) 'program hides "-" sign
  193.             Exponential_minus = False 'exponential minus is allowed again
  194.         End If
  195.         
  196.     End If
  197.         
  198. End With
  199.  
  200. End Sub
  201.  
  202. Public Sub Exponential_validation()
  203.  
  204. With frmMain
  205.     If Exponent = False Then
  206.         Value1 = .Number_space.Text
  207.         Value2 = " "
  208.     ElseIf Exponent = True Then
  209.         If Right(Left(Abs(.Number_space.Text), 2), 1) <> "." Then
  210.             If Right(.Number_space.Text, 1) = "" Then
  211.                 'do nothing
  212.             Else:
  213.                 If Misc.Whole_portion > 1 Then
  214.                     If CDbl(.Number_space.Text) > 0 Then
  215.                         .Number_space.Text = CDbl(.Number_space.Text) / 10 ^ (Whole_portion - 1)
  216.                         New_dot_position = Misc.Whole_portion - 1
  217.                         .EXP.Text = .EXP.Text + New_dot_position
  218.                         Exponential_value1 = .EXP.Text
  219.                         Value1 = .Number_space.Text * 10 ^ (Exponential_value1)
  220.                     ElseIf CDbl(.Number_space.Text) < 0 Then
  221.                         .Number_space.Text = -(Abs(CDbl(.Number_space.Text))) / 10 ^ (Whole_portion - 1)
  222.                         New_dot_position = Misc.Whole_portion - 1
  223.                         .EXP.Text = .EXP.Text + New_dot_position
  224.                         Exponential_value1 = .EXP.Text
  225.                         Value1 = .Number_space.Text * 10 ^ (Exponential_value1)
  226.                     End If
  227.                 ElseIf Misc.Whole_portion < 1 Then
  228.                     If CDbl(.Number_space.Text) > 0 Then
  229.                         Initial_length = Len(.Number_space.Text)
  230.                     ElseIf CDbl(.Number_space.Text) < 0 Then
  231.                         Initial_length = Len(.Number_space.Text) - 1
  232.                     End If
  233.                     .Number_space.Text = CDbl(.Number_space.Text) / 10 ^ (Initial_length - 1)
  234.                     .EXP.Text = .EXP.Text + Initial_length - 1
  235.                     Exponential_value1 = .EXP.Text
  236.                     Value1 = .Number_space.Text * 10 ^ (Exponential_value1)
  237.                     If Abs(Exponential_value1) > 99 Then
  238.                         .EXP.Text = ""
  239.                         .Number_space.Text = "-ERROR-"
  240.                         MsgBox "The exponent value must lie within the range from -99 to 99 inclusive.", _
  241.                         vbOKOnly + vbCritical, "Error"
  242.                         .Number_space.Text = "0"
  243.                     End If
  244.                 Else
  245.                     Exponential_value1 = .EXP.Text
  246.                     Value1 = .Number_space.Text * 10 ^ (Exponential_value1)
  247.                     Value2 = " "
  248.                 End If
  249.             End If
  250.         Else:
  251.             If Right(Left(Abs(.Number_space.Text), 2), 2) = "0." Then
  252.                 Do
  253.                     x = Right(Left(Abs(.Number_space.Text), 1), Loop_counter)
  254.                     Loop_counter = Loop_counter + 1
  255.                 Loop Until x <> "0" And x <> "."
  256.                
  257.                     .Number_space.Text = CDbl(.Number_space.Text) * 10 ^ (Loop_counter)
  258.                     If CDbl(.Number_space.Text) > 0 Then
  259.                         If CDbl(.EXP.Text) > 0 Then
  260.                             .EXP.Text = .EXP.Text - (Loop_counter)
  261.                         ElseIf CDbl(.EXP.Text) < 0 Then
  262.                             .EXP.Text = -(Abs(.EXP.Text) + Loop_counter)
  263.                         End If
  264.                     ElseIf CDbl(.Number_space.Text) < 0 Then
  265.                         If CDbl(.EXP.Text) > 0 Then
  266.                             .EXP.Text = .EXP.Text - Loop_counter
  267.                         ElseIf CDbl(.EXP.Text) < 0 Then
  268.                             .EXP.Text = -(Abs(.EXP.Text) + Loop_counter)
  269.                         End If
  270.                     End If
  271.                         Exponential_value1 = .EXP.Text
  272.                         Value1 = .Number_space.Text * 10 ^ (Exponential_value1)
  273.                 
  274.                 If Abs(Exponential_value1) > 99 Then
  275.                     .EXP.Text = ""
  276.                     .Number_space.Text = "-ERROR-"
  277.                     MsgBox "The exponent value must lie within the range from -99 to 99 inclusive.", _
  278.                     , vbOKOnly + vbCritical, "Error"
  279.                     .Number_space.Text = "0"
  280.                 End If
  281.             Else
  282.             
  283.             End If
  284.         End If
  285.         Exponent = False
  286.     End If
  287. End With
  288.  
  289. End Sub
  290.  
  291.