AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

listbox and file-read loop help

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Phe0n1x



Joined: 27 Dec 2006
Posts: 29

PostPosted: Sat Jan 06, 2007 12:20 am    Post subject: listbox and file-read loop help Reply with quote

first off, how does file-read loop work and how can I use it in the following situation?

I would like to have the script read each line (unknown number of lines) and input each one as a separate variable using file-read loop and stringsplit (or parse) and then input this data into a listbox so the user can select the numbers (in this case serial numbers) and then click a button to input the data into an edit field.

Code:

loop, read, well_serial_numbers.txt
{
    stringsplit, wellserial, ?????
}
Gui, 2: Add, Listbox, x16 y62 w100 h300 0x8 gnumberlistview, %1%|%2%|%3%|[etc. up to 20 or so]


So far I have gotten it to work with FileReadLine but then I would have to know how many lines there were. Also is there a way to input all of the lines as variables into the list box without specifying the variables as %1%|%2%|[etc]?

Here's a slightly shortened version:
Code:

Document_Image_Search:
ArrayCount = 0
Loop, Read, well_serial_numbers.txt
{
    ArrayCount += 1
    Array%ArrayCount% := A_LoopReadLine
}
FileReadLine, 1, well_serial_numbers.txt, 1
FileReadLine, 2, well_serial_numbers.txt, 2
FileReadLine, 3, well_serial_numbers.txt, 3
FileReadLine, 4, well_serial_numbers.txt, 4
FileReadLine, 5, well_serial_numbers.txt, 5
Gui, 2: Add, GroupBox, x6 y10 w220 h360 , Wells
Gui, 2: Add, Listbox, x16 y62 w100 h300 0x8 gnumberlistview, %1%|%2%|%3%|%4%|%5%
Gui, 2: Add, Button, x116 y30 w100 h40 gsearchbutton1, Search
Gui, 2: Add, Edit, x116 y320 w100 h20 , Add Serial Number
Gui, 2: Add, Button, x116 y340 w90 h20 AddNumberbutton, Add Number
Gui, 2: Add, Button, x260 y90 w110 h30 Logsbutton, Logs
Gui, 2: Add, Button, x260 y130 w110 h30 gWellFilesbutton, Well Files
Gui, 2: Add, GroupBox, x240 y70 w150 h100 , Type of Document
Gui, 2: Add, Button, x260 y310 w110 h40 gNewSearchbutton, New Search
Gui, 2: Add, Text, x116 y280 w100 h30 , Find
Gui, 2: Add, Button, x116 y100 w100 h30 gDeletebutton, Delete
Gui, 2: Add, GroupBox, x240 y200 w150 h80 , Search
Gui, 2: Add, Edit, x250 y230 w44 h0 , Search
Gui, 2: Add, Button, x260 y250 w110 h20 gsearchbutton2, Search
Gui, 2: Add, Edit, x260 y220 w110 h20 , Individual Search
Gui, 2: Add, Button, x246 y12 w150 h30 , Document Image Search Site
Gui, 2: Add, Text, x16 y32 w100 h20 , Number of Wells: %ArrayCount%
Gui, 2: Show, x170 y110 h377 w402, Document Image Search
return
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Sat Jan 06, 2007 5:12 am    Post subject: Reply with quote

I still haven't learned alot about listboxes, but I can definately help with File reading loops.

here is a sample text file: test.txt
Code:

Plymouth MA 02360
Seattle WA 98107
Kent WA 98032
Honolulu HI 96818


And here is something to do with it

Code:

Zipcodes =
Loop, Read, test.txt
{
StringSplit, address, A_LoopReadLine, %A_space%
MsgBox, Line, %A_index% is %A_LoopReadLine% which splits to %Address1%, %Address2%, %Address3%
Zipcodes = %Zipcodes%|%address3%
}

Gui, 2: Add, Listbox, x16 y62 w100 h300 0x8 gnumberlistview, %Zipcodes%

Or, you can use LV_Add or LV_modify

Code:

Gui,  Add, Listbox, x16 y62 w100 h300 0x8 gnumberlistview,

Loop, Read, test.txt
{
StringSplit, address, A_LoopReadLine, %A_space%
MsgBox, Line, %A_index% is %A_LoopReadLine% which splits to %Address1%, %Address2%, %Address3%
;Insert an LV_add command here
}

Gui, Show

_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
hd0202



Joined: 13 Aug 2006
Posts: 265
Location: Germany

PostPosted: Sat Jan 06, 2007 7:01 am    Post subject: Re: listbox and file-read loop help Reply with quote

Hi, try this code:

Code:

Document_Image_Search:
FileRead, Array, well_serial_numbers.txt
StringReplace, Array, Array, `r`n, |, UseErrorLevel
ArrayCount := ErrorLevel
StringRight, Last, Array, 1
if (Last <> "|")
  ArrayCount++
Gui, 2: Add, GroupBox, x6 y10 w220 h360 , Wells
Gui, 2: Add, Listbox, x16 y62 w100 h300 0x8 gnumberlistview, %Array%
Gui, 2: Add, Button, x116 y30 w100 h40 gsearchbutton1, Search
Gui, 2: Add, Edit, x116 y320 w100 h20 , Add Serial Number
Gui, 2: Add, Button, x116 y340 w90 h20 AddNumberbutton, Add Number
Gui, 2: Add, Button, x260 y90 w110 h30 Logsbutton, Logs
Gui, 2: Add, Button, x260 y130 w110 h30 gWellFilesbutton, Well Files
Gui, 2: Add, GroupBox, x240 y70 w150 h100 , Type of Document
Gui, 2: Add, Button, x260 y310 w110 h40 gNewSearchbutton, New Search
Gui, 2: Add, Text, x116 y280 w100 h30 , Find
Gui, 2: Add, Button, x116 y100 w100 h30 gDeletebutton, Delete
Gui, 2: Add, GroupBox, x240 y200 w150 h80 , Search
Gui, 2: Add, Edit, x250 y230 w44 h0 , Search
Gui, 2: Add, Button, x260 y250 w110 h20 gsearchbutton2, Search
Gui, 2: Add, Edit, x260 y220 w110 h20 , Individual Search
Gui, 2: Add, Button, x246 y12 w150 h30 , Document Image Search Site
Gui, 2: Add, Text, x16 y32 w100 h20 , Number of Wells: %ArrayCount%
Gui, 2: Show, x170 y110 h377 w402, Document Image Search
return


Hubert
Back to top
View user's profile Send private message
Guest






PostPosted: Sat Jan 06, 2007 3:55 pm    Post subject: Reply with quote

thank you, both of you. now how would I copy the numbers in the listbox that are highlighted (and find out how many were copied) into another file? I can do it with arrays right?
Back to top
Phe0n1x



Joined: 27 Dec 2006
Posts: 29

PostPosted: Sat Jan 06, 2007 3:55 pm    Post subject: Reply with quote

Anonymous wrote:
thank you, both of you. now how would I copy the numbers in the listbox that are highlighted (and find out how many were copied) into another file? I can do it with arrays right?


sorry, forgot to login
Back to top
View user's profile Send private message
hd0202



Joined: 13 Aug 2006
Posts: 265
Location: Germany

PostPosted: Sun Jan 07, 2007 8:09 am    Post subject: Reply with quote

hi Phe0n1x,

change one line

Code:

Gui, 2: Add, Listbox, x16 y62 w100 h300 0x8 vSelected gnumberlistview, %Array%


and add following lines
Code:

searchbutton1:
gui, 2: submit
StringReplace, Selected, Selected, |, `n, All
FileDelete, well_serial_numbers_out.txt
FileAppend, %Selected%`n, well_serial_numbers_out.txt
return

and you will find the selected numbers in a new file

Hubert
Back to top
View user's profile Send private message
Phe0n1x



Joined: 27 Dec 2006
Posts: 29

PostPosted: Sun Jan 07, 2007 5:14 pm    Post subject: Reply with quote

thank you, now I have all I need
Back to top
View user's profile Send private message
ahkiot0



Joined: 31 May 2008
Posts: 36

PostPosted: Wed Apr 01, 2009 7:21 am    Post subject: Reply with quote

mb im stupid but all thts codes > Target label does not exist

fck i just need make multi search in spec chosen

. CheckListBox

. SeekList.txt

. GHK, Add cliboard to SeekList.txt

for example when need seek in many (5~10) (my choosen) sites

or for example sometime need, on one site (mobygames) with specific parameters.

i guess simply create in delphi, that primitive (SmartGui? )) noway that sux!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group