Hallo,
ich habe mal wieder ein kleines Problem.
Ich will mit FullTrim alle Elemente eines Array entfernen, die entweder leer sind oder nur aus Leerzeichen bestehen. Leider kann es aber auch vorkommen, das im Array nur Elemente vorhanden sind die aus Leerzeichen bestehen. Ist dies der Fall so erhalte ich einen Fehler (Type mismatch).
Hier ein Codeschnipsel zum Problem:
Dim vntArray As Variant
Dim vntValue As Variant
Redim vntArray(0 To 3)
vntArray(0) = " "
vntArray(1) = " "
vntArray(2) = " "
vntArray(3) = " "
vntValue = Fulltrim(vntArray)
Kann ich den Fehler umgehen?
Oder muß ich einen anderen Ansatz wählen?
Rainer
R6 zeigt dieses (m.E. fehlerhafte Verhalten) nicht mehr.
Workaround: Eigene Routine schreiben. Anbei ein Beispiel - dieses sollte noch ergänzt werden um ein Trim auf die einzelnen Elemente des Arrays, um gleiche Bedingungen für "" und " " und " " zu schaffen.
HTH,
Bernhard
PS: Die Routine "ErrorHandler" ist durch das eigene Konstrukt zur Fehlerbehandlung zu ersetzen!
Function ArrayRemoveValue (vValues As Variant, vRemoveValue As Variant) As Variant
'==================================================================================================================
' Purpose: Remove a given Value from an array
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
' Arguments:
' vValues - the given array
' vRemoveValue - the value to remove from vValues
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
' Returns: The array without the given value to remove, EMPTY, if there is no value to return !
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
' Created by: Bernhard Koehler on 27.03.2004 Modified by:
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
' Changes:
'==================================================================================================================
Dim vResult () As Variant
Dim vEmpty As Variant 'In case of errors / wrong parameters: An empty array
Dim iLoop As Integer
On Error Goto ErrorRoutine
ArrayRemoveValue = vEmpty 'The default return value
If Isempty (vValues) Then
ArrayRemoveValue = vValues
Exit Function
End If
If Isscalar (vValues) Then
If Cstr (vValues) = "" Then
Redim vResult (0 To 0)
vResult (0) = vValues
ArrayRemoveValue = vValues
Exit Function
Else
If vValues = vRemoveValue Then
ArrayRemoveValue = vEmpty
Exit Function
Else
ArrayRemoveValue = vValues
Exit Function
End If 'of "vValues = vRemoveValue"
End If 'of "vValues = """
End If 'of "Isscalar (vValues)"
iLoop = 0
Forall member In vValues
If Not (member = vRemoveValue) Then
Redim Preserve vResult (iLoop) As Variant
vResult (iLoop) = member
iLoop = iLoop + 1
End If
End Forall
If (iLoop > 0) Then
ArrayRemoveValue = vResult
Else
ArrayRemoveValue = vEmpty
End If
Exit Function
ErrorRoutine:
Call ErrorHandler ("ArrayRemoveValue")
Exit Function
End Function