Public Function UpDataStr() As String
Dim ArrA()
Dim ArrB()
Dim S As String
S = "565*400"
ArrA = Array(205, 305, 355, 405, 455, 505, 605)
ArrB = Split(S, "*")
For I = LBound(ArrA) To UBound(ArrA)
'对比 ...........
Next
'想要的结果是:405*565
End Function
Public Function UpDataStr() As String
Dim StrTemp As String
Dim StrTemp1 As String
Dim ArrA()
Dim ArrB() As String
Dim S As String
S = "155*300"
ArrA = Array(205, 305, 355, 405, 455, 505, 605)
ArrB = Split(S, "*")
For i = LBound(ArrA) To UBound(ArrA)
If ArrA(i) > ArrB(0) Then
K = ArrA(i) - ArrB(0)
StrTemp = ArrA(i) & "*" & ArrB(1)
Exit For
End If
Next
For i = LBound(ArrA) To UBound(ArrA)
If ArrA(i) > ArrB(1) Then
K1 = ArrA(i) - ArrB(1)
StrTemp1 = ArrA(i) & "*" & ArrB(0)
Exit For
End If
Next
If K > K1 Then
UpDataStr = StrTemp1
Else
UpDataStr = StrTemp
End If
Debug.Print UpDataStr
End Function
Public Function UpDataStr() As String
Dim StrTemp As String
Dim ArrA()
Dim ArrB() As String
Dim S As String
S = "155*300"
ArrA = Array(205, 305, 355, 405, 455, 505, 605)
ArrB = Split(S, "*")
Dim k As Integer
Dim k1 As Integer
For j=1 To UBound(ArrB)
For i = 1 To UBound(ArrA)
If ArrA(i) >= ArrB(j) Then
If j = 1 Then
K = ArrA(i) - ArrB(j)
Else
k1= ArrA(i) - ArrB(j)
End If
Exit For
Else
If i = UBound(ArrA)
If j = 1 Then
k=""
Else
k1=""
End If
End If
End If
Next
Next
UpDataStr = k & "*" & k1
'*左右为空表明无符合要求的数据
End Function