<?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=11819&amp;type=atom" />
	<updated>2016-07-19T00:24:02Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=11819</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определение границ массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106169#p106169" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>
fileSize := 0
position := 0
file := FileOpen(&quot;Test.txt&quot;, &quot;r&quot;, &quot;UTF-8&quot;)
strArray := []
arrCount := 0
while (true) {
	if (file.Length &gt; fileSize) {
		fileSize := file.Length
		file.Seek(position)
		line := file.ReadLine()
		while (line != &quot;&quot;) {
			strArray.Push(line)
			line := file.ReadLine()
		}
		position := file.Tell()
		arrCount := strArray.Length()
	}
	sleep 100
}
</code></pre></div><p>Такая конструкция прочитает &quot;Test.txt&quot;, положит прочитанные строки в массив &quot;strArray&quot;, сообщит переменной &quot;arrCount&quot; верхнее значение массива и раз в 100 миллисекунд будет проверять размер &quot;Test.txt&quot;. Если размер увеличится, новые строки будут добавлены в массив &quot;strArray&quot;, а переменная &quot;arrCount&quot; получит новое предельное значение.</p>]]></content>
			<author>
				<name><![CDATA[KusochekDobra]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33846</uri>
			</author>
			<updated>2016-07-19T00:24:02Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106169#p106169</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определение границ массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106155#p106155" />
			<content type="html"><![CDATA[<p>Ещё такой вариант.<br /></p><div class="codebox"><pre><code>Loop, Read, Test.txt
{
line%A_Index% := A_LoopReadLine
last_line := A_Index
}
Random, varrandom, 1, last_line
MsgBox,  % line%varrandom%</code></pre></div>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2016-07-18T20:00:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106155#p106155</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определение границ массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106154#p106154" />
			<content type="html"><![CDATA[<p><strong>ypppu</strong><br />В файле неизвестное кол-во строк, необходимо рандомно вывести одну из строк.</p>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2016-07-18T16:37:43Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106154#p106154</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определение границ массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106153#p106153" />
			<content type="html"><![CDATA[<p>Кто-нибудь переведите, в чём задача вообще заключалась?</p>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2016-07-18T16:16:15Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106153#p106153</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определение границ массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106151#p106151" />
			<content type="html"><![CDATA[<p>Благодарю за помощь! Все варианты поробовал, но остановился на решении от <strong>Malcev</strong> из предыдущего сообщения.</p>]]></content>
			<author>
				<name><![CDATA[Veranda]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33724</uri>
			</author>
			<updated>2016-07-18T15:23:30Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106151#p106151</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определение границ массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106150#p106150" />
			<content type="html"><![CDATA[<p>Можно так ещё:<br /></p><div class="codebox"><pre><code>FileRead, All, test.txt
Sort, All, Random
msgbox % RegExReplace(All, &quot;\R.*&quot;)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2016-07-18T15:11:56Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106150#p106150</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определение границ массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106149#p106149" />
			<content type="html"><![CDATA[<p>А зачем два раза файл читать?<br /></p><div class="quotebox"><blockquote><p>random, varrandom, 1, % (objList := <a href="https://autohotkey.com/docs/commands/StringSplit.htm">StrSplit(</a><a href="https://autohotkey.com/docs/commands/FileOpen.htm">FileOpen(</a>&quot;Test.txt&quot;,&quot;r&quot;).<a href="https://autohotkey.com/docs/objects/File.htm">Read()</a>,&quot;`r`n&quot;)).<a href="https://autohotkey.com/docs/objects/Object.htm#Length">Length()</a><br />MsgBox % objList[varrandom]</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[yalanne]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32850</uri>
			</author>
			<updated>2016-07-18T15:07:13Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106149#p106149</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определение границ массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106148#p106148" />
			<content type="html"><![CDATA[<p>Первую строку заменить на:<br /></p><div class="codebox"><pre><code>FileRead, All, Test.txt
random, varrandom, 1, StrLen(RegExReplace(All, &quot;[^\r\n]&quot;))/2 + 1</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Flasher]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27593</uri>
			</author>
			<updated>2016-07-18T14:33:50Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106148#p106148</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определение границ массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106146#p106146" />
			<content type="html"><![CDATA[<p>Можно посчитать количество строк в файле до вызова random.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2016-07-18T14:07:16Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106146#p106146</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определение границ массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106145#p106145" />
			<content type="html"><![CDATA[<p>Файл Test прилагаю. Представляет из себя 14 строк с разными значениями для вывода в MsgBox.</p>]]></content>
			<author>
				<name><![CDATA[Veranda]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33724</uri>
			</author>
			<updated>2016-07-18T13:59:23Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106145#p106145</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определение границ массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106144#p106144" />
			<content type="html"><![CDATA[<p>Нужно конкретный пример файла Test.txt в начальный момент, а потом после добавления.</p>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2016-07-18T13:36:11Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106144#p106144</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Определение границ массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106143#p106143" />
			<content type="html"><![CDATA[<p>Доброго дня, уважаемые форумчане!<br />Столкнулся с проблемой: для работы скрипта подключаю внешний файл, в котором есть 16 строк. Строки вызываю через random, с ограничением диапазона чтения строк с 1 по 14<br />Каким образом можно отказаться от необходимости указывать в параметрах переменно varrandom количество строк, из списка которых необходимо вывести строку со значением? Т.е чтобы пр добавлении новых строк в файл - они наравне с уже имеющимися участвовали в поиске и ненужно было изменять значение верхней границы массива строк в файле? <img src="//forum.script-coding.com/img/smilies/roll.png" width="15" height="15" /></p><p>Была мысль сверять количество символов в строке при генерации varrandom и если их количество=0 - то происходит повторная генерация, пока в переменной не окажется строка с количеством символов &gt;0. Однако данное решение мне кажется не очень удачным.</p><div class="codebox"><pre><code>
random, varrandom, 1, 14
FileReadLine, OutputVar, Test.txt, %varrandom% ;путь к файлу
MsgBox, Текущее значение:`n%OutputVar%
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Veranda]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33724</uri>
			</author>
			<updated>2016-07-18T13:27:34Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106143#p106143</id>
		</entry>
</feed>
