ashraful089 Posted July 29, 2020 Share Posted July 29, 2020 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 More sharing options...
argumentum Posted July 29, 2020 Share Posted July 29, 2020 (edited) ..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 July 29, 2020 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Musashi Posted July 29, 2020 Share Posted July 29, 2020 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 . 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") "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 More sharing options...
argumentum Posted July 29, 2020 Share Posted July 29, 2020 ..every time I read "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move.", it just makes me laugh Musashi 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
ashraful089 Posted July 29, 2020 Author Share Posted July 29, 2020 6 minutes ago, Musashi said: Yes, this question is possibly borderline . 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 More sharing options...
argumentum Posted July 29, 2020 Share Posted July 29, 2020 (edited) 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 July 29, 2020 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now