david1337

First find text, Then do this

14 posts in this topic

#1 ·  Posted (edited)

Hi guys

I have 3 txt files, and the script searches them, to find the txt file containing my username.
If found in one of the txt files, an msgbox will tell which txtfile my username was found in. Works fine.

;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Global $Text[3] ;If changed, remember to change multiple places in the script.

$Text[0] = ("01_TextFile")
$Text[1] = ("02_TextFile")
$Text[2] = ("03_TextFile")

Global $DirforTxtFiles = "C:\Temp\"

$username = @UserName    ;pulls username that is logged in
;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/




; SCRIPT START

 For $i = 0 to 3 - 1

$TextFile = FileOpen($DirforTxtFiles & $Text[$i] & ".txt", 0)
$ReadText = FileRead($TextFile)
FileClose($TextFile)


If StringRegExp($ReadText, $username) Then


Call("MainScript")



EndIf


Next




Func MainScript()

MsgBox(0,"USER FOUND", "In following textfile: " & $Text[$i])

EndFunc

 

 

But now I want the script to do something else, if my username is NOT found in any of the txtfiles
The following example below here doesn't work, since the Else statement is placed inside the For loop, So it will run the Else statement, every time the StringRegExp doesn't find my username in a txtfile.

;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Global $Text[3] ;If changed, remember to change multiple places in the script.

$Text[0] = ("01_TextFile")
$Text[1] = ("02_TextFile")
$Text[2] = ("03_TextFile")

Global $DirforTxtFiles = "C:\Temp\"

$username = @UserName    ;pulls username that is logged in
;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/




; SCRIPT START

 For $i = 0 to 3 - 1

$TextFile = FileOpen($DirforTxtFiles & $Text[$i] & ".txt", 0)
$ReadText = FileRead($TextFile)
FileClose($TextFile)


If StringRegExp($ReadText, $username) Then


Call("MainScript")


Else
Call("NotInTextFile")


EndIf


Next






Func MainScript()

MsgBox(0,"USER FOUND", "In following textfile: " & $Text[$i])

EndFunc





;\/___________________________________________________________________________\/
Func NotInTextFile()

MsgBox(0,"", "USER NOT IN ANY TEXTFILE")

EndFunc

 

What it SHOULD do, is search the txtfiles for my username, and then when all the searching is done, it should react based on the search result.

The answer might be quite obvious, but I'm stuck at this point.

 

Any ideas would be much appreciated :)

Edited by david1337

Share this post


Link to post
Share on other sites



I would try something like this:

;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Global $aText[] = ["01_TextFile", "02_TextFile", "03_TextFile"]
Global $sDirforTxtFiles = "C:\Temp\"
$sUsername = @UserName ; Pulls username that is logged in
;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

; SCRIPT START
For $i = 0 To UBound($aText) - 1
    $hTextFile = FileOpen($sDirforTxtFiles & $aText[$i] & ".txt", 0)
    $sReadText = FileRead($hTextFile)
    FileClose($hTextFile)
    If StringRegExp($sReadText, $sUsername) Then
        MainScript()
    Else
        NotInTextFile()
    EndIf
Next

Func MainScript()
EndFunc   ;==>MainScript

Func NotInTextFile()
EndFunc   ;==>NotInTextFile

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi water

Thanks for your time!
I'm afraid that your example gives the same result.
Say my username is found in 03_Textfile.txt, the 2 first searches gives me the Else function, and then the if function
So in your example I get the MsgBox(0,"", "USER NOT IN ANY TEXTFILE") 2 times before the MsgBox(0,"USER FOUND"...

;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Global $aText[] = ["01_TextFile", "02_TextFile", "03_TextFile"]
Global $sDirforTxtFiles = "C:\Temp\"
$sUsername = @UserName ; Pulls username that is logged in
;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

; SCRIPT START
For $i = 0 To UBound($aText) - 1
    $hTextFile = FileOpen($sDirforTxtFiles & $aText[$i] & ".txt", 0)
    $sReadText = FileRead($hTextFile)
    FileClose($hTextFile)
    If StringRegExp($sReadText, $sUsername) Then
        MainScript()
    Else
        NotInTextFile()
    EndIf
Next

Func MainScript()
   MsgBox(0,"USER FOUND", "In following textfile: " & $aText[$i])
EndFunc   ;==>MainScript

Func NotInTextFile()
   MsgBox(0,"", "USER NOT IN ANY TEXTFILE")
EndFunc   ;==>NotInTextFile

 

Edited by david1337

Share this post


Link to post
Share on other sites

Then I would set a flag and call the Not-Found-Function after all files have been checked:

;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Global $aText[] = ["01_TextFile", "02_TextFile", "03_TextFile"]
Global $sDirforTxtFiles = "C:\Temp\"
Global $bFound = False
$sUsername = @UserName ; Pulls username that is logged in
;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

; SCRIPT START
For $i = 0 To UBound($aText) - 1
    $hTextFile = FileOpen($sDirforTxtFiles & $aText[$i] & ".txt", 0)
    $sReadText = FileRead($hTextFile)
    FileClose($hTextFile)
    If StringRegExp($sReadText, $sUsername) Then
        $bFound = True
        MainScript()
    EndIf
Next
If $bFound = False Then NotInTextFile()

Func MainScript()
    MsgBox(0, "USER FOUND", "In following textfile: " & $aText[$i])
EndFunc   ;==>MainScript

Func NotInTextFile()
    MsgBox(0, "", "USER NOT IN ANY TEXTFILE")
EndFunc   ;==>NotInTextFile

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Another question: If the script finds the username in more than one file do you want to get the MsgBox multiple times?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Exactly what I was searching for. The flag did the trick.
Thanks water!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Another question: If the script finds the username in more than one file do you want to get the MsgBox multiple times?

Actually if that is the case, I should still get the MsgBox multiple times yes, but after that it should call a new function ONCE, based on how many times my username is found.
So the script itself must be aware that my username has been found more than once, and react from it. Is that possible also with flags?

Thanks! :)

;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Global $aText[] = ["01_TextFile", "02_TextFile", "03_TextFile"]
Global $sDirforTxtFiles = "C:\Temp\"
Global $bFound = False
$sUsername = @UserName ; Pulls username that is logged in
;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

; SCRIPT START
For $i = 0 To UBound($aText) - 1
    $hTextFile = FileOpen($sDirforTxtFiles & $aText[$i] & ".txt", 0)
    $sReadText = FileRead($hTextFile)
    FileClose($hTextFile)
    If StringRegExp($sReadText, $sUsername) Then
        $bFound = True
        MainScript()
    EndIf
Next
If $bFound = False Then NotInTextFile()

Func MainScript()
    MsgBox(0, "USER FOUND", "In following textfile: " & $aText[$i])
    ;If username only found once, do THIS <----------------------------------------------------
    ;If username found more than once, do THAT <-----------------------------------------------
EndFunc   ;==>MainScript

Func NotInTextFile()
    MsgBox(0, "", "USER NOT IN ANY TEXTFILE")
EndFunc   ;==>NotInTextFile

 

Edited by david1337

Share this post


Link to post
Share on other sites

In this case you need a counter:

;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Global $aText[] = ["01_TextFile", "02_TextFile", "03_TextFile"]
Global $sDirforTxtFiles = "C:\Temp\"
Global $iFound = 0
$sUsername = @UserName ; Pulls username that is logged in
;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

; SCRIPT START
For $i = 0 To UBound($aText) - 1
    $hTextFile = FileOpen($sDirforTxtFiles & $aText[$i] & ".txt", 0)
    $sReadText = FileRead($hTextFile)
    FileClose($hTextFile)
    If StringRegExp($sReadText, $sUsername) Then
        $iFound = $iFound + 1
        MainScript()
    EndIf
Next
If $iFound = 0 Then NotInTextFile()
If $iFound > 1 Then FoundMultipleTimes()

Func MainScript()
    MsgBox(0, "USER FOUND", "In following textfile: " & $aText[$i])
EndFunc   ;==>MainScript

Func NotInTextFile()
    MsgBox(0, "", "USER NOT IN ANY TEXTFILE")
EndFunc   ;==>NotInTextFile

Func FoundMultipleTimes()
    MsgBox(0, "", "USER FOUND MULTIPLE TIMES")
EndFunc   ;==>FoundMultipleTimes

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Of course! So $iFound = $iFound + 1 adds 1 to the counter every time there is a match, and If $iFound > 1 Then FoundMultipleTimes() determines if that counter is larger than 1, then we have multiple hits.

So logical, so nice :)

water you're the best, thanks!

Edited by david1337

Share this post


Link to post
Share on other sites

Another enhancement could be to do the processing in two steps.

  1. Determine how many files contain the username
  2. Process the files depending on how many files have been found.
    2.1 No files
    2.2. One file
    2.3 Multiple files

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Yeah you are correct. In the actual setup where there is up to 20 txt files, the current looping process is a bit heavy and clumsy :/

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I suggest something like this:

;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Global $aText[] = ["01_TextFile", "02_TextFile", "03_TextFile"]
Global $aFound[UBound($aText)] ; Table with a flag (True) for each found file
Global $iFound = 0 ; Counter for found files
Global $sDirforTxtFiles = "C:\Temp\"
$sUsername = @UserName ; Pulls username that is logged in
;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

; SCRIPT START
For $i = 0 To UBound($aText) - 1
    $hTextFile = FileOpen($sDirforTxtFiles & $aText[$i] & ".txt", 0)
    $sReadText = FileRead($hTextFile)
    FileClose($hTextFile)
    If StringRegExp($sReadText, $sUsername) Then
        $iFound = $iFound + 1 ; Update counter
        $aFound[$i] = True ; Set found flag for this file
    EndIf
Next
If $iFound = 0 Then FoundNone() ; No file found
If $iFound = 1 Then FoundOne()  ; One file found  
If $iFound > 1 Then FoundMany() ; More than one file foun

Func FoundNone()
    MsgBox(0, "", "USER NOT IN ANY TEXTFILE")
EndFunc   ;==>FoundNone

Func FoundOne()
    MsgBox(0, "USER FOUND", "In following textfile: " & $aText[$i])
EndFunc   ;==>FoundOne

Func FoundMany()
    Local $sFoundFiles
    For $i = 1 To UBound($aFound) - 1
        If $aFound[$i] = True Then $sFoundFiles = $sFoundFiles & $aText[$i] & @CRLF
    Next
    MsgBox(0, "", "USER FOUND IN " & $iFound & " FILES:" & @CRLF & @CRLF & $sFoundFiles)
EndFunc   ;==>FoundMany

 

Edited by water
1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Hi water

I just rewrote the entire script based on your example above. It's a lot more complicated in the actual script, but finally got it working.. phew!

Once again, thanks for all your guidance!

David

Edited by david1337

Share this post


Link to post
Share on other sites

Glad to be of service :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • StillLearningThisStuff
      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
    • harvester2001
      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. It`s 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 don`t know how to "refresh" array
      Please help
      #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 ( )  
    • j0kky
      By j0kky
      Hi guys,
      talking about array in array, I would like to directly assign a value to an element in an array contained in another array.
      While it is quite simple to access the value if it is already setted:
      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?
    • SorryButImaNewbie
      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.
      (see the api, according to aoutit console, I have the same data: http://api.napiarfolyam.hu/?bank=mnb&valuta=eur&datum=20161001&datumend=20161030 )
      My idea/goal (with the If @error then... after @SZAMLATELJolvaso part) is that if this happens, I want it to automaticly jump to the last date of the array (I will be able to write something more elaborate, but for now thats my goal, to save the sinking ship )
      Thank yu for your help and insight!
    • skybax
      By skybax
      Good morning all,
      I have a question regarding a situation im in...
       
      I have an array with information from sql query, how can i send this information to a listview ?
       
      $citeste_daune = "SELECT `id_dauna`,`data_incident`,`sala`,`autor`,`suma` FROM `daune` WHERE `status`=1;" $sa_citit_daune = _query($sqlinstance, $citeste_daune) Global $aresult[10001][5] = [[10000, 5]] Global $iindex = 0 With $sa_citit_daune While NOT .eof $aresult[$iindex][0] = .fields("id_dauna").value $aresult[$iindex][1] = .fields("data_incident").value $aresult[$iindex][2] = .fields("sala").value $aresult[$iindex][3] = .fields("autor").value $aresult[$iindex][4] = .fields("suma").value $iindex = $iindex + 1 .movenext WEnd EndWith ReDim $aresult[$iindex][5] $aresult[0][0] = $iindex - 1 _ArrayDisplay($aresult) GUICtrlCreateListViewItem(_ArrayToString($aresult), $lista_daune_active)  
      This is what i see when i execure _ArrayDisplay($aresult)