⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 numberformatinfo.cls

📁 这是一个在vb下实现的各种加密程序,可以实现一般的文本加密和文件加密,但是很多算法都是已经被人破解过的.
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 1  'Persistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "NumberFormatInfo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'    CopyRight (c) 2004 Kelly Ethridge
'
'    This file is part of VBCorLib.
'
'    VBCorLib is free software; you can redistribute it and/or modify
'    it under the terms of the GNU Library General Public License as published by
'    the Free Software Foundation; either version 2.1 of the License, or
'    (at your option) any later version.
'
'    VBCorLib is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU Library General Public License for more details.
'
'    You should have received a copy of the GNU Library General Public License
'    along with Foobar; if not, write to the Free Software
'    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'
'    Module: NumberFormatInfo
'

''
' Provides numeric formatting information.
'
' @remarks<br>
' An instance of this class can be used to provide formatting for numeric data
' in places that allow for an <b>IFormatProvider</b> to be supplied. StringBuilder.AppendFormat
' is an example of when a <b>NumberFormatInfo</b> object can be used. Also, an
' instance of <b>NumberFormatInfo</b> can be used stand-alone to format numeric data
' by calling the <b>Format</b> method.
' <p>To format a number using <b>NumberFormatInfo</b>, call the <b>Format</b> method passing
' in the value to be formated.
' @see NumberFormatInfoStatic
' @see IFormatProvider
' @see ICloneable
' @include "..\..\Includes\NumberFormatInfo.txt"
Option Explicit
Implements IObject
Implements IFormatProvider
Implements ICloneable

Private Const PROP_POSITIVESIGN                 As String = "PositiveSign"
Private Const PROP_NEGATIVESIGN                 As String = "NegativeSign"
Private Const PROP_NUMBERDECIMALSEPARATOR       As String = "NumberDecimalSeparator"
Private Const PROP_NUMBERDECIMALDIGITS          As String = "NumberDecimalDigits"
Private Const PROP_NUMBERGROUPSIZES             As String = "NumberGroupSizes"
Private Const PROP_NUMBERNEGATIVEPATTERN        As String = "NumberNegativePattern"
Private Const PROP_NUMBERGROUPSEPARATOR         As String = "NumberGroupSeparator"
Private Const PROP_CURRENCYDECIMALSEPARATOR     As String = "CurrencyDecimalSeparator"
Private Const PROP_CURRENCYDECIMALDIGITS        As String = "CurrencyDecimalDigits"
Private Const PROP_CURRENCYGROUPSIZES           As String = "CurrencyGroupSizes"
Private Const PROP_CURRENCYNEGATIVEPATTERN      As String = "CurrencyNegativePattern"
Private Const PROP_CURRENcYGROUPSEPARATOR       As String = "CurrencyGroupSeparator"
Private Const PROP_CURRENCYSYMBOL               As String = "CurrencySymbol"
Private Const PROP_CURRENCYPOSITIVEPATTERN      As String = "CurrencyPositivePattern"
Private Const PROP_PERCENTDECIMALSEPARATOR      As String = "PercentDecimalSeparator"
Private Const PROP_PERCENTDECIMALDIGITS         As String = "PercentDecimalDigits"
Private Const PROP_PERCENTGROUPSIZES            As String = "PercentGroupSizes"
Private Const PROP_PERCENTNEGATIVEPATTERN       As String = "PercentNegativePattern"
Private Const PROP_PERCENTGROUPSEPARATOR        As String = "PercentGroupSeparator"
Private Const PROP_PERCENTSYMBOL                As String = "PercentSymbol"
Private Const PROP_PERCENTPOSITIVEPATTERN       As String = "PercentPositivePattern"
Private Const PROP_PERMILLESYMBOL               As String = "PerMilleSymbol"
Private Const PROP_NANSYMBOL                    As String = "NaNSymbol"
Private Const PROP_POSITIVEINFINITYSYMBOL       As String = "PositiveInfinitySymbol"
Private Const PROP_NEGATIVEINFINITYSYMBOL       As String = "NegativeInfinitySymbol"
Private Const PROP_ISREADONLY                   As String = "IsReadOnly"

Private Const INTEGER_PRECISION     As Long = 10
Private Const DOUBLE_PRECISION      As Long = 15
Private Const SINGLE_PRECISION      As Long = 7
Private Const EXPONENT_PRECISION    As Long = 6

Private Const CURRENCY_FORMAT       As Long = 67
Private Const DECIMAL_FORMAT        As Long = 68
Private Const EXPONENT_FORMAT       As Long = 69
Private Const FIXED_FORMAT          As Long = 70
Private Const GENERAL_FORMAT        As Long = 71
Private Const NUMBER_FORMAT         As Long = 78
Private Const PERCENT_FORMAT        As Long = 80
Private Const HEX_FORMAT            As Long = 88

Private Const NO_DIGITS             As Long = -1
Private Const DEFAULT_PRECISION     As Long = -1

Private Const SCALE_NAN             As Long = &H80000000
Private Const SCALE_INF             As Long = &H7FFFFFFF

Private Const BUFFER_SIZE           As Long = 1024


''
' Output patterns for negative numbers.
'
' @param [(n)] Negative value inside perenthesis. Negative symbol is not included.
' @param [-n] Negative symbol before the value.
' @param [- n] Negative symbol before the value, separated by a space.
' @param [n-] Negative symbol after the value.
' @param [n -] Negative symbol after the value, separated by a space.
Public Enum NumberNegativePatterns
    [(n)] = 0
    [-n] = 1
    [- n] = 2
    [n-] = 3
    [n -] = 4
End Enum

''
' Output patterns for negative currency values. The <b>$</b> is the currency
' symbol, then <b>-</b> is the negative symbol and <b>n</b> is the number.
'
' @param [($n)]
' @param [-$n]
' @param [$-n]
' @param [$n-]
' @param [(n$)]
' @param [-n$]
' @param [n-$]
' @param [n$-]
' @param [-n $]
' @param [-$ n]
' @param [n $-]
' @param [$ n-]
' @param [$ -n]
' @param [n- $]
' @param [($ n)]
' @param [(n $)]
Public Enum CurrencyNegativePatterns
    [($n)] = 0
    [-$n] = 1
    [$-n] = 2
    [$n-] = 3
    [(n$)] = 4
    [-n$] = 5
    [n-$] = 6
    [n$-] = 7
    [-n $] = 8
    [-$ n] = 9
    [n $-] = 10
    [$ n-] = 11
    [$ -n] = 12
    [n- $] = 13
    [($ n)] = 14
    [(n $)] = 15
End Enum

''
' Output patterns for positive currency values. The <b>$</b> is the currency symbol and <b>n</b> is the number.
'
' @param [$n]
' @param [n$]
' @param [$ n]
' @param [n $]
Public Enum CurrencyPositivePatterns
    [$n] = 0
    [n$] = 1
    [$ n] = 2
    [n $] = 3
End Enum

''
' Output patterns for positive percentage values. The <b>#</b> is the number and the <b>%</b> is the percentage symbol.
'
' @param [# %]
' @param [#%]
' @param [%#]
Public Enum PercentPositivePatterns
    [# %] = 0
    [#%] = 1
    [%#] = 2
End Enum

''
' Output patterns for negative percentage values. The <b>-</b> is the negative symbol,
' <b>#</b> is the number and the <b>%</b> is the percentage symbol.
'
' @param [-# %]
' @param [-#%]
' @param [-%#]
Public Enum PercentNegativePatterns
    [-# %] = 0
    [-#%] = 1
    [-%#] = 2
End Enum

' These are the format types supported by this
' class. They are the uppercase of the format type
' letters used in the format string.
'
Private Enum FormatType
    CustomFormat = -1
    GeneralFormat = 71      ' G
    DecimalFormat = 68      ' D
    NumberFormat = 78       ' N
    HexFormat = 88          ' X
    ExponentFormat = 69     ' E
    FixedFormat = 70        ' F
    CurrencyFormat = 67     ' C
    PercentFormat = 80      ' P
End Enum

' This structure is derived from using the ECVT function.
' The ECVT function converts an IEEE Double to its 3 components
' of digits, precision, and sign.
'
Private Type NumberType
    Scale       As Long
    Precision   As Long
    IsNegative  As BOOL
    Digits()    As Byte
    DigitsSA    As SafeArray1d
End Type

Private Type PropsType
    PositiveSign                As String
    NegativeSign                As String
    NumberDecimalSeparator      As String
    NumberDecimalDigits         As Long
    NumberGroupSizes()          As Long
    NumberNegativePattern       As NumberNegativePatterns
    NumberGroupSeparator        As String
    CurrencyDecimalSeparator    As String
    CurrencyDecimalDigits       As Long
    CurrencyGroupSizes()        As Long
    CurrencyNegativePattern     As CurrencyNegativePatterns
    CurrencyGroupSeparator      As String
    CurrencySymbol              As String
    CurrencyPositivePattern     As CurrencyPositivePatterns
    PercentDecimalSeparator     As String
    PercentDecimalDigits        As Long
    PercentGroupSizes()         As Long
    PercentNegativePattern      As PercentNegativePatterns
    PercentGroupSeparator       As String
    PercentSymbol               As String
    PercentPositivePattern      As PercentPositivePatterns
    PerMilleSymbol              As String
    NaNSymbol                   As String
    PositiveInfinitySymbol      As String
    NegativeInfinitySymbol      As String
    IsReadOnly                  As Boolean
End Type

' sets of string representation of the different output patterns.
Private mCurrencyPositivePatterns() As String
Private mCurrencyNegativePatterns() As String
Private mNumberNegativePatterns()   As String
Private mPercentPositivePatterns()  As String
Private mPercentNegativePatterns()  As String

' utility variables
Private mPtrNumberBuffer    As Long
Private mNumber             As NumberType
Private mAppendStringBuffer As WordBuffer

' this is the set of NumberFormatInfo properties.
Private mProps  As PropsType
Private mLoaded As Boolean


' we'll assume every numeric output will fit in 1024 characters.
Private mOutput(BUFFER_SIZE - 1)    As Integer
Private mOutputPos                  As Long


' used to parse the format specifier components.
Private mFormatSpecifier As WordBuffer


''
' Returns if this instance is read-only.
'
' @return Value indicating if this instance is read-only.
Public Property Get IsReadOnly() As Boolean
    IsReadOnly = mProps.IsReadOnly
End Property

' for internal use only.
Friend Property Let IsReadOnly(ByVal RHS As Boolean)
    mProps.IsReadOnly = RHS
End Property

''
' Returns a clone of this instance.
'
' @return A clone of the original instance.
' @remarks The <b>IsReadOnly</b> is passed to the clone, aswell.
Public Function Clone() As NumberFormatInfo
    Set Clone = New NumberFormatInfo
    Call Clone.CloneHelper(mProps)
End Function

''
' Returns a string representation of negative infinty.
'
' @return Negative infinity string.
' @remarks Negative infinity is achieved by dividing a negative
' number by zero. The default is "-Infinity".
Public Property Get NegativeInfinitySymbol() As String
    Call VerifyLoaded
    NegativeInfinitySymbol = mProps.NegativeInfinitySymbol
End Property

''
' Sets the negative infinity representation.
'
' @param RHS The new string that represents negative infinity.
' @remarks Negative infinity is achieved by dividing a negative
' number by zero. The default is "-Infinity".
Public Property Let NegativeInfinitySymbol(ByRef RHS As String)
    Call VerifyWritable
    Call VerifyLoaded
    mProps.NegativeInfinitySymbol = RHS
End Property

''
' Returns a string representation of positive infinity.
'
' @return Positive infinity string.
' @remarks Positive infinity is achieved by dividing a positive
' number by zero. The default is "Infinity".
Public Property Get PositiveInfinitySymbol() As String
    Call VerifyLoaded
    PositiveInfinitySymbol = mProps.PositiveInfinitySymbol
End Property

''
' Sets the positive infinity representation.
'
' @param RHS The new string representation of positive infinity.
' @remarks Positive infinity is achieved by dividing a positive
' number by zero. The default is "Infinity".
Public Property Let PositiveInfinitySymbol(ByRef RHS As String)
    Call VerifyWritable
    Call VerifyLoaded
    mProps.PositiveInfinitySymbol = RHS
End Property

''
' Returns the permille representation.
'
' @return Permille string representation.
' @remarks From <a href="http://mathworld.wolfram.com/Permil.html">MathWorld</a><br>
' The use of permille (a.k.a. parts per thousand) is a way of
' expressing ratios in terms of whole numbers. Given a ratio or fraction,
' it is converted to a permil-age by multiplying by 1000 and appending a "

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -