Jump to content

File read


Recommended Posts

An text file contains some lines like this

#123:234
#23:45
#345:123
#453:123
#233:321
#567:234
#432:346
#12:356
#56:43


want to read the Text file line by line, and extract values for 2 variable X and Y

For line 1 value will be for X=123, Y=234
the program will read all the lines in the text file line by line and mouse pointer will move on this cord: X,Y  in loop

Can anyone help to complete this please

 

ReadFile.txt

Link to comment
Share on other sites

..you're gonna get in trouble here but I'll help you this much
 

#include <Array.au3>
_ArrayDisplay(NowReadThis())
Func NowReadThis()
    Local $aArray = StringSplit(FileRead("ReadFile.txt"), @CRLF, 1)
    Local $cArray, $bArray[UBound($aArray)][2]
    $bArray[0][0] = 0
    For $n = 1 To $aArray[0]
        $cArray = StringSplit($aArray[$n], "#:")
        If UBound($cArray) < 4 Then ContinueLoop
        $bArray[0][0] += 1
        $bArray[$bArray[0][0]][0] = $cArray[2]
        $bArray[$bArray[0][0]][1] = $cArray[3]
    Next
    ReDim $bArray[$bArray[0][0] + 1][2]
    Return $bArray
EndFunc

the rest is upto you.

Welcome to the forum @ashraful089 and don't forget to read the forum rules.

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

36 minutes ago, argumentum said:

..you're gonna get in trouble here but I'll help you this much

Yes, this question is possibly borderline :lol:. Since I have just finished my solution approach, I will post it as an alternative, but also avoid MouseMove operations etc.

#Include <Array.au3>
#Include <File.au3>
Global $sFilePath = @ScriptDir & "\ReadFile.txt", $aFileRead, $aCoords
_FileReadToArray($sFilePath, $aFileRead, $FRTA_NOCOUNT)
Dim $aCoords[UBound($aFileRead)][2]
For $iLine = 0 To UBound($aFileRead) - 1
    $aCoords[$iLine][0] = StringReplace(StringSplit($aFileRead[$iLine], ':', 2)[0], '#', '')
    $aCoords[$iLine][1] = StringSplit($aFileRead[$iLine], ':', 2)[1]
Next
_ArrayDisplay($aCoords, "Coordinates", default, default, default, "X|Y")

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

6 minutes ago, Musashi said:

Yes, this question is possibly borderline :lol:. Since I have just finished my solution approach, I will post it as an alternative, but also avoid MouseMove operations etc.

Thanks for the solution. but i just need the values in 2 variable only. i dont think coordinates is my need now.. later i will use the variable values only. i am novice in autoit program. sorry if i am asking very easy things

#Include <Array.au3>
#Include <File.au3>
Global $sFilePath = @ScriptDir & "\ReadFile.txt", $aFileRead, $aCoords
_FileReadToArray($sFilePath, $aFileRead, $FRTA_NOCOUNT)
Dim $aCoords[UBound($aFileRead)][2]
For $iLine = 0 To UBound($aFileRead) - 1
    $aCoords[$iLine][0] = StringReplace(StringSplit($aFileRead[$iLine], ':', 2)[0], '#', '')
    $aCoords[$iLine][1] = StringSplit($aFileRead[$iLine], ':', 2)[1]
Next
_ArrayDisplay($aCoords, "Coordinates", default, default, default, "X|Y")

 

Link to comment
Share on other sites

8 hours ago, ashraful089 said:

values in 2 variable only

#include <Array.au3>

MainLoop()
Func MainLoop()
    Local $aArrayWithXY = NowReadThis()
;~  _ArrayDisplay($aArrayWithXY)
    If $aArrayWithXY[0][0] = 0 Then Exit 3
    While 1
        For $n = 1 To $aArrayWithXY[0][0]
            If MsgBox($MB_YESNO + $MB_TOPMOST, @ScriptName, _
                    'Entry # ' & $n & @LF & @LF & _
                    'X: ' & $aArrayWithXY[$n][0] & @LF & _
                    'Y: ' & $aArrayWithXY[$n][1] & @LF & @LF & _
                    'Continue ?', 20) <> 6 Then Exit 4
        Next
    WEnd
EndFunc

Func NowReadThis()
    Local $aArray = StringSplit(FileRead("ReadFile.txt"), @CRLF, 1)
    Local $cArray, $bArray[UBound($aArray)][2]
    $bArray[0][0] = 0
    For $n = 1 To $aArray[0]
        $cArray = StringSplit($aArray[$n], "#:")
        If UBound($cArray) < 4 Then ContinueLoop
        $bArray[0][0] += 1
        $bArray[$bArray[0][0]][0] = $cArray[2]
        $bArray[$bArray[0][0]][1] = $cArray[3]
    Next
    ReDim $bArray[$bArray[0][0] + 1][2]
    Return $bArray
EndFunc

:) 

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...