Kaydet (Commit) 62e508c2 authored tarafından Jean-Pierre Ledure's avatar Jean-Pierre Ledure

Access2Base - More accurate CStr function

Includes arrays, distinguishes integers and real numbers
Side effects in DebugPrint solved

Change-Id: Id84203cea1a93dcbc164f8661fcf2f57778b0df8
üst 53d261f2
......@@ -23,18 +23,14 @@ Const cstTab = 5
If UBound(pvArgs) >= 0 Then
For i = 0 To UBound(pvArgs)
' If IsError(pvArgs(i)) Then ' IsError gives "Object variable not set" in LO 4,0 ?!?
' pvArgs(i) = "[ERROR]"
' Else
If Not Utils._CheckArgument(pvArgs(i), i + 1, vVarTypes(), , False) Then pvArgs(i) = "[TYPE?]"
' End If
If Not Utils._CheckArgument(pvArgs(i), i + 1, vVarTypes(), , False) Then pvArgs(i) = "[TYPE?]"
Next i
End If
Dim sOutput As String, sArg As String
sOutput = ""
For i = 0 To UBound(pvArgs)
sArg = Utils._CStr(pvArgs(i), _A2B_.DebugPrintShort)
sArg = Replace(Utils._CStr(pvArgs(i), _A2B_.DebugPrintShort), "\;", ";")
' Add argument to output
If i = 0 Then
sOutput = sArg
......
......@@ -132,15 +132,24 @@ Public Function _CStr(ByVal pvArg As Variant, ByVal Optional pbShort As Boolean)
Dim sArg As String, sObject As String, oArg As Object, sLength As String, i As Long, iMax As Long
Const cstLength = 50
Const cstByteLength = 25
If IsMissing(pbShort) Then pbShort = True
If IsArray(pvArg) Then
If VarType(pvArg) = vbByte Or VarType(pvArg) - 8192 = vbByte Then
sArg = ""
sArg = ""
If VarType(pvArg) = vbByte Or VarType(pvArg) = vbArray + vbByte Then
If pbShort And UBound(pvArg) > cstByteLength Then iMax = cstByteLength Else iMax = UBound(pvArg)
For i = 0 To iMax
sArg = sArg & Right("00" & Hex(pvArg(i)), 2)
Next i
Else
sArg = "[ARRAY]"
If pbShort Then
sArg = "[ARRAY]"
Else ' One-dimension arrays only
For i = LBound(pvArg) To UBound(pvArg)
sArg = sArg & Utils._CStr(pvArg(i)) & ";" ' Recursive call
Next i
If Len(sArg) > 1 Then sArg = Left(sArg, Len(sArg) - 1)
End If
End If
Else
Select Case VarType(pvArg)
......@@ -164,13 +173,21 @@ Const cstByteLength = 25
End If
End If
Case vbVariant : sArg = "[VARIANT]"
Case vbString : sArg = pvArg
Case vbBoolean : sArg = Iif(pvArg, "TRUE", "FALSE")
Case vbString
' Replace CR + LF by \n
' Replace semicolon by \; to allow semicolon separated rows
sArg = Replace(Replace(Replace(pvArg, Chr(13), ""), Chr(10), "\n"), ";", "\;")
Case vbBoolean : sArg = Iif(pvArg, "[TRUE]", "[FALSE]")
Case vbByte : sArg = Right("00" & Hex(pvArg), 2)
Case vbSingle, vbDouble, vbCurrency
sArg = Format(pvArg)
If InStr(UCase(sArg), "E") = 0 Then sArg = Format(pvArg, "##0.0##")
sArg = Replace(sArg, ",", ".")
Case vbDate : sArg = Year(pvArg) & "-" & Right("0" & Month(pvArg), 2) & "-" & Right("0" & Day(pvArg), 2) _
& " " & Right("0" & Hour(pvArg), 2) & ":" & Right("0" & Minute(pvArg), 2)
Case Else : sArg = CStr(pvArg)
End Select
End If
If IsMissing(pbShort) Then pbShort = True
If pbShort And Len(sArg) > cstLength Then
sLength = "(" & Len(sArg) & ")"
sArg = Left(sArg, cstLength - 5 - Len(slength)) & " ... " & sLength
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment