No errors but still shows nothing - Script

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

No errors but still shows nothing - Script

Tom1234
Here's a puzzle for you :)
Winwrap basic, SPSS V19.
The script runs with no errors, only nothing happens.
What's wrong with this code:

'#Language "WWB-COM"
'Imports SPSS
Option Explicit

'Import SPSS classes and functions
Sub Main
'#####################
'Begin Description
'Script to apply value labels via a text box input to each number present in a value list.
'End Description
'#####################

On Error GoTo Bye

'Variable Declaration:
Dim i As Integer, intCount As Integer, current As Integer
Dim strVarName As String, strLabel As String, strCom As String, phr As Boolean
Dim varLabels() As Variant 'This should really be an array of all the value labels in the selected record
Dim varVariables() As Variant, varValues() As Variant 'Variables for variables and values
Dim objDataDoc As ISpssDataDoc
Dim objDocuments As ISpssDocuments
Set objDocuments = objSpssApp.Documents

varVariables = objDataDoc.GetVariables(False)
objDataDoc.GetVariableValueLabels(i, varValues, varLabels)
'I think this is the correct way to access the labels,
'but I'm still unsure as documentation on this scripting language is minimal.

Back: 'Bookmark to jump back to if user wants to restart.
strVarName = InputBox("Please specify the variable you wish to name the values of.","Target Variable")
'Loop for each number in the Value list.
	For i = 0 To UBound(varLabels)
		If IsEmpty (varLabels(i)) Then
			'Find value and ask for the current value label
			strLabel = InputBox("Please insert Label for value "& varLabels(i) &" :","Insert Value Label")
			'Apply the response to the required number
			strCom = "ADD VALUE LABELS " & strVarName & Chr$(39) & intCount & Chr$(39) & Chr$(39) & strLabel & Chr$(39) &" ."
			'Then the piece of code to execute the Syntax
			objSpssApp.ExecuteCommands(strCom, False)

		End If
 	Next i
phr=MsgBox("Would you like to modify the value labels of another variable?",vbYesNo,"Continue?")
If phr = False Then
MsgBox("PLAYER 1 WINS!",vbOkOnly,"VICTORY!")
GoTo Bye
    Else
GoTo Back
End If
Bye:

End Sub

"Lo there do I see my father. Lo there do I see my mother and my sisters and my brothers. Lo there do I see the line of my people, back to the beginning. Lo, they do call to me, they bid me take my place among them, in the Halls of Valhalla, where the brave may live...forever."
Reply | Threaded
Open this post in threaded view
|

Re: No errors but still shows nothing - Script

David Marso
Administrator
"What's wrong with this code:"
Hmmm, where to begin?
You *FIRST* need to locate the index of the desired variable *PRIOR* to calling:
objDataDoc.GetVariableValueLabels(i, varValues, varLabels)
i just happens to be  0 when this is performed!!!

IIRC: varValues will be an array of ONLY labeled values *NOT* all values in the desired variable, so you need to obtain a complete list of all values existing in the data and compare them to the values in the array.

UI??
Asking users to enter a variable name into a box is likely to open up a world of pain!
Perhaps populate a combo box or listbox instead?
Sprinkle some Debug.Print statements around and see for yourself what is what where.
OTOH,  I made some previous comments on this endeavor a while back which I shall not repeat.

----
Tom1234 wrote
Here's a puzzle for you :)
Winwrap basic, SPSS V19.
The script runs with no errors, only nothing happens.
What's wrong with this code:

'#Language "WWB-COM"
'Imports SPSS
Option Explicit

'Import SPSS classes and functions
Sub Main
'#####################
'Begin Description
'Script to apply value labels via a text box input to each number present in a value list.
'End Description
'#####################

On Error GoTo Bye

'Variable Declaration:
Dim i As Integer, intCount As Integer, current As Integer
Dim strVarName As String, strLabel As String, strCom As String, phr As Boolean
Dim varLabels() As Variant 'This should really be an array of all the value labels in the selected record
Dim varVariables() As Variant, varValues() As Variant 'Variables for variables and values
Dim objDataDoc As ISpssDataDoc
Dim objDocuments As ISpssDocuments
Set objDocuments = objSpssApp.Documents

varVariables = objDataDoc.GetVariables(False)
objDataDoc.GetVariableValueLabels(i, varValues, varLabels)
'I think this is the correct way to access the labels,
'but I'm still unsure as documentation on this scripting language is minimal.

Back: 'Bookmark to jump back to if user wants to restart.
strVarName = InputBox("Please specify the variable you wish to name the values of.","Target Variable")
'Loop for each number in the Value list.
	For i = 0 To UBound(varLabels)
		If IsEmpty (varLabels(i)) Then
			'Find value and ask for the current value label
			strLabel = InputBox("Please insert Label for value "& varLabels(i) &" :","Insert Value Label")
			'Apply the response to the required number
			strCom = "ADD VALUE LABELS " & strVarName & Chr$(39) & intCount & Chr$(39) & Chr$(39) & strLabel & Chr$(39) &" ."
			'Then the piece of code to execute the Syntax
			objSpssApp.ExecuteCommands(strCom, False)

		End If
 	Next i
phr=MsgBox("Would you like to modify the value labels of another variable?",vbYesNo,"Continue?")
If phr = False Then
MsgBox("PLAYER 1 WINS!",vbOkOnly,"VICTORY!")
GoTo Bye
    Else
GoTo Back
End If
Bye:

End Sub
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: No errors but still shows nothing - Script

Tom1234
This post was updated on .
Wow you use some very confusing acronyms! IIRC ? OTOH? as well as some very interesting highlighting techniques haha.
I know you previously stated some things but really, this is just to test the capabilities and functions within the SPSS scripting facility, I wanted to see how much I could get away with before it started to be a problem ha!

"Lo there do I see my father. Lo there do I see my mother and my sisters and my brothers. Lo there do I see the line of my people, back to the beginning. Lo, they do call to me, they bid me take my place among them, in the Halls of Valhalla, where the brave may live...forever."
Reply | Threaded
Open this post in threaded view
|

Re: No errors but still shows nothing - Script

David Marso
Administrator
IIRC : If I recall correctly.
OTOH: On the other hand.
***I HATE HTML MARKUP TAG CRAP***

Tom1234 wrote
Wow you use some very confusing acronyms! IIRC ? OTOH? as well as some very interesting highlighting techniques haha.
I know you previously stated some things but really, this is just to test the capabilities and functions within the SPSS scripting facility, I wanted to see how much I could get away with before it started to be a problem ha!
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Automatic reply: No errors but still shows nothing - Script

Tierney, Mary Lou

I am PTOB today, Friday 20 July.

 

For assistance with the MITRE Innovation Program please contact the [hidden email]

 

For assistance with Project/Portfolio Pages or Discover, please contact the [hidden email]

 

For assistance with other Innovation Zone sites, such as CI&T InZone, please contact [hidden email].

 

 

Regards,

Mary Lou

Reply | Threaded
Open this post in threaded view
|

Re: No errors but still shows nothing - Script

David Marso
Administrator
In reply to this post by Tom1234
You didn't bother to state whether my advice was a sufficient tap of the clue stick:
Adapt the UI since this is SAX basic .
Sub Main
Dim varnames() As String
Dim VarValues As Variant
Dim VarLabels As Variant
Dim VarIndex As Long
Dim I As Long
        varnames=objSpssApp.Documents.GetDataDoc(0).GetVariables (False)
        Begin Dialog UserDialog 240,91 ' %GRID:10,7,1,1
                OKButton 190,0,40,21
                ListBox 10,0,170,91,varnames(),.ListBox1
        End Dialog
        Dim dlg As UserDialog
        Dialog dlg
VarIndex=dlg.ListBox1
objSpssApp.Documents.GetDataDoc(0).GetVariableValueLabels VarIndex,VarValues,VarLabels
For I=0 To UBound(VarValues)
Debug.Print VarValues(I) & " " & VarLabels(I)
Next
End Sub
Tom1234 wrote
Wow you use some very confusing acronyms! IIRC ? OTOH? as well as some very interesting highlighting techniques haha.
I know you previously stated some things but really, this is just to test the capabilities and functions within the SPSS scripting facility, I wanted to see how much I could get away with before it started to be a problem ha!
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"