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 ...@@ -23,18 +23,14 @@ Const cstTab = 5
If UBound(pvArgs) >= 0 Then If UBound(pvArgs) >= 0 Then
For i = 0 To UBound(pvArgs) 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?]" If Not Utils._CheckArgument(pvArgs(i), i + 1, vVarTypes(), , False) Then pvArgs(i) = "[TYPE?]"
' End If
Next i Next i
End If End If
Dim sOutput As String, sArg As String Dim sOutput As String, sArg As String
sOutput = "" sOutput = ""
For i = 0 To UBound(pvArgs) 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 ' Add argument to output
If i = 0 Then If i = 0 Then
sOutput = sArg sOutput = sArg
......
...@@ -132,15 +132,24 @@ Public Function _CStr(ByVal pvArg As Variant, ByVal Optional pbShort As Boolean) ...@@ -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 Dim sArg As String, sObject As String, oArg As Object, sLength As String, i As Long, iMax As Long
Const cstLength = 50 Const cstLength = 50
Const cstByteLength = 25 Const cstByteLength = 25
If IsMissing(pbShort) Then pbShort = True
If IsArray(pvArg) Then 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) If pbShort And UBound(pvArg) > cstByteLength Then iMax = cstByteLength Else iMax = UBound(pvArg)
For i = 0 To iMax For i = 0 To iMax
sArg = sArg & Right("00" & Hex(pvArg(i)), 2) sArg = sArg & Right("00" & Hex(pvArg(i)), 2)
Next i Next i
Else Else
If pbShort Then
sArg = "[ARRAY]" 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 End If
Else Else
Select Case VarType(pvArg) Select Case VarType(pvArg)
...@@ -164,13 +173,21 @@ Const cstByteLength = 25 ...@@ -164,13 +173,21 @@ Const cstByteLength = 25
End If End If
End If End If
Case vbVariant : sArg = "[VARIANT]" Case vbVariant : sArg = "[VARIANT]"
Case vbString : sArg = pvArg Case vbString
Case vbBoolean : sArg = Iif(pvArg, "TRUE", "FALSE") ' 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 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) Case Else : sArg = CStr(pvArg)
End Select End Select
End If End If
If IsMissing(pbShort) Then pbShort = True
If pbShort And Len(sArg) > cstLength Then If pbShort And Len(sArg) > cstLength Then
sLength = "(" & Len(sArg) & ")" sLength = "(" & Len(sArg) & ")"
sArg = Left(sArg, cstLength - 5 - Len(slength)) & " ... " & sLength 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