Dear List.
The script below is suppose to accept the data file name from the user and then run the syntax " C:\Temp\ctable.sps". I get this error message when I run my script. >Error # 34. Command name: GET FILE >SPSS cannot access a file with the given file specification. The file >specification is either syntactically invalid, specifies an invalid drive, >specifies a protected directory, specifies a protected file, or specifies a >non-sharable file. >This command not executed. I guess the problem is with the script command line : PathStr= "DEFINE !Path() 'Q:\Temp\Data\'"& strFname & "!ENDDEFINE." & vbCr objSpssApp.ExecuteCommands PathStr,True and the Syntax command line : GET FILE =!Path. Below is the script and syntax . Any suggestions will be very much appreciated. ******SECTION 1 Script ********* Option Explicit Sub Main() Dim objSyntaxDoc As ISpssSyntaxDoc Dim strFname As String Dim CmdStr As String Dim PathStr As String On Error GoTo ErrorDesc strFname = InputBox$("Enter File Name") PathStr= "DEFINE !Path() 'Q:\Temp\Data\'"& strFname & "!ENDDEFINE." & vbCr objSpssApp.ExecuteCommands PathStr,True 'Open syntax file and run it Set objSyntaxDoc = objSpssApp.OpenSyntaxDoc ("C:\Temp\ctable.sps") objSyntaxDoc.Visible=True objSyntaxDoc.Run objSyntaxDoc.Close Set objSyntaxDoc = Nothing Exit Sub ErrorDesc: MsgBox "Following error occured: " & Err.Description End Sub *******SETION 2 C:\Temp\ctable.sps ********* GET FILE =!Path. * Custom Tables. CTABLES /VLABELS VARIABLES=Var1 DISPLAY=DEFAULT /TABLE Var1 [COUNT F40.0] /CATEGORIES VARIABLES=Var1 ORDER=A KEY=VALUE EMPTY=EXCLUDE TOTAL=YES POSITION=AFTER. |
That is a great script. I use it with all my rutine reports (Thanks
Raynald). Here is how I use it. ================= Sub Main() Dim strCmd As String Dim strFPath As String strFPath =GetFilePath( ,"txt" , "G:\temp\" ,"Select file ", 0) If strFPath = "" Then Exit Sub 'User clicked Cancel strCmd="DEFINE !path()FILE='" & strFPath & "'!ENDDEFINE" Debug.Print strCmd objSpssApp.ExecuteCommands strCmd, False Dim objSyntaxDoc As ISpssSyntaxDoc On Error GoTo Oopps 'Open syntax file and run it Set objSyntaxDoc = objSpssApp.OpenSyntaxDoc ("G:\temp\filename.sps") objSyntaxDoc.Visible=True objSyntaxDoc.Run objSyntaxDoc.Close Set objSyntaxDoc = Nothing Exit Sub Oopps: MsgBox "Following error occured: " & Err.Description End Sub -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Edward Boadi Sent: Wednesday, August 30, 2006 9:38 AM To: [hidden email] Subject: My First SPSS Script Dear List. The script below is suppose to accept the data file name from the user and then run the syntax " C:\Temp\ctable.sps". I get this error message when I run my script. >Error # 34. Command name: GET FILE >SPSS cannot access a file with the given file specification. The file >specification is either syntactically invalid, specifies an invalid drive, >specifies a protected directory, specifies a protected file, or specifies a >non-sharable file. >This command not executed. I guess the problem is with the script command line : PathStr= "DEFINE !Path() 'Q:\Temp\Data\'"& strFname & "!ENDDEFINE." & vbCr objSpssApp.ExecuteCommands PathStr,True and the Syntax command line : GET FILE =!Path. Below is the script and syntax . Any suggestions will be very much appreciated. ******SECTION 1 Script ********* Option Explicit Sub Main() Dim objSyntaxDoc As ISpssSyntaxDoc Dim strFname As String Dim CmdStr As String Dim PathStr As String On Error GoTo ErrorDesc strFname = InputBox$("Enter File Name") PathStr= "DEFINE !Path() 'Q:\Temp\Data\'"& strFname & "!ENDDEFINE." & vbCr objSpssApp.ExecuteCommands PathStr,True 'Open syntax file and run it Set objSyntaxDoc = objSpssApp.OpenSyntaxDoc ("C:\Temp\ctable.sps") objSyntaxDoc.Visible=True objSyntaxDoc.Run objSyntaxDoc.Close Set objSyntaxDoc = Nothing Exit Sub ErrorDesc: MsgBox "Following error occured: " & Err.Description End Sub *******SETION 2 C:\Temp\ctable.sps ********* GET FILE =!Path. * Custom Tables. CTABLES /VLABELS VARIABLES=Var1 DISPLAY=DEFAULT /TABLE Var1 [COUNT F40.0] /CATEGORIES VARIABLES=Var1 ORDER=A KEY=VALUE EMPTY=EXCLUDE TOTAL=YES POSITION=AFTER. |
In reply to this post by Edward Boadi
Thanks Egon for your response.
The command : 1. strFPath =GetFilePath( ,"sav" , "c:\temp\" ,"Select file ", 0) ----- Gives the option to select my data file . 2. strCmd="DEFINE !path()FILE='" & strFPath & "'!ENDDEFINE" ----- Creates Path = 'c:\Temp\Selected data file.sav' So GET FILE = !Path is equivalent to GET FILE = 'c:\Temp\Selected data file.sav' But when I invoke GET FILE = !Path , I get an error message ----File not found. What could be wrong ? -----Original Message----- From: Egon Kraan [mailto:[hidden email]] Sent: Wednesday, August 30, 2006 11:20 AM To: Edward Boadi; [hidden email] Subject: RE: My First SPSS Script That is a great script. I use it with all my rutine reports (Thanks Raynald). Here is how I use it. ================= Sub Main() Dim strCmd As String Dim strFPath As String strFPath =GetFilePath( ,"txt" , "G:\temp\" ,"Select file ", 0) If strFPath = "" Then Exit Sub 'User clicked Cancel strCmd="DEFINE !path()FILE='" & strFPath & "'!ENDDEFINE" Debug.Print strCmd objSpssApp.ExecuteCommands strCmd, False Dim objSyntaxDoc As ISpssSyntaxDoc On Error GoTo Oopps 'Open syntax file and run it Set objSyntaxDoc = objSpssApp.OpenSyntaxDoc ("G:\temp\filename.sps") objSyntaxDoc.Visible=True objSyntaxDoc.Run objSyntaxDoc.Close Set objSyntaxDoc = Nothing Exit Sub Oopps: MsgBox "Following error occured: " & Err.Description End Sub -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Edward Boadi Sent: Wednesday, August 30, 2006 9:38 AM To: [hidden email] Subject: My First SPSS Script Dear List. The script below is suppose to accept the data file name from the user and then run the syntax " C:\Temp\ctable.sps". I get this error message when I run my script. >Error # 34. Command name: GET FILE >SPSS cannot access a file with the given file specification. The file >specification is either syntactically invalid, specifies an invalid drive, >specifies a protected directory, specifies a protected file, or specifies a >non-sharable file. >This command not executed. I guess the problem is with the script command line : PathStr= "DEFINE !Path() 'Q:\Temp\Data\'"& strFname & "!ENDDEFINE." & vbCr objSpssApp.ExecuteCommands PathStr,True and the Syntax command line : GET FILE =!Path. Below is the script and syntax . Any suggestions will be very much appreciated. ******SECTION 1 Script ********* Option Explicit Sub Main() Dim objSyntaxDoc As ISpssSyntaxDoc Dim strFname As String Dim CmdStr As String Dim PathStr As String On Error GoTo ErrorDesc strFname = InputBox$("Enter File Name") PathStr= "DEFINE !Path() 'Q:\Temp\Data\'"& strFname & "!ENDDEFINE." & vbCr objSpssApp.ExecuteCommands PathStr,True 'Open syntax file and run it Set objSyntaxDoc = objSpssApp.OpenSyntaxDoc ("C:\Temp\ctable.sps") objSyntaxDoc.Visible=True objSyntaxDoc.Run objSyntaxDoc.Close Set objSyntaxDoc = Nothing Exit Sub ErrorDesc: MsgBox "Following error occured: " & Err.Description End Sub *******SETION 2 C:\Temp\ctable.sps ********* GET FILE =!Path. * Custom Tables. CTABLES /VLABELS VARIABLES=Var1 DISPLAY=DEFAULT /TABLE Var1 [COUNT F40.0] /CATEGORIES VARIABLES=Var1 ORDER=A KEY=VALUE EMPTY=EXCLUDE TOTAL=YES POSITION=AFTER. |
In reply to this post by Edward Boadi
It seems the problem is how you are invoking the macro.
when your syntax calls for GET FILE = !path it is actually calling for GET FILE = FILE = 'c:\temp\selected data file.sav' Because the define statement is including FILE= into the definition of !path So try instead GET !path Or change the line strCmd="DEFINE !path()FILE='" & strFPath & "'!ENDDEFINE" to strCmd="DEFINE !path()'" & strFPath & "'!ENDDEFINE" Let me know if it works -----Original Message----- From: Edward Boadi [mailto:[hidden email]] Sent: Wednesday, August 30, 2006 12:14 PM To: Egon Kraan; [hidden email] Subject: RE: My First SPSS Script Thanks Egon for your response. The command : 1. strFPath =GetFilePath( ,"sav" , "c:\temp\" ,"Select file ", 0) ----- Gives the option to select my data file . 2. strCmd="DEFINE !path()FILE='" & strFPath & "'!ENDDEFINE" ----- Creates Path = 'c:\Temp\Selected data file.sav' So GET FILE = !Path is equivalent to GET FILE = 'c:\Temp\Selected data file.sav' But when I invoke GET FILE = !Path , I get an error message ----File not found. What could be wrong ? -----Original Message----- From: Egon Kraan [mailto:[hidden email]] Sent: Wednesday, August 30, 2006 11:20 AM To: Edward Boadi; [hidden email] Subject: RE: My First SPSS Script That is a great script. I use it with all my rutine reports (Thanks Raynald). Here is how I use it. ================= Sub Main() Dim strCmd As String Dim strFPath As String strFPath =GetFilePath( ,"txt" , "G:\temp\" ,"Select file ", 0) If strFPath = "" Then Exit Sub 'User clicked Cancel strCmd="DEFINE !path()FILE='" & strFPath & "'!ENDDEFINE" Debug.Print strCmd objSpssApp.ExecuteCommands strCmd, False Dim objSyntaxDoc As ISpssSyntaxDoc On Error GoTo Oopps 'Open syntax file and run it Set objSyntaxDoc = objSpssApp.OpenSyntaxDoc ("G:\temp\filename.sps") objSyntaxDoc.Visible=True objSyntaxDoc.Run objSyntaxDoc.Close Set objSyntaxDoc = Nothing Exit Sub Oopps: MsgBox "Following error occured: " & Err.Description End Sub -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Edward Boadi Sent: Wednesday, August 30, 2006 9:38 AM To: [hidden email] Subject: My First SPSS Script Dear List. The script below is suppose to accept the data file name from the user and then run the syntax " C:\Temp\ctable.sps". I get this error message when I run my script. >Error # 34. Command name: GET FILE >SPSS cannot access a file with the given file specification. The file >specification is either syntactically invalid, specifies an invalid drive, >specifies a protected directory, specifies a protected file, or specifies a >non-sharable file. >This command not executed. I guess the problem is with the script command line : PathStr= "DEFINE !Path() 'Q:\Temp\Data\'"& strFname & "!ENDDEFINE." & vbCr objSpssApp.ExecuteCommands PathStr,True and the Syntax command line : GET FILE =!Path. Below is the script and syntax . Any suggestions will be very much appreciated. ******SECTION 1 Script ********* Option Explicit Sub Main() Dim objSyntaxDoc As ISpssSyntaxDoc Dim strFname As String Dim CmdStr As String Dim PathStr As String On Error GoTo ErrorDesc strFname = InputBox$("Enter File Name") PathStr= "DEFINE !Path() 'Q:\Temp\Data\'"& strFname & "!ENDDEFINE." & vbCr objSpssApp.ExecuteCommands PathStr,True 'Open syntax file and run it Set objSyntaxDoc = objSpssApp.OpenSyntaxDoc ("C:\Temp\ctable.sps") objSyntaxDoc.Visible=True objSyntaxDoc.Run objSyntaxDoc.Close Set objSyntaxDoc = Nothing Exit Sub ErrorDesc: MsgBox "Following error occured: " & Err.Description End Sub *******SETION 2 C:\Temp\ctable.sps ********* GET FILE =!Path. * Custom Tables. CTABLES /VLABELS VARIABLES=Var1 DISPLAY=DEFAULT /TABLE Var1 [COUNT F40.0] /CATEGORIES VARIABLES=Var1 ORDER=A KEY=VALUE EMPTY=EXCLUDE TOTAL=YES POSITION=AFTER. |
In reply to this post by Edward Boadi
Works great , thanks a MILLION Egon.
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Egon Kraan Sent: Wednesday, August 30, 2006 12:25 PM To: [hidden email] Subject: Re: My First SPSS Script It seems the problem is how you are invoking the macro. when your syntax calls for GET FILE = !path it is actually calling for GET FILE = FILE = 'c:\temp\selected data file.sav' Because the define statement is including FILE= into the definition of !path So try instead GET !path Or change the line strCmd="DEFINE !path()FILE='" & strFPath & "'!ENDDEFINE" to strCmd="DEFINE !path()'" & strFPath & "'!ENDDEFINE" Let me know if it works -----Original Message----- From: Edward Boadi [mailto:[hidden email]] Sent: Wednesday, August 30, 2006 12:14 PM To: Egon Kraan; [hidden email] Subject: RE: My First SPSS Script Thanks Egon for your response. The command : 1. strFPath =GetFilePath( ,"sav" , "c:\temp\" ,"Select file ", 0) ----- Gives the option to select my data file . 2. strCmd="DEFINE !path()FILE='" & strFPath & "'!ENDDEFINE" ----- Creates Path = 'c:\Temp\Selected data file.sav' So GET FILE = !Path is equivalent to GET FILE = 'c:\Temp\Selected data file.sav' But when I invoke GET FILE = !Path , I get an error message ----File not found. What could be wrong ? -----Original Message----- From: Egon Kraan [mailto:[hidden email]] Sent: Wednesday, August 30, 2006 11:20 AM To: Edward Boadi; [hidden email] Subject: RE: My First SPSS Script That is a great script. I use it with all my rutine reports (Thanks Raynald). Here is how I use it. ================= Sub Main() Dim strCmd As String Dim strFPath As String strFPath =GetFilePath( ,"txt" , "G:\temp\" ,"Select file ", 0) If strFPath = "" Then Exit Sub 'User clicked Cancel strCmd="DEFINE !path()FILE='" & strFPath & "'!ENDDEFINE" Debug.Print strCmd objSpssApp.ExecuteCommands strCmd, False Dim objSyntaxDoc As ISpssSyntaxDoc On Error GoTo Oopps 'Open syntax file and run it Set objSyntaxDoc = objSpssApp.OpenSyntaxDoc ("G:\temp\filename.sps") objSyntaxDoc.Visible=True objSyntaxDoc.Run objSyntaxDoc.Close Set objSyntaxDoc = Nothing Exit Sub Oopps: MsgBox "Following error occured: " & Err.Description End Sub -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Edward Boadi Sent: Wednesday, August 30, 2006 9:38 AM To: [hidden email] Subject: My First SPSS Script Dear List. The script below is suppose to accept the data file name from the user and then run the syntax " C:\Temp\ctable.sps". I get this error message when I run my script. >Error # 34. Command name: GET FILE >SPSS cannot access a file with the given file specification. The file >specification is either syntactically invalid, specifies an invalid drive, >specifies a protected directory, specifies a protected file, or specifies a >non-sharable file. >This command not executed. I guess the problem is with the script command line : PathStr= "DEFINE !Path() 'Q:\Temp\Data\'"& strFname & "!ENDDEFINE." & vbCr objSpssApp.ExecuteCommands PathStr,True and the Syntax command line : GET FILE =!Path. Below is the script and syntax . Any suggestions will be very much appreciated. ******SECTION 1 Script ********* Option Explicit Sub Main() Dim objSyntaxDoc As ISpssSyntaxDoc Dim strFname As String Dim CmdStr As String Dim PathStr As String On Error GoTo ErrorDesc strFname = InputBox$("Enter File Name") PathStr= "DEFINE !Path() 'Q:\Temp\Data\'"& strFname & "!ENDDEFINE." & vbCr objSpssApp.ExecuteCommands PathStr,True 'Open syntax file and run it Set objSyntaxDoc = objSpssApp.OpenSyntaxDoc ("C:\Temp\ctable.sps") objSyntaxDoc.Visible=True objSyntaxDoc.Run objSyntaxDoc.Close Set objSyntaxDoc = Nothing Exit Sub ErrorDesc: MsgBox "Following error occured: " & Err.Description End Sub *******SETION 2 C:\Temp\ctable.sps ********* GET FILE =!Path. * Custom Tables. CTABLES /VLABELS VARIABLES=Var1 DISPLAY=DEFAULT /TABLE Var1 [COUNT F40.0] /CATEGORIES VARIABLES=Var1 ORDER=A KEY=VALUE EMPTY=EXCLUDE TOTAL=YES POSITION=AFTER. |
Free forum by Nabble | Edit this page |