Cascade An Array All At Once, Instead Of Step By Step

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
roonyrooxcess
Posts: 61
Joined: 20 Nov 2020, 21:29

Cascade An Array All At Once, Instead Of Step By Step

06 May 2021, 17:32

Hi, I've created a basic Array from 1 to 20, & I'm trying to move the entire Array to Array 2 to 20, Array 3 to 20 etc.,

I'm filling in the gaps from the initial basic array, so if the entire Array is moved to Array 5 to 20, i use the values from the basic array 1 to 5 & copy them to the now empty Arrays 1 to 5, as the entire array has been moved to Array 5 to 20.

The script works great.

But it moves step by step, instead of the entire table updating at once, ie The entire basic array 1 to 20 moves from array5 to array6, it moves the entire basic to the new position step by step, ie the figures in array 1 to array 2, figures in array 2 to array 3 etc.,

Is it possible to move the entire array & fill in the missing arrays, as the basic array cascades down the table simultaneously? I've tried, but its too complex ...

Thanks!

Code: Select all

#SingleInstance, Force

SetFormat,Float,3.2





;Create Initial Array

Data := Object()
i:=109

NumberOfUnits:=40

Loop %NumberOfUnits%
{
	i++
	
	data[A_Index]:=i
}
Value := data[5]
x:=0
number:=0
YAxisInc:=24
StatusInc:=1
NumStatusInc:=1
NotShown := True ;gui has not yet been shown
loop
{
	;Creates Initial Array In Gui As Guide Left Row
	Loop, %NumberOfUnits%
	{
		x++			;Increments by - to create 40 to 60
		y1:=data[x]
		YAxis:=number += YAxisInc ;Increments by 12 to create a gap of 12 between numbers
		Gui,Add,Text,x160  y%YAxis%, %x% %y1%
	}

	;Create Variables To Show In Gui

	;Outerloop Using OuterInc   Cascades The Entire Initial Array From Array 1 To Array 20, Array 2 to Array 20 etc.,
	;InnerLoopFill Creates An InnerLoop Using OuterInc To Fill In Gaps Created By Cascading The Initial Array
	;If the Entire Initial Array gets displaced From Array 1 to Array 5 The InnerLoopLoop Fills Empty Values In Array 1 to 5 Using Values 1 to 5 From Initial Array
	;Outerloop
	;Outerloop Using OuterInc   Cascades The Entire Initial Array From Array 1 To Array 20, Array 2 to Array 20 etc.,
	OuterInc:=2
	FillPreviousInc:=1

	Loop %NumberOfUnits%
	{
		StartPointFill:=OuterInc-OuterInc +1
		;InnerLoop
		Datax := Object()
		IncIncrease:=OuterInc

		Loop %NumberOfUnits%

		{

			;Copies Values From Array data[1] to Datax[2],  data[2] to Datax[3] etc.
			
			

			Datax[IncIncrease] := data[A_Index]
			IncIncrease++



			;InnerLoopFill Creates An InnerLoop Using OuterInc To Fill In Gaps Created By Cascading The Initial Array
			;If the Entire Initial Array gets displaced From Array 1 to Array 5 The InnerLoop Fills Empty Values In Array 1 to 5 Using Values 1 to 5 From Initial Array
			
			InnerLoopFill:=0
			Loop %OuterInc%
			{
				InnerLoopFill++
				Datax[InnerLoopFill] := data[InnerLoopFill]
			}

		}


		;Displays Created Cascade In Gui
		x:=0
		number:=0
		YAxisInc:=YAxisInc
		StatusInc:=1
		NumStatusInc:=1
		First:=!First++
		Loop, %NumberOfUnits%
		{
			x++			;Increments by + to create 40 to 60
			y1:=Datax[x]
			YAxis:=number += YAxisInc ;Increments by 12 to create a gap of 12 between numbers
			IF NotShown
			{
			Gui, Font, s8

				Gui, Add, Edit, w100  vPriceBought, %CurrentPrice%
				
				Gui, Add, Edit, w100  vAmount, %Amount%				
				Gui,Add,Text,x360 w500  y%YAxis% vY%YAxis%,    %y1%     
				}
			Else
{

			
		

				GuiControl,,   Y%YAxis%,     %y1%   
			Sleep, 500
			}
		}
		If NotShown
			Gui, Show,x1609 y186 w900 h1200, XGraph,% NotShown := False
		OuterInc++
	}
}


esc::
{

sleep 100
Send {LControl down}
sleep 100
Send {s}
sleep 100
Send {LControl up}

Reload
}
Return
User avatar
boiler
Posts: 16957
Joined: 21 Dec 2014, 02:44

Re: Cascade An Array All At Once, Instead Of Step By Step

06 May 2021, 20:39

I'm not sure of exactly what you're trying to do, but to insert 5 new elements at the beginning of an array and shift the current elements to index 6 and up, just do this:

Code: Select all

MyArray.InsertAt(1, 0, 0, 0, 0, 0)
Demo:

Code: Select all

; initialize array with 20 letters, a through t:
MyArray := []
loop, 20
	MyArray.Push(Chr(96 + A_Index))
DisplayArray(MyArray)

; insert 5 elements starting at element 1:
MyArray.InsertAt(1, 0, 0, 0, 0, 0)
DisplayArray(MyArray)
return

DisplayArray(a) {
	for k, v in a
		out .= k "`t" v "`n"
	MsgBox, % out
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: sachinme and 342 guests