# 2 ubound arrays wont work together

## 14 posts in this topic

#1 ·  Posted (edited)

#include <array.au3>
#include <file.au3>

Local $text _FileReadToArray("text.txt",$text) ; read the list of names to array
Local $test _FileReadToArray("test.txt",$test) ; read the list of names to array

For $u = 1 To UBound($test) - 1
For $i = 1 To UBound($text) - 1

MsgBox(4096, "Test", $text[$i] & " - " & $test[$u])
Next
Next

When I run this only the first ubound array works, the second does not change value?
Do you have a suggestion for me.

Edited by RyukShini

##### Share on other sites

#include <array.au3>
#include <file.au3>

Local $text Local$test
_FileReadToArray(@ScriptDir & "\text.txt", $text) ; read the list of names to array _FileReadToArray(@ScriptDir & "\test.txt",$test) ; read the list of names to array

For $u = 1 To UBound($test) - 1
For $i = 1 To UBound($text) - 1

MsgBox(4096, "Test", $text[$i] & " - " & $test[$u])
Next
Next

My Contributions...

# FTP Connection Tester / INI File - Read, Write, Save & Load Example

##### Share on other sites

your script works fine just need to declare $text and$test

#include <array.au3>
#include <file.au3>

Local $text _FileReadToArray("text.txt",$text) ; read the list of names to array
Local $test _FileReadToArray("test.txt",$test) ; read the list of names to array

For $u = 1 To UBound($test) - 1
For $i = 1 To UBound($text) - 1

MsgBox(4096, "Test", $text[$i] & " - " & $test[$u])
Next
Next

ill get to that... i still need to learn and understand a lot of codes

Correct answer, learn to walk before you take on that marathon.

##### Share on other sites

...echo ...echo...echo...

1 person likes this

My Contributions...

# FTP Connection Tester / INI File - Read, Write, Save & Load Example

##### Share on other sites

1 person likes this

ill get to that... i still need to learn and understand a lot of codes

Correct answer, learn to walk before you take on that marathon.

##### Share on other sites
1 hour ago, 232showtime said:

your script works fine just need to declare $text and$test

#include <array.au3>
#include <file.au3>

Local $text _FileReadToArray("text.txt",$text) ; read the list of names to array
Local $test _FileReadToArray("test.txt",$test) ; read the list of names to array

For $u = 1 To UBound($test) - 1
For $i = 1 To UBound($text) - 1

MsgBox(4096, "Test", $text[$i] & " - " & $test[$u])
Next
Next

1 hour ago, l3ill said:
#include <array.au3>
#include <file.au3>

Local $text Local$test
_FileReadToArray(@ScriptDir & "\text.txt", $text) ; read the list of names to array _FileReadToArray(@ScriptDir & "\test.txt",$test) ; read the list of names to array

For $u = 1 To UBound($test) - 1
For $i = 1 To UBound($text) - 1

MsgBox(4096, "Test", $text[$i] & " - " & $test[$u])
Next
Next

Sorry That was a mistake not to declare.
After declaring the variables it still doesn't work.
$test[$u] does not change its value, it remains the same however $text[$i] changes.

##### Share on other sites

What's in the test.txt file?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

##### Share on other sites

show your full script and content of the txt file, its working fine with me.

ill get to that... i still need to learn and understand a lot of codes

Correct answer, learn to walk before you take on that marathon.

##### Share on other sites

#9 ·  Posted (edited)

Look at my next Reply...

Edited by abdulrahmanok

##### Share on other sites

RyukShini,

You have 2 embedded loops - as a result you will get the following returns:

Line 1 of test - Line 1 of text
Line 2 of test - Line 1 of text
...                               ; And this continues until the last line of the file
Line n of test - Line 1 of text
Line 1 of test - Line 2 of text   ; Only then will the line of the outer loop change and the process repeat
Line 2 of test - Line 2 of text
...
Line n of test - Line 2 of text
Line 1 of test - Line 3 of text
Line 2 of test - Line 3 of text
...
Line n of test - Line 3 of text
...
...
Line n of test - Line n of text  ; Until we end up here at the last line of both files

So the second value will eventually change, but only every time the first one resets to the first line.

M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

##### Share on other sites

Hope this what you want :

#include <array.au3>
#include <file.au3>
$First = FileReadToArray(@ScriptDir & "\FirstValu.txt") If @error Then Else For$i = 0 To UBound($First,2) - 1 ; Loop through the array. Next EndIf$Second = FileReadToArray(@ScriptDir & "\SecondValu.txt")
If @error Then
Else
For $y = 0 To UBound($Second) - 1 ; Loop through the array.

FileWrite(@ScriptDir & "\All.txt",$First[$i]&@CRLF)
FileWrite(@ScriptDir & "\All.txt",$Second[$y])
ExitLoop
; Read File To Array is Done
;~         ExitLoop  Dont exit loop unless there is an error handler
Next
EndIf

Tested .

##### Share on other sites
16 hours ago, RyukShini said:

Sorry That was a mistake not to declare.
After declaring the variables it still doesn't work.
$test[$u] does not change its value, it remains the same however $text[$i] changes.

well if you want $text and$test changed their values at the same time you can do like this:

#include <array.au3>
#include <file.au3>

Local $text Local$test
_FileReadToArray(@ScriptDir & "\text.txt", $text) ; read the list of names to array _FileReadToArray(@ScriptDir & "\test.txt",$test) ; read the list of names to array

For $u = 1 To UBound($test) - 1
MsgBox(4096, "Test", $text[$u] & " - " & $test[$u])
Next

ill get to that... i still need to learn and understand a lot of codes

Correct answer, learn to walk before you take on that marathon.

##### Share on other sites
16 hours ago, RyukShini said:

Sorry That was a mistake not to declare.
After declaring the variables it still doesn't work.
$test[$u] does not change its value, it remains the same however $text[$i] changes.

As Melba mentioned (depending on how many strings are in text.txt)

You wont see any change in $test[$u] until the loop has gone through all of text.txt stings. So if its a bumch it may take a while.

Make sense?

I prefer testing stuff like this with Consolewrite so the script doesn't have to stop:

#include <array.au3>
#include <file.au3>

Local $text Local$test
_FileReadToArray(@ScriptDir & "\text.txt", $text) ; read the list of names to array _FileReadToArray(@ScriptDir & "\test.txt",$test) ; read the list of names to array

For $u = 1 To UBound($test) - 1
For $i = 1 To UBound($text) - 1

ConsoleWrite("$text[$i] = " & $text[$i] & "$test[$u] = " & $test[$u])
Next
Next

My Contributions...

# FTP Connection Tester / INI File - Read, Write, Save & Load Example

##### Share on other sites

Thanks a lot !
I got it to work.

## 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

• ### Similar Content

• By hcI
Hello everyone !
I have a little problem
I would like to do a little program who analyse an array and return the 1st line of the array who is empty
For example :
Global aArray[5] = "abc","def","ghi","","mno" ; And Then, (maybe a For loop who) return in a variable "4" ; because the 4th case of the array is empty I've took a look in helpfile but found nothing intrusting.. If someone have already done this or have idea how to proceed.. Hci • By StillLearningThisStuff Hello all, Summary: I have a basic piece of code that is to be a part of a much larger project; I just can't seem to get the right output. I'm retrieving two lots of powershell data into 2 x 1d arrays and trying to add them into a single 2d array. Retrieving the data together into the 2d array seemed harder, due to the application names varying too much to string split. Data being pulled is application name and GUID. From here I will use this info in a drop down box and an uninstall button to run the required command to remove the selected software (have this sorted already). Problem: When I merge the data it doesn't put the application name and GUID on the same row in differing columns eg. my test box has 24 applications plus some superfluous data from Powershell to be cleaned up by the _arraydeletes. Instead I end up with an array with 58 rows and 2 columns; whereas my temp 1d arrays have 28 rows. As you can see I've tried both _ArrayInsert and _ArrayAdd but I still get the same result. Question: Is there something that I'm doing wrong in putting the data into the 2d array or do I just need to do some more post processing to tidy it up and align the names and GUIDs? Code: #include <Array.au3>Cmd1 = (" /c Powershell.exe " & Chr(34) & "Get-WmiObject -Class win32reg_addremoveprograms | where {$_.ProdID -like " & Chr(34) & Chr(123) & Chr(42) & Chr(125) & Chr(34) & "} | select DisplayName" & Chr(34))$Cmd2 = (" /c Powershell.exe " & Chr(34) & "Get-WmiObject -Class win32reg_addremoveprograms | where {$_.ProdID -like " & Chr(34) & Chr(123) & Chr(42) & Chr(125) & Chr(34) & "} | select ProdID" & Chr(34)) Global$aNameGUID[1][2] ;_ArrayDisplay($aNameGUID) ReadApps($Cmd1,0) ;_ArrayDisplay($aNameGUID) ReadApps($Cmd2,1) _ArrayDisplay($aNameGUID) Terminate() Func ReadApps($Command,$col)$DOS = Run(@ComSpec & $Command, "", @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($DOS) $DOSOut = StdoutRead($DOS) ;MsgBox(0,"Data",$DOSOut) ;Show the line items that we want in the array Local$tmpArray = StringSplit(StringTrimRight(StringStripCR($DOSOut), StringLen(@CRLF)), @CRLF) If @error Then MsgBox(0,"FAIL","I failed to find objects") Exit Else _ArrayDisplay($tmpArray) EndIf ;_ArrayDelete($tmpArray, 3) ;_ArrayDelete($tmpArray, 2) ;_ArrayDelete($tmpArray, 1) ;$tmpArray[0] = $tmpArray[0] - 3 For$i = 0 To UBound($tmpArray) - 1 ;_ArrayAdd($aNameGUID, $tmpArray[$i], $col) _ArrayInsert($aNameGUID, 0, $tmpArray[$i], $col) Next$tmpArray = 0 EndFunc ;==>ReadApps While 1 Sleep(1500) WEnd Func Terminate() Exit 0 EndFunc ;==>Terminate Thanks in advance,
Luxyboy
• By harvester2001
Hi
I need some help.
I try ping computers from targets.txt (I have computer name in lines) if they ping I want do something and after that remove pc name from targets.txt. Its working but problem is when I put this inside loop, because I need run script until all computers will not be removed from the list (targets.txt). I dont know how to "refresh" array
#include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Local $PC_list = "\targets.txt" Local$bTargets = FileReadToArray(@ScriptDir& $PC_list) Do _check_ping() ;count_lines Local$file_count_lines = _FileCountLines(@ScriptDir& $PC_list)$i = $file_count_lines ConsoleWrite("na liście "&$i & @CRLF) Until $i = 0 ; IF &i = 0 then show MsgBox MsgBox(1, "xXx", "Finish") ;PING Func _check_ping() For$sPC In $bTargets$var = Ping($sPC, 250) If$var Then ConsoleWrite($sPC &"online"& @CRLF) ;Do something ;Delete$sPC from targets.txt Local $_Array _FileReadToArray ( @ScriptDir& "\targets.txt",$_Array ) $_Array = _DeleteArrayElementWithStringInstr ($_Array, $sPC ) _FileWriteFromArray ( @ScriptDir& "\targets.txt",$_Array, 1 ) Sleep(200) Else ConsoleWrite($sPC &"offline"& @CRLF) EndIf Next EndFunc ;DELETE LINE FROM TXT Func _DeleteArrayElementWithStringInstr ($_Array, $_String ) Local$_Item For $_Element In$_Array If StringInStr ( $_Element,$_String ) <> 0 Then _ArrayDelete ( $_Array,$_Item ) Else $_Item+=1 EndIf Next Return ($_Array ) EndFunc ;==> _DeleteArrayElementWithStringInstr ( )
Local $a[3] = [1, 2],$b[2] = [3, 4] $a[2] =$b ConsoleWrite(($a[2])[0] & " " & ($a[2])[1] & @CRLF) If I try to write directly to the element, I get an error:
Local $a[3] = [1, 2] Local$b[2] $a[2] =$b ($a[2])[0] = 1 Is assigning first every value of the contained array and then including it in the container the only way? • By SorryButImaNewbie Hello all! I wrote a little script to automate some of my work (for which I'm greatfull). I have little problem now. My script get data of currency values from specified time period. The problem, if XY day is a holiday or something, then the bank doesn't have new values for that day, thus my script can ask for "till that date" if there is only data for "till that date-1". I should be done with this for tomorrow and I should learn for my test paper tomorrow, make a genetic algorhytm homework, and at least look at a ppt... So here is my code, pleas ask if you need more information! InternetRead2() ;Creating Date and Arfolyam arrays, using DateInterval read from above (_ArraysDisplayed and function is "tested") ;Calculate and write HUF*OSSZEG Do Local$SZAMLATELJOlvaso = _Excel_RangeRead($ExcelObject, Default,$SZAMLATELJoszlop & $CellaOlvasoSzamlalo) Local$Time = StringTrimRight($SZAMLATELJOlvaso, 6)$DateArrayTimeIndex = _ArraySearch($DateArray,$Time, 0, 0, 0, 0, 1) ;MsgBox(64, "Értesítés", $DateArrayTimeIndex) If @error = 6 Then$DateArrayTimeIndex = _ArraySearch($DateArray,$Time-1, 0, 0, 0, 0, 1) ;MsgBox(64, "Értesítés", $DateArrayTimeIndex) EndIf If @error = 6 Then$DateArrayTimeIndex = _ArraySearch($DateArray,$Time-2, 0, 0, 0, 0, 1) ;MsgBox(64, "Értesítés", $DateArrayTimeIndex) EndIf If @error = 6 Then$DateArrayTimeIndex = _ArraySearch($DateArray,$Time-3, 0, 0, 0, 0, 1) ;MsgBox(64, "Értesítés", $DateArrayTimeIndex) EndIf If @error = 6 Then$DateArrayTimeIndex = _ArraySearch($DateArray,$Time-4, 0, 0, 0, 0, 1) ;MsgBox(64, "Értesítés", $DateArrayTimeIndex) EndIf$DateArrayTimeIndex = $DateArrayTimeIndex+1 ;Egyébként arraysearch -1et ad vissza, 0nál. Passz Sleep(200) If Not$SZAMLATELJOlvaso = "" Then _Excel_RangeWrite($ExcelObject,$ExcelObject.Activesheet, "=" & $OSSZEGoszlop &$CellaOlvasoSzamlalo & "*" & String($ArfolyamArray[$DateArrayTimeIndex]) & "", String($sHUFBeszurOszlop) &$CellaOlvasoSzamlalo) If @error Then _Excel_RangeWrite($ExcelObject,$ExcelObject.Activesheet, "=" & $OSSZEGoszlop &$CellaOlvasoSzamlalo & "*" & String($ArfolyamArray[$oXML_Node.Length]) & "", String($sHUFBeszurOszlop) &$CellaOlvasoSzamlalo) MsgBox(64, "Értesítés", "Valamilyen okból, nem találok az adott dátumhoz árfolyamot, a keresési idők közül a legutolsó árfolyammal töltöttem ki!" & @CRLF & Number($oXML_Node_Datum)) EndIf EndIf$CellaOlvasoSzamlalo = $CellaOlvasoSzamlalo + 1 Until$SZAMLATELJOlvaso = "" also my internetread2 function :
Func InternetRead2() ;ezt használja az excelmove ;----------------------------------- ;Original Source: https://www.autoitscript.com/forum/topic/184884-solved-basic-com-help-working-on-string-returned-from-api-mi-doing-this-okey/ ;by Genius257 ;TO DO: Some error handling maybe: what if there is no $MinTime/$MaxTime? ;Read the returns in to array for future use --> Right now, 2 arrays one with the dates and one with the exchangerates ;----------------------------------- ;Globals decleared to avoid warnings Global $MinTime ;20160601000000 Global$MaxTime ;20160610000000 Global $MinTimeFormated = StringTrimRight($MinTime, 6) Global $MaxTimeFormated = StringTrimRight($MaxTime, 6) $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") If$MaxTimeFormated = "" and $MinTimeFormated = "" Then MsgBox(64, "Értesítés", "Nincsenek beolvasott dátumok a memóriában, dummy dátumokat adok meg!" & @CRLF & "20160901, 20160910")$MinTimeFormated = "20160901" $MaxTimeFormated = "20160905" EndIf$oHTTP.Open("GET", "http://api.napiarfolyam.hu/?bank=mnb&valuta=eur&datum="&$MinTimeFormated&"&datumend="&$MaxTimeFormated&"", False) $oHTTP.Send()$sXML = $oHTTP.responseText Global$oXML = ObjCreate("Microsoft.XMLDOM") $oXML.loadXML($sXML ) $oXML_Nodes =$oXML.SelectNodes("./arfolyamok/deviza/item") Global $ArfolyamArray[$oXML_Nodes.Length] ;MsgBox(64, "Title", "" & $oXML_Nodes.Length & "") ;_ArrayDisplay($ArfolyamArray) Global $DateArray[$oXML_Nodes.Length] For $i=0 To$oXML_Nodes.Length-1 Global $oXML_Node =$oXML_Nodes.Item($i)$oXML_Node_Bank = $oXML_Node.SelectNodes("./bank")$oXML_Node_Bank = $oXML_Node_Bank.Length>0?$oXML_Node_Bank.Item(0).text:"" Global $oXML_Node_Datum =$oXML_Node.SelectNodes("./datum") $oXML_Node_Datum =$oXML_Node_Datum.Length>0?$oXML_Node_Datum.Item(0).text:""$oXML_Node_Penznem = $oXML_Node.SelectNodes("./penznem")$oXML_Node_Penznem = $oXML_Node_Penznem.Length>0?$oXML_Node_Penznem.Item(0).text:"" $oXML_Node_Kozeps =$oXML_Node.SelectNodes("./kozep") $oXML_Node_Kozep01 =$oXML_Node_Kozeps.Length>0?$oXML_Node_Kozeps.Item(0).text:""$oXML_Node_Kozep02 = $oXML_Node_Kozeps.Length>1?$oXML_Node_Kozeps.Item(1).text:"" $ArfolyamArray[$i] = $oXML_Node_Kozep01$DateArray[$i] = StringTrimRight(StringReplace($oXML_Node_Datum, "-", ""), 8) ConsoleWrite( "Match [" & StringFormat("%02i", $i+1) & "]:"&@CRLF& _ @TAB&"Bank: "&@TAB&$oXML_Node_Bank&@CRLF& _ @TAB&"Datum: "&@TAB&$oXML_Node_Datum&@CRLF& _ @TAB&"Penznem: "&@TAB&$oXML_Node_Penznem&@CRLF& _ @TAB&"Kozep01: "&@TAB&$oXML_Node_Kozep01&@CRLF& _ @TAB&"Kozep02: "&@TAB&$oXML_Node_Kozep02&@CRLF _ ) Next ;_ArrayDisplay($ArfolyamArray) ;_ArrayDisplay($DateArray) EndFunc My problem is that I have dates in my excel till 2016.10.30, but I only have dates till 28.