Jump to content

Func is called two times / $array[$pos++] -> $array[PosIncrease()]


Go to solution Solved by guinness,

Recommended Posts

Posted

Ther is no something like $pos++, and that would be easy  like   $array[$pos++]

I cant find out what is the solution for this problem, maybe someone can help me  :)

Thank you!
 

#include <array.au3>

Local $array[1024]
Local $pos = -1


$array[PosIncrease()] &= "start"
For $i = 1 To 10
    $array[PosIncrease()] &= "new value"
    ConsoleWrite($pos & @CR)
Next
$array[PosIncrease()] &= "end"

_ArrayDisplay($array)

Func PosIncrease()
    $pos += 1
    ConsoleWrite("  ++ "& $pos & @CR)
    Return $pos
EndFunc 
Posted (edited)

My bad...

There is solution, just need to fix to start from index 0
:D 

 

#include <array.au3>

Local $array[1024]

_ArrayAdd($array, "start")
For $i = 1 To 10
    _ArrayAdd($array, "new value")
Next
_ArrayAdd($array, "end")

_ArrayDisplay($array)
Edited by CoolBreeze
Posted

maybe Something like this:

#include <array.au3>

Local $array[1024]


$array[1] &= "start"

For $i = 3 To 22 step 2
    $array[$i] &= "new value"
Next

$array[$i] &= "end"
_ArrayDisplay($array)

Saludos

  • Solution
Posted

This works, as I am guessing you already know about _ArrayAdd() and were just thinking outside the box. Good for you.

#include <Array.au3>

Local $aArray[1024]
Local $iIndex = -1

PostIncrement($iIndex)
$aArray[$iIndex] = "Start"

For $i = 1 To 10
    PostIncrement($iIndex)
    $aArray[$iIndex] = "New Value"
Next
PostIncrement($iIndex)
$aArray[$iIndex] = "End"
_ArrayDisplay($aArray)

Func PostDecrement(ByRef $iValue)
    $iValue -= 1
    Return $iValue
EndFunc   ;==>PostDecrement

Func PostIncrement(ByRef $iValue)
    $iValue += 1
    Return $iValue
EndFunc   ;==>PostIncrement

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...