<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Копирование строк в двумерном массиве]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=15553&amp;type=atom" />
	<updated>2020-07-29T22:31:03Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=15553</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Копирование строк в двумерном массиве]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=141269#p141269" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>arr1 := [[0, 2, 3, 4, 5], [1, 5, 4, 3, 2], [0, 6, 7, 8, 9], [1, 9, 8, 7, 6]]
arr2 := []

for k, v in arr1
{
	if (v[1] == 1)
	{
		arr2.Push(v)
	}
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2020-07-29T22:31:03Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=141269#p141269</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Копирование строк в двумерном массиве]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=141171#p141171" />
			<content type="html"><![CDATA[<p>Добрый день!<br />Имеется двумерный массив table1[x, y]<br />Нужно скопировать их него в массив table2 некоторые строки по определенному условию.<br />Допустим, если table1[x, 1] = 1, то строка table1[x] вставляется в конец массива table2.<br />Таблица1:<br />1 а б в г д<br />0 е ж з и к<br />0 л м н о п<br />1 р с т у ф<br />0 х ц ч ш щ<br />1 ъ ь э ю я<br />Должна получиться таблица2:<br />1 а б в г д<br />1 р с т у ф<br />1 ъ ь э ю я<br />Делаю так:<br /></p><div class="codebox"><pre><code>
i := 1
loop %x% {
	if (table1[A_Index, 1] = 1) {
		a := A_Index
		loop %y% {
			table2[i, A_Index] := table1[a, A_Index]
		}
		i += 1
	}
}
</code></pre></div><p>Есть ли способ попроще?<br />Что-то вроде такого:<br /></p><div class="codebox"><pre><code>
loop %x% {
	if (table1[A_Index, 1] = 1) 
		table2.Push(table1[A_Index])
}
</code></pre></div><p>UPD:<br />Пока ковырялся, столкнулся еще с парой проблем.<br />Создал табличку в excel (см. приложенный файл).<br />Считываю Range из экселя в массив arr1.</p><div class="codebox"><pre><code>
OnExit(&quot;ExitFunc&quot;)

ExitFunc(ExitReason, ExitCode) {
	global Xl
	Xl.quit
}

FileSelectFile, inputFile
if Errorlevel
	return

Xl := ComObjCreate(&quot;Excel.Application&quot;)
Xl.Visible := True
ot := Xl.Workbooks.Open(inputFile)

; Определяем длину таблицы
Loop {
	a := ot.Worksheets(1).Cells(A_Index, 1).value
	if (a = &quot;&quot;)
		break
	x := a_index
}
MsgBox % x ; показывает количество строк в экселевском файле (4)
; Создаем массив из таблицы
dataArea := ot.Worksheets(1).Range(&quot;A1:E&quot; x)
arr1 := dataArea.value

; создаем массив вручную
;arr1 := [[0, 2, 3, 4, 5], [1, 5, 4, 3, 2], [0, 6, 7, 8, 9], [1, 9, 8, 7, 6]]

arr2[1] := arr1[1] ; присваиваем первой строке массива arr2 первую строку массива arr1
if (arr2[1] = arr1[1]) ; сравниваем строки
	MsgBox Строки идентичны ; msgbox отображается, если arr1 создан из экселя, и НЕ отображается, если создан вручную (О_о)
MsgBox % &quot;&quot;&quot;&quot; arr1[1,1] &quot;&quot;&quot; = &quot;&quot;&quot; arr2[1,1] &quot;&quot;&quot;&quot; ; показывает &quot;0&quot; = &quot;&quot; в обоих случаях
MsgBox % &quot;&quot;&quot;&quot; arr1.MaxIndex() &quot;&quot;&quot; = &quot;&quot;&quot; arr2.MaxIndex() &quot;&quot;&quot;&quot; ; показывает &quot;4&quot; = &quot;&quot; в обоих случаях
ExitApp

</code></pre></div><p>Почему arr1[1,1] отображается, а arr2[1,1] нет?<br />Чем отличаются друг от друга&nbsp; массивы arr1 в случае создания из excel и вручную?</p><p>Что ж все так сложно-то, а?</p>]]></content>
			<author>
				<name><![CDATA[KepocuH]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=28557</uri>
			</author>
			<updated>2020-07-28T10:47:10Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=141171#p141171</id>
		</entry>
</feed>
