
249
Chapter 6 Application Programs
Example Programs for Excel 7.0
4
6
Sub makeDataTable(Channel As Integer, columnIndex As Integer)
’ This routine will take the parsed data in row ’1’ for a channel and put it into a
’ table. ’Channel’ determines the row of the table and ’columnIndex’ determines the
’ column (scan sweep count).
’ The number of comma-delimited fields returned per channel is determined by the
’ FORMat:READing commands. The number of fields per channel is required to locate
’ the data in row 1. In this example, there are three cells (fields) per channel.
’ Set up the heading while scanning the first channel.
If Channel = 1 Then
’ Label the top of the data column and time stamp column
Cells(4, columnIndex * 2) = "Scan " & Str(columnIndex)
Cells(4, columnIndex * 2).Font.Bold = True
Cells(3, columnIndex * 2 + 1) = "time stamp"
Cells(4, columnIndex * 2 + 1) = "min:sec"
End If
’ Get channel number, put in column ’A’ for first scan only
If columnIndex = 1 Then
Cells(C 4, 1) = Cells(1, 3)
End If
’ Get the reading data and put into the column
Cells(C 4, columnIndex * 2) = Cells(1, 1)
’ Get the time stamp and put into the column to the right of data; to convert relative
’ time to Excel time, divide by 86400.
Cells(C 4, columnIndex * 2 + 1) = Cells(1, 2) / 86400
Cells(C 4, columnIndex * 2 + 1).NumberFormat = "mm:ss.0"
End Sub
Function ConvertTime(TimeString As String) As Date
’ This routine will take the string returned from the SYSTem:TIME:SCAN? command and
’ return a number compatible with the Excel format. When loaded into a cell, it can
’ be formatted using the Excel ’Format’ menu.
Dim timeNumber As Date
’ Decimal or time portion of the number
Dim dateNumber As Date
’ Integer or date portion of the number
Cells(1, 1).ClearContents
Cells(1, 1) = TimeString
Range("a1").TextToColumns Destination:=Range("a1"), comma:=True
dateNumber = DateSerial(Cells(1, 1), Cells(1, 2), Cells(1, 3))
timeNumber = TimeSerial(Cells(1, 4), Cells(1, 5), Cells(1, 6))
ConvertTime = date timeNumber
End Function
Sub GetErrors()
’ Call this routine to check for instrument errors. The GPIB address variable
’ ’VISAaddr’ must be set.
Dim DataString As String
OpenPort
SendSCPI
"SYSTEM:ERROR?"
’ Read one error from the error queue
Delay (0.1)
DataString = GetSCPI()
MsgBox DataString
ClosePort
End Sub
34970A Refresh UG.book Page 249 Wednesday, February 17, 2010 12:34 PM
Summary of Contents for 34970A
Page 16: ...16 34970A Refresh UG book Page 16 Wednesday February 17 2010 12 34 PM ...
Page 20: ...34970A Refresh UG book Page 20 Wednesday February 17 2010 12 34 PM ...
Page 21: ...1 1 Quick Start 34970A Refresh UG book Page 21 Wednesday February 17 2010 12 34 PM ...
Page 39: ...2 2 Front Panel Overview 34970A Refresh UG book Page 39 Wednesday February 17 2010 12 34 PM ...
Page 59: ...3 3 System Overview 34970A Refresh UG book Page 59 Wednesday February 17 2010 12 34 PM ...
Page 87: ...4 4 Features and Functions 34970A Refresh UG book Page 87 Wednesday February 17 2010 12 34 PM ...
Page 217: ...5 5 Error Messages 34970A Refresh UG book Page 217 Wednesday February 17 2010 12 34 PM ...
Page 241: ...6 6 Application Programs 34970A Refresh UG book Page 241 Wednesday February 17 2010 12 34 PM ...
Page 254: ...254 34970A Refresh UG book Page 254 Wednesday February 17 2010 12 34 PM ...
Page 255: ...7 7 Tutorial 34970A Refresh UG book Page 255 Wednesday February 17 2010 12 34 PM ...
Page 324: ...324 34970A Refresh UG book Page 324 Wednesday February 17 2010 12 34 PM ...