WWBasic + SPSS,用于重命名值标签的脚本

问题描述 投票:0回答:1

在我开始之前我想指出我将这个问题标记为VBA,因为我实际上无法为Winwrap创建一个新标签,并且我被告知Winwrap与VBA几乎相同。

我正在研究SPSS V19.0,我正在尝试创建一个代码,帮助我识别并为所有在指定变量(或所有变量)中没有标签的值分配值标签。 下面的伪代码是针对单个变量的版本(可能是由文本框输入,也可能是通过SPSS 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

vba spss basic winwrap
1个回答
2
投票

Winwrap和VBA几乎完全相同,你可以在这篇文章中找到差异:http://www.winwrap.com/web/basic/reference/?p=doc_tn0143_technote.htm我没有使用过winwrap,但我会尝试用VBA的知识回答。

  • Dim varLabels As Variant

你可以通过说dim varLabels()作为变量来制作一个数组。动态声明的数组dim varLabels(10)作为变体'静态声明的数组dim varLabels(1到10)作为变体'数组从1开始 - 我是主要使用昏暗的varLabels(1到10,1到3)'多维数组

  • 昏暗的objSpssApp为什么?

“在理论上”,您可以将其作为变体类型,甚至可以

Dim objSpssApp 

没有进一步声明,这基本上是相同的 - 它将起作用,因为变体可以是任何东西,不会产生错误。虽然根据显式数据类型声明对象是很好的定制,因为变体类型在内存方面很昂贵。你应该真正了解对象的类名,但我不能给你这个。我想你应该做的事情如下:

set objSpssApp = new <Spss Window> 
set objSpssApp = nothing 'In the end to release the object 
  • 码: '循环1 对于i = 0到-1 current = GetObject(variable.valuelist(i))'将使用它来获取值 设置varLabels(i)=当前 下一个

我不知道为什么你要从0到-1计数,但也许它是无关紧要的。要填充数组,您可以这样做:varLabels(i)= i SET语句用于设置对象,您无需创建对象来创建数组。另请注意,您没有声明此处使用的一半变量。

  • 码: strVar = InputBox(“请为值插入标签”; varLabels(i);“:”,“插入值标签”)

请注意,串联运算符语法是&。这似乎在WinWrap中是相同的:http://www.winwrap.com/web/basic/language/?p=doc_operators_oper.htm但是你知道这一点,因为你在代码中使用它。

  • 码: 'intCount = intCount + 1'增加计数,使其显示正确的数字 '它不在循环中,因此甚至可以计算填充的值标签 '也许这种方法会更好?

我不确定我是否理解这个问题,但理论上所有循环在任何情况下都是有效的,这取决于你的偏好。对于...接下来,做...循环,而... ...最后,他们都做了基本相同的事情。 intCount = intCount + 1在循环中使用时似乎有效。

  • 使用Next(for ... next)

使用计数器时,请始终使用Next iCounter,因为它会递增计数器。

我希望这个回复可能对你有用!

© www.soinside.com 2019 - 2024. All rights reserved.