Macro (SVB) Programs Example - Creating and Customizing Box-Plots

This program illustrates how to create customized Box Plots.

'This program creates box plots 
'it allows user to select variables 
'box plot can be based on mean or median 
'additionally we allow user to scale it to arbitrary scale 
Public nv As Long Public myvars(1 To 10) As Long 
Public nonpar As Boolean 
Public commonscale As Boolean 
Public maxvalue As Double 
'Function stats show dialog allowing to select appropriate statistics and options 
Function stats As Boolean 
On Error 
GoTo finishBegin Dialog UserDialog 290,175,"Select Box Plot Type" ' %GRID:10,7,1,1 
GroupBox 20,14,250,63,"Box Plot type",.GroupBox1 
OptionGroup .Group1 
OptionButton 40,35,170,14,"Median",.OptionButton1 
OptionButton 40,56,170,14,"Mean, SD and SE",.OptionButton2 
CheckBox 20,91,230,14,"Set common Y axis scale",.scale 
OKButton 30,147,100,21 
CancelButton 160,147,110,21 
Text 50,116,120,14,"Maximum Y Value:",.Text1 
TextBox 180,112,80,21,.MaxValue 
End Dialog
Dim dlg As UserDialog 
dlg.scale = commonscale 
dlg.MaxValue = "20" Dialog dlg
commonscale = dlg.scale 
maxvalue = CDbl(dlg.MaxValue) 

If dlg.group1 = 0 Thennonpar = True
Else
nonpar = False
End If 
stats = True 
Exit 
Functionfinish:stats = False
End Function 
'Function UI handles user interface for the program 
'First it allows for selection of variables and then 
'user selects statistics to be displayed in a box plot Function UI As Boolean
nv = 0 
ret = Select
Variables1 (ActiveDataSet, _ "Variables for Box Plot", 1, 3, myvars, nv, "Variables:")
If ret And nv > 0 
Thenmyvars(nv+1) = 0 
commonscale = True 
UI = statsElseUI = False
End If
End Function 
'BoxPlot creates BoxPlots based on user selections 
Sub BoxPlotSet newanalysis = Analysis (sc2dBoxPlots)
With newanalysis.Dialog.DependentVariable = myvars 
.GraphType = scBox2DBoxWhiskers 
.BoxMode = scBoxRegularMode 
.MiddlePointStyle = scBoxMidPoint 
If nonpar 
Then
.MiddlePointValue = scBoxMidPointMedian 
.MedianBoxValue = scMedianBoxPercentiles 
.BoxCoefficient(scBoxMidPointMedian) = 25.000000 
.WhiskerCoefficient(scBoxMidPointMedian) = 1.000000 
.MedianWhiskerValue = scMedianWhiskerNonOutlierRange
Else
.MiddlePointValue = scBoxMidPointMean 
.MiddlePointStyle = scBoxMidPoint 
.BoxCoefficient(scBoxMidPointMean) = 1.000000 
.WhiskerCoefficient(scBoxMidPointMean) = 1.000000
End If 
.OutLiers = scBoxOutlierAndExtremes 
.OutLiersCoefficient = 1.500000 
.DisplayFTestAndP = False 
.DisplayKruskalWallisTest = False
End 
WithT$ = "Graph created: " + Str$(Now()) 
Set results = newanalysis.Dialog.Graphs 
Dim g As Graph Dim ax As Axis2D 
For Each g 
In resultsg.Titles.Item(scgMainTitle) = T$ 
If commonscale Then
Set ax = g.Content.Axes(scgLeftY)
If maxvalue > 0 Then
ax.SetManualRange(0,maxvalue)
Else
MsgBox _ "The specified maximum Y-axis value is less than the Y-axis" & _ vbCrLf & _ "minimum value; 
20 will be used as the max value"ax.SetManualRange(0,20)
End If
ax.RangeMode = scgManualRange 
Set ax = NothingEnd 
If g.GraphWindow.Background.Color = RGB(255,255,255) g.Visible = True
Next
End Sub 
Sub Main
If UI Then BoxPlot 
End If
End Sub