How to copy table structure in STATISTICA ?

#1
Hi guys!

I'm interested in copying table structure of STATISTICA spreadsheet.
One way to do this is using some kind of copy&paste method "Copy with Headers". Is there any direct way to create empty spreadsheet with the same structure in Statistica Basic ? Spreadsheet.CopyVariables does copying within a specific table only.


Konstantin.
 

JenB

New Member
#2
Try this...


Option Base 1

Sub Main

Dim s1 As Spreadsheet
Dim s2 As Spreadsheet
Dim i As Long

Set s1 = ActiveSpreadsheet
Set s2 = Spreadsheets.New
s2.SetSize(s1.NumberOfCases, s1.NumberOfVariables)
s2.Visible = True

For i = 1 To s1.NumberOfVariables
s2.VariableName(i) = s1.VariableName(i)
s2.VariableType(i) = s1.VariableType(i)
If s1.VariableType(i)=scText Then
s2.VariableTypeLength(i) = s1.VariableTypeLength(i)
End if
s2.Variable(i).AutoFit​
Next i​

End Sub
 
Last edited:
#3
Thanks with refinements

Try this...


Option Base 1

Sub Main

Dim s1 As Spreadsheet
Dim s2 As Spreadsheet
Dim i As Long

Set s1 = ActiveSpreadsheet
Set s2 = Spreadsheets.New
s2.SetSize(s1.NumberOfCases, s1.NumberOfVariables)
s2.Visible = True

For i = 1 To s1.NumberOfVariables
s2.VariableName(i) = s1.VariableName(i)
s2.VariableType(i) = s1.VariableType(i)
If s1.VariableType(i)=scText Then
s2.VariableTypeLength(i) = s1.VariableTypeLength(i)
End if
s2.Variable(i).AutoFit​
Next i​

End Sub
Thank you Jen. To make S2 look not ugly one should add

For i = 1 To S2.Numberofvariables

S2.VariableHeaders(i).AutoFit

Next i

I think there are other details with this :)
 
#4
Here is the code

Dim jndex As Integer


For jndex = 1 To Source.NumberOfVariables
Target.VariableName(jndex) = Source.VariableName(jndex)
Target.VariableType(jndex) = Source.VariableType(jndex)
If Source.VariableType(jndex)=scText Then
Target.VariableTypeLength(jndex) = Source.VariableTypeLength(jndex)
End If
Target.VariableFormatString(jndex) = Source.VariableFormatString(jndex)
Target.Variable(jndex).AutoFit
Target.VariableHeaders(jndex).AutoFit

Dim Vals() As Double, Labels() As String, Descr() As String
Source.VariableTextLabels(jndex,Vals(),Labels(),Descr())
ReDim Preserve Vals(Source.NumberOfTextLabels(jndex))
ReDim Preserve Labels(Source.NumberOfTextLabels(jndex))
ReDim Preserve Descr(Source.NumberOfTextLabels(jndex))


For kndex=0 To Source.NumberOfTextLabels(jndex)-1
Target.SetTextLabel(jndex,Vals(kndex),Labels(kndex),Descr(kndex))
Next kndex

Target.Variable(jndex).ColumnWidth=Source.Variable(jndex).ColumnWidth
Next jndex