From 62e508c2a78ac4a9cabe0d9bb878f0f7bd487f88 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Ledure Date: Wed, 30 Nov 2016 16:50:13 +0100 Subject: Access2Base - More accurate CStr function Includes arrays, distinguishes integers and real numbers Side effects in DebugPrint solved Change-Id: Id84203cea1a93dcbc164f8661fcf2f57778b0df8 --- wizards/source/access2base/Compatible.xba | 8 ++------ wizards/source/access2base/Utils.xba | 29 +++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) (limited to 'wizards') diff --git a/wizards/source/access2base/Compatible.xba b/wizards/source/access2base/Compatible.xba index 92012b56a420..77e99bcdc97c 100644 --- a/wizards/source/access2base/Compatible.xba +++ b/wizards/source/access2base/Compatible.xba @@ -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 diff --git a/wizards/source/access2base/Utils.xba b/wizards/source/access2base/Utils.xba index d84259696ce2..8514d95feae5 100644 --- a/wizards/source/access2base/Utils.xba +++ b/wizards/source/access2base/Utils.xba @@ -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 -- cgit