Old 17th September 2008, 20:33   #1
max0davis
Junior Member
 
Join Date: Sep 2008
Posts: 8
Question Iterate over all listbox values not just selected

I have an interface where I add IP addresses to a listbox using a textbox and I want to then iterate over all of those IP addresses in the "Leave" function of my page... how do I get each string in a listbox one at a time to do something with it? Here is some code I have so far:

code:

Function VersusConcentratorPage
nsDialogs::Create /NOUNLOAD 1018
Pop $VERSUS_IP_DIALOG
${If} $VERSUS_IP_DIALOG == error
Abort
${EndIf}
${NSD_CreateGroupBox} 0u 0u 150u 140u "Versus Concentrator IP List"
${NSD_CreateListBox} 10u 15u 131u 76u ""
Pop $VERSUS_IP_LISTBOX
${NSD_CreateText} 10u 97u 131u 14u ""
Pop $VERSUS_IP_TEXTBOX
${NSD_CreateButton} 10u 117u 51u 16u "Add Conc IP"
Pop $VERSUS_IP_ADD_BUTTON
${NSD_OnClick} $VERSUS_IP_ADD_BUTTON VersusConcentratorAddIP
${NSD_CreateButton} 70u 117u 71u 16u "Remove Conc IP"
Pop $VERSUS_IP_REM_BUTTON
${NSD_OnClick} $VERSUS_IP_REM_BUTTON VersusConcentratorRemIP
${NSD_CreateGroupBox} 170u 0u 130u 140u "Instructions"
${NSD_CreateLabel} 190u 20u 91u 101u "Enter the IP of each versus conentrator here."
nsDialogs::Show
FunctionEnd

Function VersusConcentratorLeave



FunctionEnd

Function VersusConcentratorAddIP
${NSD_GetText} $VERSUS_IP_TEXTBOX $0
${NSD_LB_AddString} $VERSUS_IP_LISTBOX $0
${NSD_SetText} $VERSUS_IP_TEXTBOX ""
FunctionEnd

Function VersusConcentratorRemIP
${NSD_LB_GetSelection} $VERSUS_IP_LISTBOX $0
${NSD_LB_DelString} $VERSUS_IP_LISTBOX $0
FunctionEnd

max0davis is offline   Reply With Quote
Old 17th September 2008, 20:48   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,449
LB_GETCOUNT and LB_GETTEXT messages, see MSDN for details

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 17th September 2008, 21:07   #3
max0davis
Junior Member
 
Join Date: Sep 2008
Posts: 8
Was looking at this page

Yeah, I was looking at this page:

http://msdn.microsoft.com/en-us/library/bb761313(VS.85).aspx

But I can't quite put it together.

Had something like this:

SendMessage $VERSUS_IP_LISTBOX ${LB_GETTEXT} 0 0 $1
System::Call user32::SendMessage(i$VERSUS_IP_LISTBOX,i${LB_GETTEXT},ir1,t.r1)

But it didn't seem to pull a string value out of the listbox, what am I doing wrong there? Do you see it?

I am not very familiar with the syntax of user32::SendMessage, what does that all mean? Is there a good doc on it?
max0davis is offline   Reply With Quote
Old 17th September 2008, 21:39   #4
max0davis
Junior Member
 
Join Date: Sep 2008
Posts: 8
Tried this:

code:

SendMessage $VERSUS_IP_LISTBOX ${LB_GETCURSEL} 0 0 $0
${IF} $0 >= 0
IntOp $1 $0 + 0;
SendMessage $VERSUS_IP_LISTBOX ${LB_GETTEXT} $1 $0 $2
System::Call user32::SendMessage(i$VERSUS_IP_LISTBOX,i${LB_GETTEXT},i$INDEX,t.$0)
MessageBox MB_OK '0: $0, 1: $1, 2: $2'
${ENDIF}



But I got this warning:

1 warning:
unknown variable/constant "INDEX,t.$0)" detected, ignoring (C:\Documents and Settings\Max Davis\Desktop\setup.nsi:269)

And it doesn't work.

Assuming it is talking about $INDEX not being set... when I set it (Var INDEX) I got this:

1 warning:
Variable "INDEX" not referenced or never set, wasting memory!

And it still didn't work.
max0davis is offline   Reply With Quote
Old 17th September 2008, 22:11   #5
max0davis
Junior Member
 
Join Date: Sep 2008
Posts: 8
I was able to get the first string in the select box with this:

code:

SendMessage $VERSUS_IP_LISTBOX ${LB_GETTEXT} 0 $0
System::Call user32::SendMessage(i$VERSUS_IP_LISTBOX,i${LB_GETTEXT},iR0,t.R0)
MessageBox MB_OK $0



What is a good way to now loop to get all of them?

Can someone give me an example syntax using:
Do[While|Until]..{ExitDo|Continue|Break}..Loop[While|Until]
From logicLib?
max0davis is offline   Reply With Quote
Old 17th September 2008, 22:40   #6
max0davis
Junior Member
 
Join Date: Sep 2008
Posts: 8
This is where I am currently at:

code:

Function VersusConcentratorLeave

${NSD_LB_GetCount} $VERSUS_IP_LISTBOX $R0
IntOp $R1 $R1 & 0

IPLoop:
SendMessage $VERSUS_IP_LISTBOX ${LB_GETTEXT} 0 $0
System::Call user32::SendMessage(i$VERSUS_IP_LISTBOX,i${LB_GETTEXT},iR1,t.R1)
MessageBox MB_OK $0
IntOp $R1 $R1 + 1
StrCmp "$R1" "$R0" 0 End
GOTO IPLoop
End:

FunctionEnd



But it only outputs the last string in the listbox.
max0davis is offline   Reply With Quote
Old 18th September 2008, 12:02   #7
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,449
in that code, the text would be in $R1, not $0. You can remove the non system plugin sendmessage, it is never going to work

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 18th September 2008, 16:06   #8
max0davis
Junior Member
 
Join Date: Sep 2008
Posts: 8
Thumbs up The final working script

This is the final working script to add values to a listbox and then iterate over them in the leave:

code:

Function VersusConcentratorPage
nsDialogs::Create /NOUNLOAD 1018
Pop $VERSUS_IP_DIALOG
${If} $VERSUS_IP_DIALOG == error
Abort
${EndIf}
${NSD_CreateGroupBox} 0u 0u 150u 140u "Versus Concentrator IP List"
${NSD_CreateListBox} 10u 15u 131u 76u ""
Pop $VERSUS_IP_LISTBOX
${NSD_CreateText} 10u 97u 131u 14u ""
Pop $VERSUS_IP_TEXTBOX
${NSD_CreateButton} 10u 117u 51u 16u "Add Conc IP"
Pop $VERSUS_IP_ADD_BUTTON
${NSD_OnClick} $VERSUS_IP_ADD_BUTTON VersusConcentratorAddIP
${NSD_CreateButton} 70u 117u 71u 16u "Remove Conc IP"
Pop $VERSUS_IP_REM_BUTTON
${NSD_OnClick} $VERSUS_IP_REM_BUTTON VersusConcentratorRemIP
${NSD_CreateGroupBox} 170u 0u 130u 140u "Instructions"
${NSD_CreateLabel} 190u 20u 91u 101u "Enter the IP of each versus conentrator here."
nsDialogs::Show
FunctionEnd

Function VersusConcentratorLeave
${NSD_LB_GetCount} $VERSUS_IP_LISTBOX $R3
IntOp $R2 $R2 & 0
Loop:
System::Call user32::SendMessage(i$VERSUS_IP_LISTBOX,i${LB_GETTEXT},iR2,t.R1)
messageBox MB_OK $R1 # DO SOMETHING WITH EACH ONE HERE
IntOp $R2 $R2 + 1
IntCmp $R2 $R3 0 Loop
FunctionEnd

Function VersusConcentratorAddIP
${NSD_GetText} $VERSUS_IP_TEXTBOX $0
${NSD_LB_AddString} $VERSUS_IP_LISTBOX $0
${NSD_SetText} $VERSUS_IP_TEXTBOX ""
FunctionEnd

Function VersusConcentratorRemIP
${NSD_LB_GetSelection} $VERSUS_IP_LISTBOX $0
${NSD_LB_DelString} $VERSUS_IP_LISTBOX $0
FunctionEnd



Anyone is free to reuse this code for their purpose. I used it as a way to collect IP addresses to create config file.
max0davis is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump