Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
6
Erster Beitrag:
vor 1 Jahr
Letzter Beitrag:
vor 1 Jahr
Beteiligte Autoren:
Peter Muckle, Ruben Sanchez Peña, Stefan Bentvelsen

WM 20: using arrays to build CSV files

Startbeitrag von Peter Muckle am 08.10.2016 12:18

Hi All,

I'm trying to use an array to build a csv file and get the error message

"Attempt to access element2. Number of Elements in Array Dimension 1:1"

I am new to arrays. My code is out of the help file:


MyString1 is string
MyString1 = "%1,%2,%3,%4,%5,%6,%7,%8"

MyArray is array of 1 string
MyArray[1] = QRY_EXPORT.AssessmentIDonDevice
MyArray[2] = QRY_EXPORT.CountryID
MyArray[3] = QRY_EXPORT.RecordName
MyArray[4] = QRY_EXPORT.LocationName
MyArray[5] = QRY_EXPORT.LocationType
MyArray[6] = QRY_EXPORT.Latitude
MyArray[7] = QRY_EXPORT.Longitude
MyArray[8] = QRY_EXPORT.RecordLocation

MyResult is string = StringBuild(MyString1, MyArray)


This is abbreviated; there are 197 items in the array.

Thanks for any help.

Pete

Antworten:

Hi Pete,

if the order of the items is the same as in the Query, I should use something like
from the top of my head, not tested):

MyResult is string
lsItems = HListItem(QRY_EXPORT)
FOR EACH STRING lsItem OF lsItems SEPARATED BY CRLF
MyResult += [", "] + lsItem
END

von Stefan Bentvelsen - am 08.10.2016 13:25
Hi.

Try to define your array like arrMyArray is array of 8 by 1 string.

Too you can try to use arrayadd to populate your array with the values.

Rubén

von Ruben Sanchez Peña - am 08.10.2016 13:50
Thanks for the ideas Stefan and Ruben...I couldn't get either to work so went back to the long way of making strings.

Cheers

Pete

von Peter Muckle - am 09.10.2016 16:11
Hi. For me this code works

MyString1 is string
MyString1 = "%1,%2,%3,%4,%5,%6,%7,%8"

MyArray is array [8] string
MyArray[1] = "1"
MyArray[2] = "1"
MyArray[3] = "1"
MyArray[4] = "1"
MyArray[5] = "1"
MyArray[6] = "1"
MyArray[7] = "1"
MyArray[8] = "1"

sMyResult is string = StringBuild(MyString1, MyArray)

The result is "1,1,1,1,1,1,1,1"

Rubén

von Ruben Sanchez Peña - am 10.10.2016 12:47
Thanks Rubén, it looks like I was missing the square brackets.

Best wishes

Pete

von Peter Muckle - am 18.10.2016 08:34
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.