Graphic 3 for SigmaPlot

Keywords: Buy SigmaPlot - Purchase SigmaPlot - Buy SigmaStat - Purchase SigmaStat - Buy Sigma Plot - Purchase Sigma Plot - Buy Sigma Stat - Purchase Sigma Stat

Adding a For-Loop to Your Macro

You certainly can repeat recording one curve fit after another to create a macro that performs multiple curve fits but this restricts you to using this macro on exactly that number of curve fits and produces lots of repetitive macro code. A better procedure is to modify your macro code by placing a for-loop around the macro code recorded for the first curve fit. To do this open your macro for editing by selecting Tools, Macro, Macros..., Exponential Fit, Edit. The macro edit window is displayed. Expand the window vertically as much as possible and scroll down through the code. Near the beginning of the macro you will see

Sub Main
ActiveDocument.CurrentPageItem.Select(False, -1688, 1521, -1688, 1521)
ActiveDocument.CurrentPageItem.Select(False, -1688, 1521, -1688, 1521)

This is the beginning of the main subroutine and the first two "Select" statements that correspond to your right click on the graph data point that was the first recorded operation in your macro. The numbers in this statement refer to the position on the graph page where you clicked. Scroll down about 35 more lines to

Set FitFile = Nothing
ActiveDocument.CurrentPageItem.Select(False, -1667, 958, -1667, 958)
ActiveDocument.CurrentPageItem.Select(False, -1667, 958, -1667, 958)

The Set FitFile = Nothing statement is the last statement of the first recorded curve fit. The two "Select" statements are the start of the second curve fit (the right click on the data point for the second data set). 

We are going to 1) delete all the statements recorded for the second curve fit, 2) place a for-loop around the first set of curve fit statements and 3) modify one line in the curve fit code to select a different y data column each time through the for-loop. To delete the statements for the second curve fit, highlight all lines starting with the first "Select" statement in the middle of the code to the last Set FitFile = Nothing statement just above the End Sub statement. Then delete these lines.

Now add the for-loop statements at the beginning and end of the remaining macro code. Enter the following two lines at the beginning of the macro

Sub Main
Dim I As Integer
For I = 1 To 2
ActiveDocument.CurrentPageItem.Select(False, -1688, 1521, -1688, 1521)
ActiveDocument.CurrentPageItem.Select(False, -1688, 1521, -1688, 1521)

and the "Next i" line at the end of the macro

Set FitFile = Nothing
Next I
End Sub

If you ran the macro now it would run twice and fit the data in columns 1 and 2 twice. So we need to change one more line in the code. Find the two lines that define the columns to fit.

FitObject.Variable("x") = "col(1)"
FitObject.Variable("y") = "col(3)"

and modify the second line to be

FitObject.Variable("y") = "col(" + CStr(i+1) + ")"

As the for-loop index I increments from 1 to 2 this statement changes the y column to be fit from "col(2)" to "col(3)."

Lets test the modified macro. Click File, Save to save these modifications and close the macro window. Make sure that the graph in the Exponential Data Set 1.jnb notebook is open. If the graph has fit lines from a previous run, then close the notebook without saving and reopen it. To run the macro, select Macros, Exponential Fit from the main menu. The macro runs, exponential functions are fit to both data sets and fit lines are displayed on the graph.

Since the macro placed curve fit results in the worksheet as its last step, the worksheet is displayed on top of the graph page. You will have to click on the graph window to make it the currently displayed window. When we write a macro to display curve fit lines on a graph we would like to have the graph displayed as the last step.  We can easily modify our macro to bring the graph page to the front.

Back to SigmaPlot Product Uses Page.

 

SigmaPlot gr 1

 

 

Sigma Plot 11.0 Prices
Buy Sigma Plot 11.0!

Sigma Plot
Product Details

Capabilities
New Features
Graphs
Statistics
Reporting
Smoothing
Transformations
21 CFR 11
Section 508
Sigma Plot Requirements

Sigma Plot
Resources

Sigma Plot Add-on Modules
Sigma Plot FAQ
Graph Showcase
Sigma Plot Quotes
Sigma Plot Product Uses
Sigma Plot Web Viewer
Technical Support

Other Products
AutoSignal
PeakFit
SigmaPlot
SigmaScan
SigmaStat
SYSTAT
TableCurve 2D
TableCurve 3D

 

bottombar221