<< Click to Display Table of Contents >> Navigation: 3. Script Language > Variable Definitions and Operations > Array -Commands > Array -Commands |
Array Commands
Using the new 1 - dimensional Arrays you can more easily Script tasks.
This Script was derived from a real life Script which has been modified to protect the Origin's Data.
It shows a field where Arrays can be used.
This Sample Script will take a ".csv-File Spreadsheet" and sort it over into a new format (other Header) csv-file.
Which is generally a complicated task, made easy with the SPR.
The Script can easily be adapted to modify your csv-Spreadsheet-Files.
'#EXE:?path\
'#SPI:ForceWrite
'---------------------------------------------------------
' Preparations and Globale Variables
'---------------------------------------------------------
'How long does the Script run?
$$TMA=#dtime#
IEM.
' compiler
VAR.$$FIA=$cmdexe$
ELS.
' editor
VAR.$$FIA=?exeloc\ROHDATEN.csv
EIF.
NEF.$$FIA
$$ERR=File not found:$crlf$ $$FIA.
GTO.ero
EIF.
' Target Filename
VAF.$$OUF=?exeloc\Result.csv
' Define Delimiter
$$DEL=,
VBT.$$DEL
'-----------------------------------------------------------
' Target Headline
'-----------------------------------------------------------
$$HEA=Anrede,Vorname,Weitere Vornamen,Nachname,Firma,Abteilung,Straße geschäftlich,
$$HEA+Straße geschäftlich 2,Straße geschäftlich 3,Ort geschäftlich,Region geschäftlich,Postleitzahl geschäftlich,
$$HEA+Land/Region geschäftlich,Straße privat,Straße privat 2,Straße privat 3,Ort privat,Bundesland/Kanton privat,
$$HEA+$crlf$
' Count elements in Headline
GSC.$$HEA|,|$$ELC|d
' Define Array Numbers for Source and Target Array.
VIN.$$SRC=1
VIN.$$DES=2
ARR.Dim|$$SRC|32
' Dimension Target Array by number of Columns
ARR.Dim|$$DES|$$ELC
'-----------------------------------------------------------
' Write Header
'-----------------------------------------------------------
CTF.$$OUF|$$HEA
'-----------------------------------------------------------
' Load RAW-csv-File into TXT-Commandbuffer
TXT.Load Textfile|$$FIA|$$NUL
IVV.$$NUL<5
$$ERR=Is this file empty?
GTO.ero
EIF.
PRT.$$NUL Lines loaded.
'-----------------------------------------------------------
'
'-----------------------------------------------------------
:Main
' Skip Headline, start in Line 2
VAN.$$CNT=2
' Main Loop (Line by Line)
DOL.
TXT.glt|$$CNT|$$LIN
VRT.$$LIN|$$DEL
GSB.Prepare_Array
GSB.Process_Line
VIC.$$CNT
OOP.($$CNT>($$NUL-1))
' Replace all , with ;
'FIL.RIF|$$OUF|,|;
'-----------------------------------------------------------
'
'-----------------------------------------------------------
:enx
CAL.$$TMA=#dsince#|
MBX.Skript ends after $$TMA Seeconds.||Computer tells
ENR.
'-----------------------------------------------------------
'
'-----------------------------------------------------------
:Prepare_Array
' Copy Line into Array 2
FOR.$$LUP|1|32
$$ELE=
SBD.$$LIN|,|$$LUP|$$ELE
ARR.Set Array|$$SRC|$$LUP|$$ELE
NEX.
RET.
'-----------------------------------------------------------
'-----------------------------------------------------------
:Process_Line
' Jump over if "D" contains nothing Lines
DIC.gfi|"D"|$$LOA
ARR.Get|$$SRC|$$LOA|$$ANZ
VBT.$$ANZ
JNS.$$ANZ|JumpOverLine
' Jump over Lines if there are specified Fields in the csv-File
' Jump over to P3, if P1 starts with P2 not case-sensitive
%TestElement "C"|HPJ|JumpOverLine
%TestElement "G"|CVS565|JumpOverLine
%TestElement "H"|DO-REPLY|JumpOverLine
%TestElement "D"|Initsystem|JumpOverLine
' The letters in this section have been randomized
'--------------
' Move Fields from Spreadsheet 1 to Target Sheet Columns
'--------------
' Vorname
%MoveElement "D"|"B"
' Nachname
%MoveElement "G"|"D"
' Abteilung
%MoveElement "R"|"G"
' Position
%MoveElement "AF"|"H"
' Straße geschäftlich
%MoveElement "AA"|"S"
' Ort geschäftlich
%MoveElement "B"|"L"
'E-Mail-Adresse
%MoveElement "AD"|"AE"
'--------------
' FIXED Values
'--------------
'E-Mail-Typ
%SetElement "AF"|SMTP
'Geburtstag
%SetElement "BO"|0.0.00
'Geschlecht
%SetElement "AA"|Keine Angabe
'Jahrestag
%SetElement "AT"|0.0.00
GSB.Save_Array
:JumpOverLine
RET.
'-----------------------------------------------------------
'-----------------------------------------------------------
' Ziel Array Zeile schreiben
:Save_Array
$$OUP=
FOR.$$LUP|1|$$ELC
ARR.Get|$$DES|$$LUP|$$ELE
$$OUP+$$ELE,
NEX.
'MBX.$$OUP
' Zeile nach Datei schreiben
VRT.$$OUP|,
VAR.$$FIB=$$OUP$crlf$
ATF.$$OUF|$$FIB
RET.
'===========================================================
:ero
$$ERT=There was an Error: $crlf$$$ERR
MBX.$$ERT||Fehler
GTO.enx
'-----------------------------------------------------------
'-----------------------------------------------------------
' MACROS
'-----------------------------------------------------------
' Bewegt ein Element P1 von Array 2 nach P2 Array 1
: %MoveElement 2
#IF PARAMS=2
DIC.gfi|§§§01|$$LOA
DIC.gfi|§§§02|$$LOB
ARR.Get|$$SRC|$$LOA|$$ELE
'PRT.Moving $$LOA->$$LOB ($$ELE)
ARR.Set|$$DES|$$LOB|$$ELE
#ELS
MBX.Zu wenig Parameter!
#EIF
END%
'-----------------------------------------------------------
'
'-----------------------------------------------------------
'-----------------------------------------------------------
'
'-----------------------------------------------------------
' Set Element P1 with fixed value P2
: %SetElement 2
#IF PARAMS=2
$$LOA=§§§01
DIC.gfi|$$LOA|$$LOC
$$LOB=§§§02
VBT.$$LOB
ARR.Set|$$DES|$$LOC|$$LOB
#ELS
MBX.Zu wenig Parameter!
#EIF
END%
-----------------------------------------------------------
'
'-----------------------------------------------------------
' Set Element P1 with fixed value P2
: %GetElement 2
#IF PARAMS=2
DIC.gfi|§§§01|$$LOA
ARR.Get|$$DES|$$LOA|§§§02
#ELS
MBX.Zu wenig Parameter!
#EIF
END%
-----------------------------------------------------------
'
'-----------------------------------------------------------
' Jump over to P3, if P1 starts with P2 not case-sensitive
: %TestElement 3
' Makro-Lokale Variablen
#IF PARAMS=3
DIC.gfi|§§§01|$$LOA
$$LOB=§§§02
$$LAB=§§§03
ARR.Get|$$SRC|$$LOA|$$ANZ
' Not case sensitive
VTL.$$LOB
VTL.$$ANZ
' Trim both
VBT.$$LOB
VBT.$$ANZ
LEN.$$LOB|$$LEN
' $$STA bekommt Left$(String in Länge(Suchwert))
GSS.1|$$LEN|$$ANZ|$$STA
'PRT.Testing: $$ANZ vs. $$LOB
JIV.$$STA=$$LOB|$$LAB
#ELS
MBX.Zu wenig Parameter in Makro "Testelement"!
END.
#EIF
END%
See also:
•SDO.Arr----Small-Introduction-To-A
•Unpack-Array-from-File_Delimiter
•Unpack-Array-from-Var_Delimiiter