AnsweredAssumed Answered

Programming loop with VBA in Agilent's E5071B ENA Series VNA

Question asked by Ganiu on Jul 9, 2009
Dear Moderators,

I am presently designing a coaxial sensor to measure the dielectric properties of samples at fundamental frequency of 1.25 GHz. I am using Agilent's E5071B 8.5GHz ENA series which produced 6 modes. My problem is that I can only take measurement of samples of one mode at a time while I want to measure all the 6 modes at once instead of one mode after the other. I have read the VBA code and hope it should be possible if I can modify it by including a loop in the VBA code to process the number of modes I want at a time but I don't know how to go about it. Can someone please help with this?

Thank you in advance,
Ganiu.

The code is shown below:

Sub Main()

'This VBA program allows the characterisation of a number of samples.
'It automatically subtracts the background cavity response.
 
  Dim Sample(1000) As String
  Dim Reply As Long
  Dim MyFile As String
  Dim I As Integer, N As Integer
  Dim DeltaBW(1000) As Double
  Dim DeltaFreq(1000) As Double
  Dim DeltaIL(1000) As Double
  Dim PowerFactor(1000) As Double
  Dim Bw0 As Double, Cent0 As Double, Qfac0 As Double
  Dim Bw1 As Double, Cent1 As Double, Qfac1 As Double
  Dim IFBw As Double, Loss0 As Double, Bw00 As Double
  Dim Loss1 As Double, Bw01 As Double
  Dim BwData As Variant
   
'''Presetting the E5070A/E5071A
 
  SCPI.MMEMory.Load.STATe = "d:\ganiu\state01.sta"
 
  MsgBox ("Note: output data file will be stored on your memory stick, so insert stick now")
 
  MyFile = InputBox("Enter your output data file name .txt?")


  N = 0
 
   
Start_here:
 
  SCPI.MMEMory.Load.STATe = "d:\ganiu\state01.sta"


  Sample(N) = InputBox("Enter the sample name/identifier?")
 
  MsgBox ("Insert the sample now.")

  MsgBox ("Ready to measure the sample?")
 
  SCPI.TRIGger.SEQuence.Source = "bus"
  SCPI.TRIGger.SEQuence.SINGle
  SCPI.IEEE4882.WAI

  BwData = SCPI.CALCulate(1).SELected.MARKer(1).BWIDth.DATA
  Bw0 = BwData(0)
  Cent0 = BwData(1)
  Qfac0 = BwData(2)
  Loss0 = BwData(3)
 
  SCPI.SENSe(1).FREQuency.CENTer = Cent0
  SCPI.SENSe(1).FREQuency.SPAN = 5 * Bw0
 
  SCPI.TRIGger.SEQuence.Source = "bus"
  SCPI.TRIGger.SEQuence.SINGle
  SCPI.IEEE4882.WAI
 
  BwData = SCPI.CALCulate(1).SELected.MARKer(1).BWIDth.DATA
  Bw0 = BwData(0)
  Cent0 = BwData(1)
  Qfac0 = BwData(2)
  Loss0 = BwData(3)
 
  SCPI.SENSe(1).FREQuency.CENTer = Cent0
  SCPI.SENSe(1).FREQuency.SPAN = 1.2 * Bw0
  IFBw = 300#    'IF bandwidth = 300 Hz
  SCPI.SENSe(1).BANDwidth.RESolution = IFBw
 
  SCPI.TRIGger.SEQuence.Source = "bus"
  SCPI.TRIGger.SEQuence.SINGle
  SCPI.IEEE4882.WAI
 
  SCPI.DISPlay.WINDow(1).TRACe(1).Y.SCALe.AUTO
 
  BwData = SCPI.CALCulate(1).SELected.MARKer(1).BWIDth.DATA
  Bw0 = BwData(0)
  Cent0 = BwData(1)
  Qfac0 = BwData(2)
  Loss0 = BwData(3) + 0.2
 
  Bw00 = (1 - 10 ^ (Loss0 / 20)) * Bw0
 
  MsgBox ("Remove the sample now.")
 
  MsgBox ("Ready to measure the cavity background?")
 
  SCPI.MMEMory.Load.STATe = "d:\ganiu\state01.sta"
 
  SCPI.TRIGger.SEQuence.Source = "bus"
  SCPI.TRIGger.SEQuence.SINGle
  SCPI.IEEE4882.WAI

  BwData = SCPI.CALCulate(1).SELected.MARKer(1).BWIDth.DATA
  Bw1 = BwData(0)
  Cent1 = BwData(1)
  Qfac1 = BwData(2)
  Loss1 = BwData(3)
 
  SCPI.SENSe(1).FREQuency.CENTer = Cent1
  SCPI.SENSe(1).FREQuency.SPAN = 5 * Bw1
 
  SCPI.TRIGger.SEQuence.Source = "bus"
  SCPI.TRIGger.SEQuence.SINGle
  SCPI.IEEE4882.WAI
 
  BwData = SCPI.CALCulate(1).SELected.MARKer(1).BWIDth.DATA
  Bw1 = BwData(0)
  Cent1 = BwData(1)
  Qfac1 = BwData(2)
  Loss1 = BwData(3)
 
  SCPI.SENSe(1).FREQuency.CENTer = Cent1
  SCPI.SENSe(1).FREQuency.SPAN = 1.2 * Bw1
  IFBw = 300#    'IF bandwidth = 300 Hz
  SCPI.SENSe(1).BANDwidth.RESolution = IFBw
 
  SCPI.TRIGger.SEQuence.Source = "bus"
  SCPI.TRIGger.SEQuence.SINGle
  SCPI.IEEE4882.WAI
 
  SCPI.DISPlay.WINDow(1).TRACe(1).Y.SCALe.AUTO
 
  BwData = SCPI.CALCulate(1).SELected.MARKer(1).BWIDth.DATA
  Bw1 = BwData(0)
  Cent1 = BwData(1)
  Qfac1 = BwData(2)
  Loss1 = BwData(3) + 0.2
 
  Bw01 = (1 - 10 ^ (Loss1 / 20)) * Bw1

  DeltaBW(N) = Bw00 - Bw01
  DeltaFreq(N) = Cent0 - Cent1
  DeltaIL(N) = Loss1 - Loss0
  PowerFactor(N) = 10 ^ (DeltaIL(N) / 10)
 
  'SCPI.DISPlay.ECHO.Clear
  ECHO " "
  ECHO "File name                      :  " & MyFile
  ECHO "Sample name                    :  " & Sample(N)
  ECHO "Bandwidth Change (in MHz)      :  " & DeltaBW(N) / 1000000#
  ECHO "Frequency Shift  (in MHz)      :  " & DeltaFreq(N) / 1000000
  ECHO "Trans. power change (linear)   :  " & PowerFactor(N)
 
  SCPI.DISPlay.TABLe.TYPE = "ECHO"
  SCPI.DISPlay.TABLe.STATe = True
   
  N = N + 1

  Reply = MsgBox("Measure another sample?", vbYesNo)
  If Reply = vbYes Then GoTo Start_here
 
  MyFile = "g:\" & MyFile & ".txt"
  fnum = FreeFile()
  Open MyFile For Output As fnum
  Print #fnum, "Sample", " Delta_BW(MHz)", " Delta_f(MHz)", "               Power_Factor"
  For I = 0 To N - 1
    Print #fnum, Sample(I), DeltaBW(I) / 1000000#, DeltaFreq(I) / 1000000#, PowerFactor(I)
  Next I

Close #fnum
 
   
  SCPI.MMEMory.Load.STATe = "d:\ganiu\state01.sta"
 
  End Sub  

Outcomes