在开始之前,我想指出的是,我将这个问题标记为VBA,因为我实际上不能为Winwrap做一个新的标记,并且我被告知Winwrap与VBA几乎是一样的。
我正在研究SPSSV19.0,我正在尝试做一个代码来帮助我识别和分配所有在指定变量(或所有变量)中没有标签的值标签。
下面的伪代码用于这个版本,它是一个变量(可能是由文本框输入的,也可能是通过Stats程序中的自定义对话发送的(从语法调用.sbs文件,给出变量名)。
以下是伪代码:
Sub Main(variable As String)
On Error GoTo bye
'Variable Declaration:
Dim i As Integer, intCount As Integer
Dim strValName As String, strVar As String, strCom As String
Dim varLabels As Variant 'This should be an array of all the value labels in the selected record
Dim objSpssApp As 'No idea what to put here, but I want to select the spss main window.
'Original Idea was to use two loops
'The first loop would fill an array with the value lables and use the index as the value and
'The second loop would check to see which values already had labels and then
'Would ask the user for a value label to apply to each value that didn't.
'loop 1
'For i = 0 To -1
'current = GetObject(variable.valuelist(i)) 'would use this to get the value
'Set varLabels(i) = current
'Next
'Loop for each number in the Value list.
strValName = InputBox("Please specify the variable.")
'Loop for each number in the Value list.
For i = 0 To varLabels-1
If IsEmpty (varLabels(i)) Then
'Find value and ask for the current value label
strVar = InputBox("Please insert Label for value "; varLabels(i);" :","Insert Value Label")
'Apply the response to the required number
strCom = "ADD VALUE LABELS " & strVar & Chr$(39) & intCount & Chr$(39) & Chr$(39) & strValName & Chr$(39) &" ."
'Then the piece of code to execute the Syntax
objSpssApp.ExecuteCommands(strCom, False)
End If
'intCount = intCount + 1 'increase the count so that it shows the correct number
'it's out of the loop so that even filled value labels are counted
'Perhaps this method would be better?
Next
Bye:
End Sub这根本不是有效的代码,它基本上是我想要实现的过程的伪代码--我只是在寻求一些帮助,如果可以的话,这将是神奇的。
事先非常感谢
Mav
发布于 2012-06-28 09:54:05
with和VBA几乎与您在这篇文章中可以找到的不同之处相同:technote.htm我还没有使用with,但我将尝试用我从VBA获得的知识来回答。
您可以通过这样的方式创建一个数组,例如,把dim varLabels()说成变体‘动态声明的数组varLabels(10)为变体’静态声明的数组dim varLabels(1至10)为变体‘varLabels(1至10)从1开始--我主要使用dim varLabels(1到10,1到3)多维数组
“理论上”,您可以将其保留为变体类型,甚至可以这样做。
Dim objSpssApp 没有进一步的声明,这基本上是相同的-它将工作,因为变体可以是任何东西,不会产生错误。但是,根据显式数据类型声明对象是很好的习惯,因为变体类型在内存方面很昂贵。实际上,您应该知道对象的类名,但我不能给您这个。我想你应该这样做:
set objSpssApp = new <Spss Window>
set objSpssApp = nothing 'In the end to release the object 我不知道你为什么要从0数到-1,但也许这是不相关的。要填充数组,只需这样做: varLabels(i) =i-- SET语句用于设置对象,而不需要创建对象来创建数组。还请注意,您没有声明这里使用的变量的一半。
注意,级联操作符语法是&。这在WinWrap:oper.htm中似乎是一样的,但是您知道这一点,因为您在代码中使用了它。
我不确定我是否理解这个问题,但理论上,所有循环在任何情况下都是有效的,这取决于您的偏好。为了..。接下来,做..。循环,而.最后,他们做的事情基本上是一样的。在循环中使用intCount = intCount +1似乎是有效的。
使用计数器时,始终使用Next iCounter,因为它会增加计数器。
我希望这个答复能对你有所帮助!
https://stackoverflow.com/questions/11241361
复制相似问题