Das Notes Forum

Domino 9 und frühere Versionen => ND6: Entwicklung => Thema gestartet von: bikerboy am 22.01.07 - 17:14:18

Titel: Konveriterung Array -> String
Beitrag von: bikerboy am 22.01.07 - 17:14:18
Hallo hier eine ganz kurze Sache.


Möchte aus einem Array einen Wert in einen String Konvertieren.

bis jetzt habe ich es folgendermassen versucht :

Code

Dim array(0) as Variant
Dim string as String

string = Cstr(array(0))



funzt aber nicht, er gibt mir einen Typmissmachted zurück.

Bedanke mich schonmal für die Antworten
Titel: Re: Konveriterung Array -> String
Beitrag von: Glombi am 22.01.07 - 17:26:29
Das geht mit Implode alias Join

Concatenates all members of an Array of Strings and returns a string. Elements of the Array are separated by a delimiter, if provided, or the space character (" ").
Syntax
Implode(sourceArray as Variant, [delimiter as String]) as String
Elements
sourceArray
One-dimensional Array containing the substrings to be concatenated. sourceArray can be an array of Strings, or an array of Variants. If sourceArray is an array of Variants, Implode will attempt to convert any non-string elements to Strings.
delimiter
 Optional String containing separation character(s) for the concatenated Strings
Return value
Implode returns a String containing the elements of sourceArray with delimiter between elements, or with the space character " " as a separator if delimiter is not specified.
Usage
Implode creates a String that will hold the concatenation of sourceArray. Implode then iterates through sourceArray, With each iteration, Implode converts the next element of sourceArray to a String, if necessary, and appends it to the concatenation String. If more elements remain in sourceArray, a delimeter (either " " or the specified value) is appended to the concatenation String and Implode continues to iterate. After all elements of sourceArray have been concatenated, Implode returns the concatenation String.
Error handling
Implode will throw a Run-time Type mismatch if:
an element in a variant array cannot be coerced to a string.
the delimiter is set to nothing.
the array passed in is not of either type string or variant.
a list is passed instead of an array.
the array passed in contains an element set to nothing.
the array passed in has not been properly initialized.
Implode will throw a run-time Wrong Number of Dimensions error if the array is not one-dimensional.
Implode will throw a run-time Invalid Use of Null error if the array passed in contains an element set to null or if the delimiter is set to null.
Hinweis  Implode is an alias of Join and is identical in every way.
Titel: Re: Konveriterung Array -> String
Beitrag von: bikerboy am 22.01.07 - 17:49:54
hmmm will nicht.

Code
string = Trim(Implode(Array," "))

ist doch eigentlich richtig, oder?
Titel: Re: Konveriterung Array -> String
Beitrag von: Axel am 22.01.07 - 18:37:59
Die Zeile sieht für sich allein gesehen erstmal soweit richtig aus.

Aber wie sieht die Umgebung aus, sprich der Code drumrum. Und vor allem, was will nicht.

Ein paar mehr Infos wären hilfreich. Mein Kristallkugel ist noch im Winterurlaub.  ;)


Axel

Titel: Re: Konveriterung Array -> String
Beitrag von: Tode am 22.01.07 - 18:41:33
Die sache ist ganz einfach:

Dim array( 0 ) as Variant... So lange da noch nix anderes gelaufen ist, kann array( 0 ) ALLES sein (auch ein NotesDocument, ein Array mit 10 Werten, ein Excel- Objekt )

In diesem Stadium ist ein CStr schlicht und ergreifend nicht möglich (was sollte Cstr( NotesDocument ) auch zurückliefern, um nur ein Beispiel zu nennen).

Du must in array( 0 ) erst mal irgendwas schreiben, dann kannst Du dieses "irgendwas" auch mit CStr umwandeln (sofern sich das Objekt sowas gefallen lässt)...

Tode
Titel: Re: Konveriterung Array -> String
Beitrag von: flaite am 22.01.07 - 20:03:47
Du kannst die Funktion Datatype benutzen, um den Datentyp abzufragen.
Such mal in der Designer-Hilfe nach Datatype.
Titel: Re: Konveriterung Array -> String
Beitrag von: bikerboy am 23.01.07 - 08:43:29
in dem Array steht ja was drin. Es ist immer ein String ! Immer ! Wenn ich mir die Daten aus dem Debugger geben lasse sagt er mir sagor, dass es ein String ist.

der Code drumherum sieht folgendermassen aus.

Code
			searchField = docProfile.GetItemValue("firstkey")(0)
			varSourceArray(0) = docCol.GetItemValue(searchField)(0)
			varResult(0)= Replace( varSourceArray, varFindArray, varReplaceArray)
			searchValue = Trim(Cstr(Implode(varResult(0))))
Titel: Re: Konveriterung Array -> String
Beitrag von: Tode am 23.01.07 - 08:56:15
sach mal: Du hast noch keinen Debugger bemüht, oder ?

in varResult(0) steht ein ARRAY mit einem Wert.

Im Debugger müsste das irgendwie so aussehen:

varResult
  -
      -[0] DeinString

mal ganz abgesehen dass Du in Deinem Code wild zwischen (0) und ohne (0) hin und her springst.


Korrekt wäre das ganze schlicht und ergreifend so:

dim varSourceArray as Variant
Dim varResult as Variant

searchField = docProfile.GetItemValue("firstkey")(0)
varSourceArray = docCol.GetItemValue(searchField)
varResult = Replace( varSourceArray, varFindArray, varReplaceArray)
searchValue = Trim(Cstr(Implode(varResult(0))))

Gruß
Tode


Titel: Re: Konveriterung Array -> String
Beitrag von: bikerboy am 23.01.07 - 09:29:28
in dem Array steht ja was drin. Es ist immer ein String ! Immer ! Wenn ich mir die Daten aus dem Debugger geben lasse sagt er mir sagor, dass es ein String ist.

der Code drumherum sieht folgendermassen aus.

Code
			searchField = docProfile.GetItemValue("firstkey")(0)
			varSourceArray(0) = docCol.GetItemValue(searchField)(0)
			varResult(0)= Replace( varSourceArray, varFindArray, varReplaceArray)
			searchValue = Trim(Cstr(Implode(varResult(0))))

Ich glaube schon dass ich den Debugger angemacht habe oder ?

Und auch mit deiner Version funktioniert es nicht

Habe es nun

Code

Dim varResult as Variant
Dim searchValue as String

varResult = Replace( varSourceArray, varFindArray, varReplaceArray)
searchValue = Trim(Cstr(varResult(0)))


So funktioniert es. Das Implode hat gestört, ohne es geht es jetzt wunderbar.

Danke für die Mühe