dragosv6 Posted September 26, 2020 Share Posted September 26, 2020 (edited) Hi guys this is my first topic and i hope that i posted in the correct section i have a text file like below with somewhere 3000-4000 lines aaa = bbb ccc = ddd i made an input and a button when i input aaa i want to show bbb when i input ccc i want to show ddd and so on i created a script and if i input aaa and press once it shows bbb. But after that if i input ccc and press the second time i will get nothing expandcollapse popup#include <WindowsConstants.au3> #include <StaticConstants.au3> #include <guiconstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> #include <File.au3> #include <Array.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> #include <WinAPIShPath.au3> #include <INet.au3> #include <Constants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <Inet.au3> #include <Misc.au3> #include <WinAPIDiag.au3> Opt("GUIOnEventMode", 1) Global $handleGUI = GUICreate("gui", 1250, 900) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetBkColor(0xFFFFFF) Local $idMenu1 = GUICtrlCreateMenu("Menu") Local $idMenu3 = GUICtrlCreateMenu("About") GUICtrlCreateGroup("Option Checker", 960, 20, 220, 200) GUICtrlSetFont(-1, 11, 500) Global $inputfa = GUICtrlCreateInput("aaa", 970, 59, 85, 28) ;input FA GUICtrlSetFont(-1, 12, 700) Global $statusfa = GUICtrlCreateLabel("", 970, 100, 80, 28) ; Valid GUICtrlSetColor(-1, 0x00FF00) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold Global $fadescription = GUICtrlCreateLabel("", 970, 120, 300, 38) GUICtrlSetFont(-1, 11, 700) ; Bold ;GUICtrlSetFont(-1, 11, 700) Global $checkfa = GUICtrlCreateButton("Check FA", 1070, 59, 95, 30) GUICtrlSetFont(-1, 11, 500) ;GUICtrlSetOnEvent(-1, "checkfagui") GUICtrlSetOnEvent(-1, "checkfa") Global $FaPath = @ScriptDir & "\test.txt" Global $FaFileOpen = FileOpen(@ScriptDir & "\test.txt", 0) Global $FaFileRead = FileReadLine($FaFileOpen, 1) GUISetState() While 1 Sleep(20000) WEnd Func checkfa() $readinputfa = GUICtrlRead($inputfa) GUICtrlSetState($checkfa, $GUI_HIDE) Global $loadingfa = GUICtrlCreateButton("Loading", 1070, 59, 95, 30) GUICtrlSetFont(-1, 11, 500) If $FaFileOpen = -1 Then MsgBox(0, "File is missing!", "") EndIf $i = 0 For $i = 1 To _FileCountLines($FaFileOpen) Local $line = FileReadLine($FaPath, $i) Local $faoption = StringMid($line, 1, 3) Local $fadescriptionline = StringMid($line, 7, 30) If $readinputfa = $faoption Then GUICtrlSetData($statusfa, "Valid!") GUICtrlSetColor(-1, 0x00FF00) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold GUICtrlSetData($fadescription, $fadescriptionline) GUICtrlSetState($loadingfa, $GUI_HIDE) GUICtrlSetState($checkfa, $GUI_SHOW) FileClose($FaFileOpen) ExitLoop EndIf Next EndFunc ;==>checkfa Func _Exit() Exit EndFunc ;==>_Exit word_finder.txt Edited September 26, 2020 by Jos Simply add source in codebox <> Link to comment Share on other sites More sharing options...
Danp2 Posted September 26, 2020 Share Posted September 26, 2020 Welcome to the forums. From what I can see, you open the file at the beginning of your script and then close it in the fucntion checkfa. After that, you won't be able to read from the file. If the file contents aren't constantly changing, then you can avoid this issue by reading the file contents into an array and then performing your search against the array. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
dragosv6 Posted September 26, 2020 Author Share Posted September 26, 2020 Hey Danp2 Thanks for the answer Can u give me an example so i can put it into my code? thanks! Link to comment Share on other sites More sharing options...
Dan_555 Posted September 26, 2020 Share Posted September 26, 2020 (edited) Hi. Use FileReadToArray and _ArraySearch. Both have an Example in the Autoit Help file. But, if you want to make your script workable, then move the FileClose($FaFileOpen) line from CheckFa function to the _Exit function. (or just comment it out ... ) Edited September 26, 2020 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
dragosv6 Posted September 26, 2020 Author Share Posted September 26, 2020 28 minutes ago, Dan_555 said: Hi. Use FileReadToArray and _ArraySearch. Both have an Example in the Autoit Help file. But, if you want to make your script workable, then move the FileClose($FaFileOpen) line from CheckFa function to the _Exit function. nop . not working Link to comment Share on other sites More sharing options...
Developers Jos Posted September 26, 2020 Developers Share Posted September 26, 2020 Where did you move it to? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
dragosv6 Posted September 26, 2020 Author Share Posted September 26, 2020 I managed to create an array like Danp2 suggested and do a comparison but something is missing Thanks guys for trying to help me wordchecker.au3 test.txt Link to comment Share on other sites More sharing options...
zeenmakr Posted September 26, 2020 Share Posted September 26, 2020 @dragosv6 i would recommend these naming variable practices: $iLineCount - the 'i' is for interger; $sFileName - 's'=string, $hFileOpen - h=handle, a=array, c=control ect... it's difficult to read your code the way it is. 7 hours ago, dragosv6 said: i have a text file like below with somewhere 3000-4000 lines aaa = bbb ccc = ddd i made an input and a button when i input aaa i want to show bbb when i input ccc i want to show ddd are the list in test.txt file created by you or computer generated? either way, it is easier to use IniRead() but you need to add the 'section' tag to test.txt like this [Animals Dictionary] dog = Puppy cat = Kitten [Cars Dictionary] tesla = Model S 3 X Y truck = Cybertruck [EN Dictionary] aaa = a1 bbb = b1 try this expandcollapse popup#include <WindowsConstants.au3> #include <StaticConstants.au3> #include <guiconstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> #include <File.au3> #Include <Array.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> #include <WinAPIShPath.au3> #include <INet.au3> #include <Constants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <Inet.au3> #include <Misc.au3> #include <WinAPIDiag.au3> Opt("GUIOnEventMode", 1) ;~ HotKeySet('{ESC}', '_Exit') Global $sFilePath = @ScriptDir & "\test.txt" ; GUI Global $hGUI = GUICreate("My Dictionary", 1250, 900) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetBkColor(0xFFFFFF) Local $idMenu1 = GUICtrlCreateMenu("Menu") Local $idMenu3 = GUICtrlCreateMenu("About") GUICtrlCreateGroup("Option Checker", 960, 20, 220, 200) GUICtrlSetFont(-1, 11, 500) Global $cUserLookUp = GUICtrlCreateInput("dog", 970, 59, 85, 28) ;input FA GUICtrlSetFont(-1, 12, 700) GUICtrlSetTip(-1, 'Enter term to search') Global $cLookupStatus = GUICtrlCreateLabel("Status", 970, 100, 80, 28) ;display status label ;~ GUICtrlSetColor(-1, 0x00FF00) ; Green; ;~ GUICtrlSetFont(-1, 12, 700) ; Bold GUICtrlSetTip(-1, 'Status') Global $cLookupResult = GUICtrlCreateLabel("Result", 970, 120, 300, 38) ;display result found GUICtrlSetFont(-1, 11, 700) ; Bold ;GUICtrlSetFont(-1, 11, 700) GUICtrlSetTip(-1, 'Result') Global $cBtnSearch = GUICtrlCreateButton("Find", 1070, 59, 95, 30) ;action GUICtrlSetFont(-1, 11, 500) ;GUICtrlSetOnEvent(-1, "checkfagui") GUICtrlSetOnEvent(-1, "_DictionaryFinder") GUISetState() ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; Delete the previous GUIs and all controls. GUIDelete($hGUI) ExitLoop EndSwitch WEnd ; ----------------------- ; e.g dictionary format ; ----------------------- ;~ [Animals Dictionary] ;~ dog = puppy ;~ dat = Kitten ;~ [Cars Dictionary] ;~ tesla = Model S 3 X Y ;~ truck = Cybertruck ;~ [EN Dictionary] ;~ aaa = a1 ;~ bbb = b1 Func _DictionaryFinder() Local $sDictionaryType Local $sw = 1 Switch $sw Case 1 Local $sDictionaryType = "Animals Dictionary" Case 2 Local $sDictionaryType = "Cars Dictionary" Case 3 Local $sDictionaryType = "EN Dictionary" EndSwitch Local $sUserLookupTerm = GUICtrlRead($cUserLookUp) Local $sDefaultValue = "No Search Result Found" Local $sRead = IniRead($sFilePath, $sDictionaryType, $sUserLookupTerm, $sDefaultValue) ;~ If $sRead == $sDefaultValue Then If StringCompare($sRead, $sDefaultValue, $STR_NOCASESENSEBASIC) Then GUICtrlSetData($cLookupStatus,"SUCCESS") GUICtrlSetColor($cLookupStatus, 0x00FF00) ; Green GUICtrlSetFont($cLookupStatus, 12, 700) ; Bold GUICtrlSetData($cLookupResult, $sUserLookupTerm &' = '& $sRead) ;set result Else GUICtrlSetData($cLookupStatus,"FAIL") GUICtrlSetColor($cLookupStatus, 0xff0000) ; red GUICtrlSetFont($cLookupStatus, 12, 700) ; Bold GUICtrlSetData($cLookupResult, $sUserLookupTerm &' = '& $sRead) ;set result EndIf EndFunc ; WARNING THERE ARE LOTS OF PROBLEMS IN THIS FUNCTION - no changes made yet Func _DictionaryFinderXXX() Local $hFileOpen = FileOpen($sFilePath, $FO_READ) Local $sUserLookupTerm = GUICtrlRead($cUserLookUp) GUICtrlSetState($cBtnSearch, $GUI_HIDE) Global $loadingfa = GUICtrlCreateButton("Loading", 1070, 59, 95, 30) Dim $aDictionary If Not _FileReadToArray($sFilePath, $aDictionary) Then MsgBox(4096, "Error", " Error reading text file to Array error:" & @error) Exit EndIf _ArrayDisplay($aDictionary, "Debug: $aDictionary") ; Split lines into 2D array Dim $aSplittedLine[$aDictionary[0] + 1][2] = [["col1", "col2"]] ;MsgBox(0,"","" & $aDictionary[0] ) For $x = 1 To $aDictionary[0] $aLookupWord = StringSplit($aDictionary[$x], "=") If $aLookupWord[0] = 2 Then $aSplittedLine[$x][0] = $aLookupWord[1] $aSplittedLine[$x][1] = $aLookupWord[2] EndIf If $sUserLookupTerm = $aSplittedLine[$x][0] Then GUICtrlSetData($cLookupStatus,"Valid!") GUICtrlSetColor(-1, 0x00FF00) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold GUICtrlSetData($cLookupResult,$aSplittedLine[$x][1]) GUICtrlSetState($loadingfa, $GUI_HIDE) GUICtrlSetState($cBtnSearch, $GUI_SHOW) EndIf Next _ArrayDisplay($aSplittedLine, "Debug: $aSplittedLine") EndFunc Func _Exit() Exit EndFunc ;==>_Exit dragosv6 1 Link to comment Share on other sites More sharing options...
Dan_555 Posted September 26, 2020 Share Posted September 26, 2020 (edited) The textfile contains following line: aaa = bbb when you are using the string split method, the aaa has a space after it, so the array gets the "aaa " as a string, which does not match the aaa search. this should work: expandcollapse popup#include <WindowsConstants.au3> #include <StaticConstants.au3> #include <guiconstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> #include <File.au3> #include <Array.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> #include <WinAPIShPath.au3> #include <INet.au3> #include <Constants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <Inet.au3> #include <Misc.au3> #include <WinAPIDiag.au3> Opt("GUIOnEventMode", 1) Global $handleGUI = GUICreate("gui", 1250, 900) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetBkColor(0xFFFFFF) Local $idMenu1 = GUICtrlCreateMenu("Menu") Local $idMenu3 = GUICtrlCreateMenu("About") GUICtrlCreateGroup("Option Checker", 960, 20, 220, 200) GUICtrlSetFont(-1, 11, 500) Global $inputfa = GUICtrlCreateInput("aaa", 970, 59, 85, 28) ;input FA GUICtrlSetFont(-1, 12, 700) Global $statusfa = GUICtrlCreateLabel("", 970, 100, 80, 28) ; Valid GUICtrlSetColor(-1, 0x00FF00) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold Global $fadescription = GUICtrlCreateLabel("", 970, 120, 300, 38) GUICtrlSetFont(-1, 11, 700) ; Bold ;GUICtrlSetFont(-1, 11, 700) Global $checkfa = GUICtrlCreateButton("Check FA", 1070, 59, 95, 30) GUICtrlSetFont(-1, 11, 500) ;GUICtrlSetOnEvent(-1, "checkfagui") GUICtrlSetOnEvent(-1, "Check") Global $sFile = @ScriptDir & "\test.txt" Global $FaFileOpen = FileOpen(@ScriptDir & "\test.txt", 0) ;Global $FaFileRead = FileReadLine($FaFileOpen, 1) GUISetState() While 1 Sleep(20000) WEnd Func Check() $readinputfa = GUICtrlRead($inputfa) GUICtrlSetState($checkfa, $GUI_HIDE) Global $loadingfa = GUICtrlCreateButton("Loading", 1070, 59, 95, 30) Dim $text If Not _FileReadToArray($sFile, $text) Then MsgBox(4096, "Error", " Error reading text file to Array error:" & @error) Exit EndIf ;_ArrayDisplay($text, "Debug: $text") ; Split lines into 2D array Dim $avIPs[$text[0] + 1][2] = [["col1", "col2"]] ;MsgBox(0,"","" & $text[0] ) For $x = 1 To $text[0] $array = StringSplit($text[$x], "=") If $array[0] = 2 Then $avIPs[$x][0] = StringStripWs($array[1],3) $avIPs[$x][1] = StringStripWs($array[2],3) EndIf ConsoleWrite ( $x & ": " & chr(34) & $readinputfa &chr(34) & " = " &chr(34) & $avIPs[$x][0] &chr(34) & @crlf) If $readinputfa = $avIPs[$x][0] Then ConsoleWrite ("found" & $avIPs[$x][1] & @crlf) GUICtrlSetData($statusfa, "Valid!") GUICtrlSetColor(-1, 0x00FF00) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold GUICtrlSetData($fadescription, $avIPs[$x][1]) EndIf Next ;_ArrayDisplay($avIPs, "Debug: $avIPs") GUICtrlSetState($loadingfa, $GUI_HIDE) GUICtrlSetState($checkfa, $GUI_SHOW) EndFunc ;==>Check Func _Exit() FileClose($FaFileOpen) Exit EndFunc ;==>_Exit Edited September 26, 2020 by Dan_555 dragosv6 1 Some of my script sourcecode Link to comment Share on other sites More sharing options...
dragosv6 Posted September 26, 2020 Author Share Posted September 26, 2020 yap working! i used the one that Dan_555 proposed but also tested the one zeenmakr suggested. Both are ok! gave u guys a thank you! Link to comment Share on other sites More sharing options...
dragosv6 Posted September 26, 2020 Author Share Posted September 26, 2020 19 minutes ago, Dan_555 said: The textfile contains following line: aaa = bbb when you are using the string split method, the aaa has a space after it, so the array gets the "aaa " as a string, which does not match the aaa search. this should work: expandcollapse popup#include <WindowsConstants.au3> #include <StaticConstants.au3> #include <guiconstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> #include <File.au3> #include <Array.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> #include <WinAPIShPath.au3> #include <INet.au3> #include <Constants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <Inet.au3> #include <Misc.au3> #include <WinAPIDiag.au3> Opt("GUIOnEventMode", 1) Global $handleGUI = GUICreate("gui", 1250, 900) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetBkColor(0xFFFFFF) Local $idMenu1 = GUICtrlCreateMenu("Menu") Local $idMenu3 = GUICtrlCreateMenu("About") GUICtrlCreateGroup("Option Checker", 960, 20, 220, 200) GUICtrlSetFont(-1, 11, 500) Global $inputfa = GUICtrlCreateInput("aaa", 970, 59, 85, 28) ;input FA GUICtrlSetFont(-1, 12, 700) Global $statusfa = GUICtrlCreateLabel("", 970, 100, 80, 28) ; Valid GUICtrlSetColor(-1, 0x00FF00) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold Global $fadescription = GUICtrlCreateLabel("", 970, 120, 300, 38) GUICtrlSetFont(-1, 11, 700) ; Bold ;GUICtrlSetFont(-1, 11, 700) Global $checkfa = GUICtrlCreateButton("Check FA", 1070, 59, 95, 30) GUICtrlSetFont(-1, 11, 500) ;GUICtrlSetOnEvent(-1, "checkfagui") GUICtrlSetOnEvent(-1, "Check") Global $sFile = @ScriptDir & "\test.txt" Global $FaFileOpen = FileOpen(@ScriptDir & "\test.txt", 0) ;Global $FaFileRead = FileReadLine($FaFileOpen, 1) GUISetState() While 1 Sleep(20000) WEnd Func Check() $readinputfa = GUICtrlRead($inputfa) GUICtrlSetState($checkfa, $GUI_HIDE) Global $loadingfa = GUICtrlCreateButton("Loading", 1070, 59, 95, 30) Dim $text If Not _FileReadToArray($sFile, $text) Then MsgBox(4096, "Error", " Error reading text file to Array error:" & @error) Exit EndIf ;_ArrayDisplay($text, "Debug: $text") ; Split lines into 2D array Dim $avIPs[$text[0] + 1][2] = [["col1", "col2"]] ;MsgBox(0,"","" & $text[0] ) For $x = 1 To $text[0] $array = StringSplit($text[$x], "=") If $array[0] = 2 Then $avIPs[$x][0] = StringStripWs($array[1],3) $avIPs[$x][1] = StringStripWs($array[2],3) EndIf ConsoleWrite ( $x & ": " & chr(34) & $readinputfa &chr(34) & " = " &chr(34) & $avIPs[$x][0] &chr(34) & @crlf) If $readinputfa = $avIPs[$x][0] Then ConsoleWrite ("found" & $avIPs[$x][1] & @crlf) GUICtrlSetData($statusfa, "Valid!") GUICtrlSetColor(-1, 0x00FF00) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold GUICtrlSetData($fadescription, $avIPs[$x][1]) EndIf Next ;_ArrayDisplay($avIPs, "Debug: $avIPs") GUICtrlSetState($loadingfa, $GUI_HIDE) GUICtrlSetState($checkfa, $GUI_SHOW) EndFunc ;==>Check Func _Exit() FileClose($FaFileOpen) Exit EndFunc ;==>_Exit Dan one more question if i want to insert a Else where to put it? i tried to insert it here: If $readinputfa = $avIPs[$x][0] Then ConsoleWrite ("found" & $avIPs[$x][1] & @crlf) GUICtrlSetData($statusfa, "Valid!") GUICtrlSetColor(-1, 0x00FF00) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold GUICtrlSetData($fadescription, $avIPs[$x][1]) Else GUICtrlSetData($statusfa, "Invalid!") GUICtrlSetColor(-1, 0xFFFFFF) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold ;GUICtrlSetData($fadescription, $avIPs[$x][1]) EndIf but it sais invalid all the time. Link to comment Share on other sites More sharing options...
Dan_555 Posted September 26, 2020 Share Posted September 26, 2020 Put an exitloop command just before the else Some of my script sourcecode Link to comment Share on other sites More sharing options...
dragosv6 Posted September 26, 2020 Author Share Posted September 26, 2020 4 minutes ago, Dan_555 said: Put an exitloop command just before the else nop same For $x = 1 To $text[0] $array = StringSplit($text[$x], "=") If $array[0] = 2 Then $avIPs[$x][0] = StringStripWs($array[1],3) $avIPs[$x][1] = StringStripWs($array[2],3) EndIf ;ConsoleWrite ( $x & ": " & chr(34) & $readinputfa &chr(34) & " = " &chr(34) & $avIPs[$x][0] &chr(34) & @crlf) If $readinputfa = $avIPs[$x][0] Then ConsoleWrite ("found:"& $avIPs[$x][0] & " = " & $avIPs[$x][1] & @crlf) GUICtrlSetData($statusfa, "Valid!") GUICtrlSetColor(-1, 0x00FF00) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold GUICtrlSetData($fadescription, $avIPs[$x][1]) ExitLoop Else ;ConsoleWrite ("notfound" & $avIPs[$x][1] & @crlf) GUICtrlSetData($statusfa, "Invalid!") GUICtrlSetColor(-1, 0xFFFFFF) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold ;GUICtrlSetData($fadescription, $avIPs[$x][1]) EndIf Next Link to comment Share on other sites More sharing options...
dragosv6 Posted September 26, 2020 Author Share Posted September 26, 2020 and if i put 4000 lines it stays somewhere for 10 seconds and this time the Valid Or invalid keeps blinking Link to comment Share on other sites More sharing options...
zeenmakr Posted September 26, 2020 Share Posted September 26, 2020 10 minutes ago, dragosv6 said: but it sais invalid all the time. here is something to think about: although your original method works and because you have a large text file it takes longer than it is supposed to to search. because your file is formatted the way it it, take advantage the IniRead() which is much more efficient. _ArraySearch() is an alternative suggested after _FileReadToArray(). I dont' see why you need to re-invent the wheel. Also do take into account case sensitive check as well 6 minutes ago, Dan_555 said: Put an exitloop command just before the else Exitloop is for while loop, ContinueLoop is for for loop Link to comment Share on other sites More sharing options...
zeenmakr Posted September 26, 2020 Share Posted September 26, 2020 3 minutes ago, dragosv6 said: and if i put 4000 lines it stays somewhere for 10 seconds and this time the Valid Or invalid keeps blinking this is the inefficiency im referring to. Do or While loop allows to exit loop once search found Link to comment Share on other sites More sharing options...
Dan_555 Posted September 26, 2020 Share Posted September 26, 2020 (edited) Then do it in this way: expandcollapse popup#include <WindowsConstants.au3> #include <StaticConstants.au3> #include <guiconstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> #include <File.au3> #include <Array.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> #include <WinAPIShPath.au3> #include <INet.au3> #include <Constants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <Inet.au3> #include <Misc.au3> #include <WinAPIDiag.au3> Opt("GUIOnEventMode", 1) Global $handleGUI = GUICreate("gui", 1250, 900) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetBkColor(0xFFFFFF) Local $idMenu1 = GUICtrlCreateMenu("Menu") Local $idMenu3 = GUICtrlCreateMenu("About") GUICtrlCreateGroup("Option Checker", 960, 20, 220, 200) GUICtrlSetFont(-1, 11, 500) Global $inputfa = GUICtrlCreateInput("aaa", 970, 59, 85, 28) ;input FA GUICtrlSetFont(-1, 12, 700) Global $statusfa = GUICtrlCreateLabel("", 970, 100, 80, 28) ; Valid GUICtrlSetColor(-1, 0x00FF00) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold Global $fadescription = GUICtrlCreateLabel("", 970, 120, 300, 38) GUICtrlSetFont(-1, 11, 700) ; Bold ;GUICtrlSetFont(-1, 11, 700) Global $checkfa = GUICtrlCreateButton("Check FA", 1070, 59, 95, 30) GUICtrlSetFont(-1, 11, 500) ;GUICtrlSetOnEvent(-1, "checkfagui") GUICtrlSetOnEvent(-1, "Check") Global $sFile = @ScriptDir & "\test.txt" Global $FaFileOpen = FileOpen(@ScriptDir & "\test.txt", 0) ;Global $FaFileRead = FileReadLine($FaFileOpen, 1) GUISetState() While 1 Sleep(20000) WEnd Func Check() local $found=-1 $readinputfa = GUICtrlRead($inputfa) GUICtrlSetState($checkfa, $GUI_HIDE) Global $loadingfa = GUICtrlCreateButton("Loading", 1070, 59, 95, 30) Dim $text If Not _FileReadToArray($sFile, $text) Then MsgBox(4096, "Error", " Error reading text file to Array error:" & @error) Exit EndIf ;_ArrayDisplay($text, "Debug: $text") ; Split lines into 2D array Dim $avIPs[$text[0] + 1][2] = [["col1", "col2"]] ;MsgBox(0,"","" & $text[0] ) For $x = 1 To $text[0] $array = StringSplit($text[$x], "=") If $array[0] = 2 Then $avIPs[$x][0] = StringStripWS($array[1], 3) $avIPs[$x][1] = StringStripWS($array[2], 3) EndIf ConsoleWrite($x & ": " & Chr(34) & $readinputfa & Chr(34) & " = " & Chr(34) & $avIPs[$x][0] & Chr(34) & @CRLF) If $readinputfa = $avIPs[$x][0] Then ConsoleWrite("found" & $avIPs[$x][1] & @CRLF) $found=$x ExitLoop EndIf Next ;_ArrayDisplay($avIPs, "Debug: $avIPs") if $found>-1 then GUICtrlSetData($statusfa, "Valid!") GUICtrlSetColor(-1, 0x00FF00) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold GUICtrlSetData($fadescription, $avIPs[$found][1]) Else ;ConsoleWrite ("notfound" & $avIPs[$x][1] & @crlf) GUICtrlSetData($statusfa, "Invalid!") GUICtrlSetColor(-1, 0xFFFFFF) ; Green; GUICtrlSetFont(-1, 12, 700) ; Bold ;GUICtrlSetData($fadescription, $avIPs[$x][1]) EndIf GUICtrlSetState($loadingfa, $GUI_HIDE) GUICtrlSetState($checkfa, $GUI_SHOW) EndFunc ;==>Check Func _Exit() FileClose($FaFileOpen) Exit EndFunc ;==>_Exit Edit: Of course, to read in the file and to split the array each time is a bit inefficient, it can be done once (provided that the text file is not changed on the fly). from the Help file: Quote ExitLoop Terminate a While/Do/For loop. Edited September 26, 2020 by Dan_555 dragosv6 1 Some of my script sourcecode Link to comment Share on other sites More sharing options...
zeenmakr Posted September 26, 2020 Share Posted September 26, 2020 4 minutes ago, Dan_555 said: Terminate a While/Do/For loop. stand corrected Link to comment Share on other sites More sharing options...
dragosv6 Posted September 26, 2020 Author Share Posted September 26, 2020 yap all good now tried all possibilities and are fine Thanks Dan_555 for the help. Also Thanks zeenmakr for the ini suggestion. 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