Autor Thema: Fulltrim  (Gelesen 7465 mal)

Offline ZaLudtske

  • Senior Mitglied
  • ****
  • Beiträge: 319
  • Geschlecht: Männlich
  • carpe diem
Fulltrim
« am: 20.07.07 - 13:04:54 »
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:

Code

	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
Rainer Zaske

MCSD - C#

Offline koehlerbv

  • Moderator
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 20.460
  • Geschlecht: Männlich
Re: Fulltrim
« Antwort #1 am: 25.07.07 - 00:04:01 »
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!

Code
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

Glombi

  • Gast
Re: Fulltrim
« Antwort #2 am: 25.07.07 - 07:13:16 »
Die KBASE sagt folgendes:

Error: 'Type Mismatch' when using Variant array in LotusScript FullTrim function
Product:
Lotus Notes  >  Lotus Notes  >  Versions 6.5, 6.0, 5.0
Platform(s):
Mac OS, Windows
Doc Number:
1089796

Published   06.08.2003
Technote

Problem

A call to the LotusScript FullTrim function can sometimes result in the following error:
"Type Mismatch."
Further research indicates that this occurs only when a Variant array is passed as the parameter, and the elements of the array contain no text other than spaces, tabs or newline characters.

For example:

Dim d(1) As Variant
d(0)=" "
d(1)=""
result=Fulltrim(d)



Solution
This issue was reported to Quality Engineering as SPR# CDCO4K6KEL and has been fixed in Notes 5.0.12 and 6.0. 

Workaround:

If the application allows, use a String array rather than a Variant array.


Additional code examples:

This code works without causing the error (since there is at least one element with a character other than a space, tab or newline).

Dim d(1) As Variant
d(0)=" "
d(1)="xyz"
result=Fulltrim(d)

This code works without causing the error because a String array is used:

Dim d(1) As String
d(0)=" "
d(1)=""
result=Fulltrim(d)


This code works without causing the error because a single variable Variant is used:

Dim d As Variant
d=" "
result=Fulltrim(d)


Excerpt from the Notes R5 Online Help:

FullTrim function 
Takes an array and eliminates "empty" entries, or takes a string and eliminates duplicate, trailing and leading whitespace.
Syntax
FullTrim( v As Variant ) As Variant
Element
v
Any Array, String, or Variant containing a String.
Return value
A Variant containing a Array or String. If you pass in a String, you get back a String.
If you pass in an Array, you get back an Array.
Usage
Empty for strings is the Empty string.
Empty for numbers is the value 0.
Empty for Variants containing the above are the same. As Well as NULL and Empty.
The  FullTrim Trims strings by eliminating any duplicate whitespaces (SPACE, TAB, NEWLINE) from the center of the string and all whitespace at the beginning and end of the strings.
The number of elements in a returned array may vary as empty elements are removed. If all the elements are removed, an array with one empty element is returned.


Andreas

Offline ZaLudtske

  • Senior Mitglied
  • ****
  • Beiträge: 319
  • Geschlecht: Männlich
  • carpe diem
Re: Fulltrim
« Antwort #3 am: 25.07.07 - 07:16:19 »
Danke für die Infos.

Ich habe das das Problem ähnlich der Lösung von Bernhard gelöst.

Rainer
Rainer Zaske

MCSD - C#

 

Impressum Atnotes.de  -  Powered by Syslords Solutions  -  Datenschutz