<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Копирование строк в двумерном массиве]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=15553</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=15553&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Копирование строк в двумерном массиве».]]></description>
		<lastBuildDate>Wed, 29 Jul 2020 22:31:03 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Копирование строк в двумерном массиве]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=141269#p141269</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (Phoenixxx_Czar)]]></author>
			<pubDate>Wed, 29 Jul 2020 22:31:03 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=141269#p141269</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Копирование строк в двумерном массиве]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=141171#p141171</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (KepocuH)]]></author>
			<pubDate>Tue, 28 Jul 2020 10:47:10 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=141171#p141171</guid>
		</item>
	</channel>
</rss>
