Sylo Posted July 14, 2008 Share Posted July 14, 2008 (edited) Ok, what I am trying to do is create a program to take an input and then search a text file for this input. Now I have searched the forums but with no luck of finding something close to what I am trying to do. The lines in the text file look something like this: "10 ","9781870471626","9781870471626","Stress P/bk ","" Now I would like to set this up to either search by "9781870471626" or "Stress P/bk" and then get back the first number in that line "10" which is the ID am trying to find. To give an idea how I have been going about this here is what I have done so far. First I took the text file and read to an array. Then created a input box for the use to put in what they are searching for. Then I do an _ArraySearch to see if what they put in was found or not. Please keep in mind I am very new to this and I know this is most likely completely wrong way to go about doing this task. My Code: #include <GUIConstantsEx.au3> #include <file.au3> #include <Array.au3> Opt('MustDeclareVars', 1) Global $itemsFile Global $lineRead Global $itemArray Global $userInput Global $itemOutput _FileReadToArray(C:\Test_items.txt", $itemArray) $userInput = InputBox("Enter Item","Please Enter The Item Number","") If $userInput = "" then MsgBox(0,"Empty", "Nothing Entered, Closing Program",3) EndIf $itemOutput = _ArraySearch($itemArray, $userInput) if $itemOutput = -1 Then MsgBox(0,"Not Found","Could Not Find Item") Else if $itemOutput = 1 Then MsgBox(0,"Item Found","Output goes here!") EndIf EndIf Exit Edited July 14, 2008 by Sylo Link to comment Share on other sites More sharing options...
Valuater Posted July 14, 2008 Share Posted July 14, 2008 This should do the trick.... expandcollapse popup#include <GUIConstantsEx.au3> #include <file.au3> #include <Array.au3> Opt('MustDeclareVars', 1) Global $itemsFile Global $lineRead Global $itemArray Global $userInput Global $itemOutput Global $Split, $return = "" _FileReadToArray("C:\Test_items.txt", $itemArray) $userInput = InputBox("Enter Item", "Please Enter The Item Number", "") If $userInput = "" Then MsgBox(0, "Empty", "Nothing Enter, Closing Program", 3) Exit EndIf For $x = 1 To UBound($itemArray) - 1 $Split = StringSplit($itemArray[$x], ",") If StringInStr($itemArray[$x], $userInput) Then $return &= $Split[1] & @CRLF ; return is 1st number ; ExitLoop ; use this if you ONLY want the first match EndIf Next If $return <> "" Then MsgBox(0, "Item(s) Found", $return) Else MsgBox(0, "Empty", "Nothing Enter, Closing Program", 3) EndIf 8) ***** not tested 8) Link to comment Share on other sites More sharing options...
Sylo Posted July 14, 2008 Author Share Posted July 14, 2008 (edited) This should do the trick.... expandcollapse popup#include <GUIConstantsEx.au3> #include <file.au3> #include <Array.au3> Opt('MustDeclareVars', 1) Global $itemsFile Global $lineRead Global $itemArray Global $userInput Global $itemOutput Global $Split, $return = "" _FileReadToArray("C:\Test_items.txt", $itemArray) $userInput = InputBox("Enter Item", "Please Enter The Item Number", "") If $userInput = "" Then MsgBox(0, "Empty", "Nothing Enter, Closing Program", 3) Exit EndIf For $x = 1 To UBound($itemArray) - 1 $Split = StringSplit($itemArray[$x], ",") If StringInStr($itemArray[$x], $userInput) Then $return &= $Split[1] & @CRLF ; return is 1st number ; ExitLoop ; use this if you ONLY want the first match EndIf Next If $return <> "" Then MsgBox(0, "Item(s) Found", $return) Else MsgBox(0, "Empty", "Nothing Enter, Closing Program", 3) EndIf 8) ***** not tested 8) For $x = 1 To UBound($itemArray) - 1 $Split = StringSplit($itemArray[$x], ",") If StringInStr($itemArray[$x], $userInput) Then $return &= $Split[1] & @CRLF; return is 1st number ; ExitLoop; use this if you ONLY want the first match EndIf Next If you could can you please explain what this does. I looked in the help file and am still a bit confused on how this works. Also to make it so that after the item found and they hit ok, to make iit go back to the inputbox, would i make it one big While loop? same if it is not found? p.s. I will test it right now...thanks for the help! Edited July 14, 2008 by Sylo Link to comment Share on other sites More sharing options...
Sylo Posted July 14, 2008 Author Share Posted July 14, 2008 It works so far...just want to thank you for your help. Was I that far off? Or was I going in the right direction? Link to comment Share on other sites More sharing options...
Sylo Posted July 14, 2008 Author Share Posted July 14, 2008 I have another question for you. I am trying to take output it get when i search for an item and display it in a list. This way I can show all parts of it and not just the company. I looked at using GUICtrlListVeiw and see if that can help me. But I can't seem to get it to work. Code: For $x = 1 To UBound($itemArray) - 1 $Split = StringSplit($itemArray[$x], ",") If StringInStr($itemArray[$x], $userInput) Then $return &= $Split[1] & @CRLF ;returns the company number (the first number in the line) ;ExitLoop EndIf Next GUICreate("Test",420,250, 100,400,-1) $listview = GUICtrlCreateListView("Company|Item Number|ISBN ",10,10,400,150);,$LVS_SORTDESCENDING) $listview_ctrl = GUICtrlCreateListViewItem($Split[1] & "|" & $Split[2] & "|" & $Split[3] & "|" & $Split[4], $listview) if $return <> "" Then MsgBox(0,"Item(s) Found", GUICtrlRead($listview)) Else MsgBox(0, "Item Not Found", "Not Found, Closing Program", 3) EndIf Link to comment Share on other sites More sharing options...
Valuater Posted July 14, 2008 Share Posted July 14, 2008 (edited) Use/Try _ArrayDisplay() 8) Wait,,,,, Edited July 14, 2008 by Valuater Link to comment Share on other sites More sharing options...
Sylo Posted July 14, 2008 Author Share Posted July 14, 2008 Use/Try _ArrayDisplay()8)Wait,,,,,Because some times if the use enters in a part of a title of a book instead of the whole thing there might be more then 1 book with similar title. This way i can show them then they can choose the one that best fits the book they are trying to find the company for. Link to comment Share on other sites More sharing options...
Valuater Posted July 14, 2008 Share Posted July 14, 2008 because YOU are trying!.... expandcollapse popup#include <GUIConstantsEx.au3> #include <file.au3> #include <Array.au3> Opt('MustDeclareVars', 1) Global $itemsFile Global $lineRead Global $itemArray Global $userInput Global $itemOutput Global $Split, $return = "", $GUI, $listview _FileReadToArray("C:\Test_items.txt", $itemArray) $userInput = InputBox("Enter Item", "Please Enter The Item Number", "") If $userInput = "" Then MsgBox(0, "Empty", "Nothing Enter, Closing Program", 3) Exit EndIf For $x = 1 To UBound($itemArray) - 1 $Split = StringSplit($itemArray[$x], ",") If StringInStr($itemArray[$x], $userInput) Then $return &= $Split[1] & @CRLF ; return is 1st number DisplayAdd($Split) ; ExitLoop ; use this if you ONLY want the first match EndIf Next If $return <> "" Then MsgBox(0, "Item(s) Found", $return) Else MsgBox(0, "Empty", "Nothing Enter, Closing Program", 3) EndIf ; Functions -------------------------------- Func DisplayAdd($Spliter) Local $listview_ctrl If Not IsHWnd($GUI) Then $GUI = GUICreate("Test", 420, 250, 100, 400, -1) $listview = GUICtrlCreateListView("Company|Item Number|ISBN ", 10, 10, 400, 150);,$LVS_SORTDESCENDING) $listview_ctrl = GUICtrlCreateListViewItem($Spliter[1] & "|" & $Spliter[2] & "|" & $Spliter[3] & "|" & $Spliter[4], $listview) GUISetState() Else $listview_ctrl = GUICtrlCreateListViewItem($Spliter[1] & "|" & $Spliter[2] & "|" & $Spliter[3] & "|" & $Spliter[4], $listview) EndIf EndFunc ;==>DisplayAdd *** not tested 8) Link to comment Share on other sites More sharing options...
Sylo Posted July 14, 2008 Author Share Posted July 14, 2008 Thanks again....wish I didn't have to bug you so much for this...just having a hard time getting started with this stuff.... Link to comment Share on other sites More sharing options...
Valuater Posted July 15, 2008 Share Posted July 15, 2008 Thanks again....wish I didn't have to bug you so much for this...just having a hard time getting started with this stuff....That's really OK!we like helping people who want to help themselves. Some just want to order a program and take advantage of our free help.8) Link to comment Share on other sites More sharing options...
Sylo Posted July 22, 2008 Author Share Posted July 22, 2008 (edited) That's really OK! we like helping people who want to help themselves. Some just want to order a program and take advantage of our free help. 8) Ok one more question!! I am now trying to make it so I can have more then just the first thing matching the search. Here is example text file the program is searching: "53 ","2499","","PAINTER 5 WOW! ","" "53 ","2572PP0321205472","","ADOBE ENCORE DVD CIAB DISCONTI","" "53 ","2671IN0741427206","","THE RADIO FUNNY BOOK ","" "53 ","2777EL0240806336","","PHOTOSHOP FOR DIGITAL VIDEO ","" "53 ","2900AD0790611368","","SIMPLIFYING DIGITAL SIGNAL PRO","" "53 ","2991CP1578202604","","INSTANT VEGAS 5 ","" "53 ","3830","","B'CASTERS LAW & REG CONFERENCE","" "53 ","2777EL0240806336","","PHOTOSHOP FOR DIGITAL VIDEO TEST 1 ","" "53 ","2777EL0240806336","","PHOTOSHOP FOR DIGITAL VIDEO TEST 2 ","" "53 ","2777EL0240806336","","PHOTOSHOP FOR DIGITAL VIDEO TEST 3 ","" Notice there are multiple items with similar numbers. I am trying to make it so that it brings up all the ones meeting the search. Code: expandcollapse popup#include <GUIConstantsEx.au3> #include <file.au3> #include <Array.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Global $itemArray Global $userInput Global $itemOutput Global $Split Global $return = "" Global $listview Global $GUI Global $listview_ctrl Global $lastline _FileReadToArray("C:\List_Test.txt", $itemArray);reads the file into the array $userInput = InputBox("Enter Item", "Please Enter The ISBN Number or Title of Book", "") If $userInput = "" Then;just checks to make sure something is entered into the input box MsgBox(0, "Empty", "Nothing Entered, Closing Program", 3) Exit EndIf For $x = 1 To UBound($itemArray) - 1 $Split = StringSplit($itemArray[$x], ",");how the line is broke down If StringInStr($itemArray[$x], $userInput) Then $return = $Split[1] & @CRLF;returns the company number (the first number in the line) DisplayAdd($Split) ExitLoop EndIf Next Func DisplayAdd($Split);creates the output into a list Local $listview_ctrl Local $button1 Local $msg While 1 $msg = GUIGetMsg() If Not IsHWnd($GUI) Then;checks to make sure $GUI is a valid window ;MsgBox(0,"Testing to see if this works!!", $GUI,3) $GUI = GUICreate("Items Found",420,250,275,275,-1) $listview = GUICtrlCreateListView("Company|Item Number|ISBN|Title", 10, 10, 400, 150) $listview_ctrl = GUICtrlCreateListViewItem($Split[1] & "|" & $Split[2] & "|" & $Split[3] & "|" & $Split[4], $listview) $button1 = GUICtrlCreateButton ("Close", 160, 205, 70, 20) GUISetState() EndIf Do ;MsgBox(0,"Getting to the DO statement", $EOF,3) $Split = StringSplit($itemArray[$x], ",") $listview_ctrl = GUICtrlCreateListViewItem($Split[1] & "|" & $Split[2] & "|" & $Split[3] & "|" & $Split[4], $listview) Until Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $button1 ExitLoop EndSelect WEnd EndFunc ;==>DisplayAdd Edited July 22, 2008 by Sylo Link to comment Share on other sites More sharing options...
Bert Posted July 22, 2008 Share Posted July 22, 2008 I'm wondering is using SQL may be a better way to go on this. Look at the SQlite section in the User Defined Functions area of the helpfile. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Sylo Posted July 22, 2008 Author Share Posted July 22, 2008 I'm wondering is using SQL may be a better way to go on this. Look at the SQlite section in the User Defined Functions area of the helpfile.Thanks, I will check that out. 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