How can I use List boxes and Push buttons in a MapViewer script?

Below is an example of how to handle a button press event in a user dialog and how to move a string from one listbox to another.


To run this script:

  1. Copy the text below, from the Dim L1() As String start line to the End Function end line.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\MapViewer 8\Scripter.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines.
  5. Press Ctrl+V to paste your copied script over top of these existing lines.
  6. Click Script | Run to run the script.



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(),.list1
MultiListBox 250,7,130,140,L2(),.list2
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("list1")) ' # strings to move - 1
ReDim L2(cnt)

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

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

dlgF1 = True 'leave dialog open

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

End Select

End Function


Updated January 4, 2019

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Please sign in to leave a comment.