1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'Begin Description
'This script illustrates how to use a list box to display SPSS variables.
'It simply displays the selected variable in a message box when finished.
'End Description

Option Explicit

Sub Main
	'First get the variable list; it's a property of the Info object.
	Dim objInfo As ISpssInfo
	
	'we'll store the variable names in this array
	Dim strVariables() As String
	'we'll need to know how many variables there are
	Dim intNumVariables As Integer
	'loop control index
	Dim i As Integer
	'and we'll make things nice by displaying the name of the data file
	Dim strFilePath As String
	
	Set objInfo = objSpssApp.SpssInfo
	'the variables are indexed by 0 to .NumVariables - 1
	intNumVariables = objInfo.NumVariables
	
	If intNumVariables > 0 Then
		'set aside enough storage for the array
		ReDim strVariables(intNumVariables - 1)
		
		'read in the variable names
		For i = 0 To intNumVariables - 1
			'if we preferred, we could work with labels instead, or both
			strVariables(i) = objInfo.VariableAt(i)
			'strVariables(i) = objInfo.VariableLabelAt(i)
			'strVariables(i) = objInfo.VariableAt(i) & ": " & objInfo.VariableLabelAt(i)
		Next 
	Else
		ReDim strVariables(0)
		strVariables(0) = "(No Data)"
	End If
	
	'the path to the file
	strFilePath = objSpssApp.Documents.GetDataDoc(0).GetDocumentPath
	'if the file hasn't been saved
	If strFilePath = "" Then
		strFilePath = "(Untitled)"
	End If
	
	'Define and put up the dialog.
	
	'To edit the dialog: position the cursor between Begin Dialog and 
	'End Dialog, then activate the Dialog Editor.
	'Note that the dialog editor created a template with ListArray()
	'as the ListBox parameter; it's been replaced by strVariables.
	Begin Dialog UserDialog 400,203
		OKButton 280,175,100,21
		GroupBox 10,7,380,154,strFilePath,.GroupBox1
		ListBox 20,21,360,140,strVariables(),.ListBox1
	End Dialog
	
	Dim dlg As UserDialog

	'We'll set the default choice to be item 0
	dlg.ListBox1 = 0
	
	'this actually puts up the dialog.	
	Dialog dlg
	
	'display the user selection: the index is returned in dlg.ListBox1
	MsgBox "The variable selected was """ & strVariables(dlg.ListBox1) & """", _
		vbInformation, "Variable List Demo"
	'note: to include " in a quoted string, we need to type it twice
End Sub