Array addieren

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Array addieren

Re: Array addieren

Post by just me » 29 Jun 2019, 01:25

Moin,

ich würde es so lösen:

Code: Select all

#NoEnv
IniRead, TestVar, %A_ScriptFullPath%, Umsatz ; Umsatz.ini

; Grundstellung 0 setzen
TagesUmsatz := 0
; RTrim entfernt Zeilenumbrüche am Ende
; StrSplit erstellt ein Array, ...
; ... das mit der For-Schleife abgearbeitet wird
For Index, Einzelposten In StrSplit(RTrim(TestVar, "`r`n"), "`n", "`r")
   Tagesumsatz += Einzelposten

MsgBox, % Format("{:0.2f}", Tagesumsatz)

/* Ins Skript eingebettete INI - nur zum Testen!!!
[Umsatz]
5.30
1.10
5.50
8.10
99.10
58.20
65.70
23.10
[Dummy]
*/

Wie erstellst Du diese 'INI'-Datei? Normalerweise befinden sich innerhalb der [Sektionen] ja Schlüssel=Wert Paare.

Array addieren

Post by centershox » 28 Jun 2019, 17:08

Servus und guten Abend zusammen,

stehe grad vor nem kleinem Problemchen welches ich nichtmehr nur durch passives lesen lösen kann :D

Ich habe ne .ini die seiht folgendermaßen aus

Code: Select all

[Umsatz]
5.30
1.10
5.50
8.10
99.10
58.20
65.70
23.10
Ich will hier alle Werte auslesen und zusammen addieren um einen Gesamtwert zu ermitteln.

Folgend wollte ich es lösen:

Code: Select all

IniRead, TestVar, Umsatz.ini, Umsatz

umsatz_array := StrSplit(TestVar, "`n", "`n")
Tagesumsatz := umsatz_array[2] + umsatz_array[1] + umsatz_array[3] + umsatz_array[4] + umsatz_array[5] + umsatz_array[6] + umsatz_array[7] + umsatz_array[8] + umsatz_array[9] + umsatz_array[12] + umsatz_array[11] + umsatz_array[13] + umsatz_array[14] + umsatz_array[15] + umsatz_array[16] + umsatz_array[17] + umsatz_array[18] + umsatz_array[19] + umsatz_array[20] + umsatz_array[10] + umsatz_array[21] + umsatz_array[22] + umsatz_array[23] + umsatz_array[24] + umsatz_array[25] + umsatz_array[26] + umsatz_array[27] + umsatz_array[28] + umsatz_array[29] + umsatz_array[30] + umsatz_array[31] + umsatz_array[32] + umsatz_array[33] + umsatz_array[34] + umsatz_array[35] + umsatz_array[36] + umsatz_array[37] + umsatz_array[38] + umsatz_array[39] + umsatz_array[40] + umsatz_array[41] + umsatz_array[42] + umsatz_array[43] + umsatz_array[44] + umsatz_array[45] + umsatz_array[46] + umsatz_array[47] + umsatz_array[48] + umsatz_array[49] + umsatz_array[50]

MsgBox, %Tagesumsatz%
Jedoch hauen mir die "leeren" arrays da nen Fehler rein.
Kann man irgendwie definieren, dass die arrays standardmäßig den Wert 0.00 haben oder wie würdet ihr es lösen?

Danke

Mfg Timo

Top