nguyênthtaihl
Thành viên mới
- Tham gia
- 20/4/09
- Bài viết
- 22
- Được thích
- 1
- Giới tính
- Nam
Tự nhiên bạn cho 1 đóng số liệu rồi bảo tình XOR ---> Là tính cái gì đâyChào mọi người!
em đang làm lập trình! mọi lần phải tính XOR thủ công mất nhiều thời gian quá!
mong mọi người chỉ bảo cho em cách tính XOR!
Trân trọng cảm ơn.
Function MyCheck(Cas As Byte) As Boolean
Dim A, B, C, D
A = 10: B = 8: C = 6: D = Null ' Initialize variables.
Select Case Cas
Case 1
MyCheck = A > B Xor B > C ' True;True => False.
Case 2
MyCheck = B > A Xor B > C ' False;True => True.
Case 3
MyCheck = B > A Xor C > B ' False;False => False.
Case 4
MyCheck = B > D Xor A > B ' Returns Null.
Case 5
MyCheck = A Xor B ' Returns 2 (bitwise comparison).
Case 6
MyCheck = A Xor D ' Returns NULL.
End Select
End Function
Function CucTri(rData As Range) As Variant
'Returns a two-element variant containing a min and max value for chart'
'scales based on the min and max values in the data range, computing'
'values with the least number of significant digits necessary for the'
'data range to cover some minimum fraction (dMinFrac) of the chart range.'
Const dMinFrac As Double = 0.8
Dim NumMin As Double, NumMax As Double 'min and max of data range'
Dim GHD As Double, GHT As Double ' min and max of chart range'
Dim dLog As Double: Dim nDigit As Integer
With WorksheetFunction
'Get the min and max of the data range'
NumMin = .Min(rData): NumMax = .Max(rData)
'If the data has a zero-span range, return that range'
If NumMin = NumMax Then
CucTri = Array(NumMin, NumMax)
Exit Function '- - - - - - - - - - - - - - - - - - - - - - - - ->'
End If
'Compute the digit position for one significant digit'
dLog = Log(.Max(Abs(NumMax), Abs(NumMin))) / Log(10)
nDigit = CInt(dRndUpDn(-dLog, 1, False))
Do
'Round the min down, and the max up, to the computed significance'
GHD = dRndUpDn(NumMin, nDigit, False)
GHT = dRndUpDn(NumMax, nDigit, True)
'If this chart range is sufficiently narrow for data range, finish;'
'otherwise, add another significant digit and try again'
If (NumMax - NumMin) / (GHT - GHD) >= dMinFrac Then
Exit Do '- - - - - - - - - - - - - - - - - - - - - - - - ->'
Else
nDigit = nDigit + 1
End If
Loop
End With
'Return the computed values as a two-element variant
CucTri = Array(GHD, GHT)
End Function
Function dRndUpDn(dNum As Double, nDigit As Integer, bUpdn As Boolean) As Double
'Returns a Double rounded up or down to the specified significance.'
'Unlike ROUNDDOWN() and ROUNDUP(), this function rounds in absolute'
'direction, rather than toward or away from zero.'
'bUpDn = False => Round Down'
'= True => Round Up'
If dNum = 0 Then Exit Function '- - - - - - - - - - - - - - - - - ->'
With WorksheetFunction
If dNum > 0 Xor bUpdn Then '<=|'
dRndUpDn = .RoundDown(dNum, nDigit)
Else
dRndUpDn = .RoundUp(dNum, nDigit)
End If
End With
End Function