|
おはようございます。
ついでに引き算
'===================================================================
Sub test2()
Dim s1 As String
Dim s2 As String
s1 = "131"
s2 = "125"
[a1].Value = "'" & strsub(s1, s2)
s1 = "3505100010000100010000200000402111111111"
s2 = "35"
[a2].Value = "'" & strsub(s1, s2)
End Sub
'=================================================================
Function strsub(ByVal str1 As String,ByVal str2 As String) As String
Dim l1 As Long
Dim l2 As Long
Dim g0 As Long
Dim g1 As Long
Dim g2 As Long
Dim g3 As Long
Dim wk As String
Dim hugo As String
g0 = mystrcomp(str1, str2)
hugo = ""
If g0 = -1 Then
wk = str1
str1 = str2
str2 = wk
hugo = "-"
End If
If g0 = 0 Then
strsub = "0"
Else
l1 = Len(str1)
l2 = Len(str2)
g3 = 0
Do While l1 > 0 Or l2 > 0
If l1 > 0 Then g1 = Val(Mid(str1, l1, 1)) Else g1 = 0
If l2 > 0 Then g2 = Val(Mid(str2, l2, 1)) Else g2 = 0
g0 = g1 - g2 - g3
If g0 < 0 Then
g0 = 10 + g0
g3 = 1
Else
g3 = 0
End If
strsub = CStr(g0) & strsub
l1 = l1 - 1
l2 = l2 - 1
Loop
For g0 = 1 To Len(strsub)
If Mid(strsub, g0, 1) <> "0" Then
strsub = Mid(strsub, g0)
Exit For
End If
Next
strsub = hugo & strsub
End If
End Function
'=======================================================================
Function mystrcomp(ByVal strnum1 As String,ByVal strnum2 As String) As Long
' mystrcomp 1 strnum1>strnum2
' 0 strnum1=strnum2
' -1 strnum1<strnum2
Dim x As String
Dim y As String
x = Space(Application.Max(Len(strnum1), Len(strnum2)))
y = x
RSet x = strnum1
RSet y = strnum2
mystrcomp = StrComp(x, y)
End Function
|
|