Home > Software engineering >  VBS base class to write a simple function
VBS base class to write a simple function

Time:09-26

For example:
Integer part can directly integer values to the digits, such as 102.98 after the integer is equal to 10; 54.76 after the integer equal to 54; - 65.3 integer is - 65
Less than two, such as 1.432 processing results of 14; 0.987 processing results - 98; 0.0144 the results of 14
I will deal with logical induction is: an integer, decimal (only to four decimal places, or more than four directly returns 0)
Integer part: divided into greater than or equal to the direct value and does not meet the two values after two times 10
The decimal part: directly multiplied by 10000 in the first two
Good logic understanding but my programming level is too bad, can only for teachers,

CodePudding user response:

The original poster to see how this:
 Option Explicit 

Private Function ValueTransform (ByVal dVal As Double) As Long
Dim iFlag As Long
As Long Dim v

IFlag=1 & amp; Or (dVal & lt; 0)
DVal=Abs (dVal)
If (dVal & lt; 10) Then
DVal=10000 # * dVal
The Else
Do
If (dVal & lt; 1000000 #), Then Exit the Do
DVal=dVal/10000 #
Loop
End the If
V=Int (dVal)
Do
If (v & lt; 100 & amp;) Then the Exit Do
V=v \ 10 & amp;
Loop
ValueTransform=iFlag * v
End the Function

Private Sub Command1_Click ()
The Debug. Print "- 3555=", ValueTransform (3555)
The Debug. Print "- 0.00123=", ValueTransform (0.00123)
The Debug. Print "0.000089=", ValueTransform (0.000089)
The Debug. Print "- 73555=", ValueTransform (73555)
The Debug. Print "- 65.3=", ValueTransform (65.3)
The Debug. Print "1.432=", ValueTransform (1.432)
"Use" string "can also, but must be legitimate" numerical format
"The Debug. Print "- 0.987=", ValueTransform (e56 "0.987")
End Sub
'test results:
'- 3555=- 35
'- 0.00123=- 12
0.00008=0
''- 73555=73
'- 65.3=- 65
1.432=14
''- e56=0.987-98
  • Related