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 

How to insert a variable into every line of a lisbox?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Hedonist



Joined: 24 Jan 2005
Posts: 34

PostPosted: Sun Jul 06, 2008 7:05 pm    Post subject: How to insert a variable into every line of a lisbox? Reply with quote

I need to retrieve data from a list box then insert a constant variable into every line of that list box. The data is then appended to a file. Here is how I am retrieving the data.
Code:
ControlGet,servers,list,,ListBox1,


Here is the listbox content.
    server1
    server2
    server3
    server4


Here is what I need. The constant is "grid".
    grid,server1,
    grid,server2,
    grid,server3,
    grid,server4,


Any help?
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Sun Jul 06, 2008 7:27 pm    Post subject: Reply with quote

Look up Loop, Parse and FileAppend

HTH
Back to top
Hedonist



Joined: 24 Jan 2005
Posts: 34

PostPosted: Sun Jul 06, 2008 8:38 pm    Post subject: Reply with quote

Can you give me an example?
Back to top
View user's profile Send private message
Hedonist



Joined: 24 Jan 2005
Posts: 34

PostPosted: Sun Jul 06, 2008 9:25 pm    Post subject: I need to retrieve data from a edit box Reply with quote

Ok.. I canged my mind. I am going to use a Edit box instead of a Listbox. So here is my question.

I need to retrieve data from a edit box then insert a constant variable into every line of that edit box data. The data is then appended to a file. Here is how I am retrieving the data.
Code:
GuiControlGet,servers,,Edit1,


Here is the Edit box content.
    server1
    server2
    server3
    server4


Here is what I need as a result. The constant is "grid".
    grid,server1,
    grid,server2,
    grid,server3,
    grid,server4,


Any help?
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Sun Jul 06, 2008 9:38 pm    Post subject: Reply with quote

Code:
servers=
(
server1
server2
server3
server4
)

loop, parse, servers, `n, `r
  new .= "grid," a_loopfield "`n"
 
msgbox, % new 


Smile
_________________
Back to top
View user's profile Send private message
Hedonist



Joined: 24 Jan 2005
Posts: 34

PostPosted: Sun Jul 06, 2008 10:05 pm    Post subject: Reply with quote

Sorry I should had specified. Grid comes from a variable %grid%.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Sun Jul 06, 2008 10:26 pm    Post subject: Reply with quote

Code:
servers=
(
server1
server2
server3
server4
)

loop, parse, servers, `n, `r
  new .= grid "," a_loopfield "`n"
 
msgbox, % new


Smile
_________________
Back to top
View user's profile Send private message
Hedonist



Joined: 24 Jan 2005
Posts: 34

PostPosted: Sun Jul 06, 2008 10:39 pm    Post subject: Reply with quote

That simple? I was trying to use.
Code:
new .= %grid% "," a_loopfield "`n"


Thanks allot.
Back to top
View user's profile Send private message
Hedonist



Joined: 24 Jan 2005
Posts: 34

PostPosted: Sun Jul 06, 2008 11:07 pm    Post subject: Reply with quote

One problem. This gives me a blank server at the end of the list.

Like this.
    grid1,server1,
    grid1,server2,
    grid1,server3,
    grid1,,
    grid2,server88,
    grid2,server89,
    grid2,server90,
    grid2,,


Her is my code.
Code:
GuiControlGet,servers,,Edit1,
loop, parse, servers, `n, `r
  newservers .= "`n" grid "," a_loopfield ","


How can I get it to ignore a blank line?
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Mon Jul 07, 2008 6:17 am    Post subject: Reply with quote

Code:
GuiControlGet,servers,,Edit1,
loop, parse, servers, `n, `r
  newservers .= (( A_Index = 1 ) ? "" : "`n" ) grid "," a_loopfield ","

_________________
Back to top
View user's profile Send private message
Hedonist



Joined: 24 Jan 2005
Posts: 34

PostPosted: Mon Jul 07, 2008 2:36 pm    Post subject: Reply with quote

That didn't work. It isn't omitting the blank line at the end of the list. I have to leave a carriage return after every entry. That is how the scanner that I am using works.

My list looks like this.
    server1
    server2
    server3
    --->this is a blank line<---

    I still get this.
      grid1,server1,
      grid1,server2,
      grid1,server3,
      grid1,,
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Mon Jul 07, 2008 5:59 pm    Post subject: Reply with quote

Code:
GuiControlGet,servers,,Edit1,
loop, parse, servers, `n, `r
{
  ifequal,a_loopfield,, continue
  newservers .= (( A_Index = 1 ) ? "" : "`n" ) grid "," a_loopfield ","
}


Smile
_________________
Back to top
View user's profile Send private message
Hedonist



Joined: 24 Jan 2005
Posts: 34

PostPosted: Mon Jul 07, 2008 10:21 pm    Post subject: Reply with quote

That's it.. Thanks so much.
Back to top
View user's profile Send private message
Hedonist



Joined: 24 Jan 2005
Posts: 34

PostPosted: Tue Jul 08, 2008 11:37 pm    Post subject: Reply with quote

SKAN,

That worked real well in Windows XP, but I am writing this for Windows CE. I get some real strange results when I run it in CE. Here is the link if you want to know more.
http://www.autohotkey.com/forum/viewtopic.php?p=206478#206478

Is there any other way you can think of retrieving and rearranging the data?
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Wed Jul 09, 2008 5:57 am    Post subject: Reply with quote

Code:
GuiControlGet,servers,,Edit1,
FileAppend, %servers%, servers.txt


Jay, can you upload the list, servers.txt ?
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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