logo

img

Knowledgebase Home | Contact Knowledgebase Home | Contact
Search the Knowledgebase Browse by Category
How can I use List boxes and Push buttons in a script?
User Opinions
0% thumbs up 100% thumbs down

How would you rate this answer?
Helpful
Not helpful
Below is an example of how to handle a button press event in a user dialog and how to move multiple strings from one listbox to another.

Option Explicit

Dim L1() As String 'string array for the first listbox
Dim L2() As String 'string array for the second listbox

Sub Main

' initialize the first listbox strings
ReDim L1(3)
L1(0) = "item 0"
L1(1) = "item 1"
L1(2) = "item 2"
L1(3) = "item 3"

' set up the UserDialog structure
Begin Dialog UserDialog 400,203,"example",.dlgF1 ' %GRID:10,7,1,1
MultiListBox 10,7,130,147,L1(),.mlb1
MultiListBox 250,7,130,140,L2(),.mlb2
PushButton 160,35,70,21,"Add =>",.btnAdd
OKButton 300,175,90,21
End Dialog

' display the dialog
Dim dlg As UserDialog
Dialog dlg

End Sub

' this dialogfunc processes events from the dialog
Function dlgF1(itm$,act%,Val%) As Boolean
Dim i, cnt As Integer

Select Case act%

Case 2 'listbox change or button press
If itm$ = "btnAdd" Then ' Add button pressed
cnt = UBound(DlgValue("mlb1")) ' # strings to move - 1
ReDim L2(cnt)

' move the strings from L1 to L2
For i = 0 To cnt
L2(i) = L1(DlgValue("mlb1")(i))
Next

' update the 2nd listbox
DlgListBoxArray "mlb2",L2

dlgF1 = True 'leave dialog open

ElseIf itm$ = "OK" Then
dlgF1 = False 'close dialog
End If
End Select

End Function

Visitor Comments
No visitor comments posted. Post a comment
Related Questions
Attachments
No attachments were found.
Products