The macros

Navigation:  Example 4: Remote control by OLE automation >

The macros

Previous pageReturn to chapter overviewNext page

The Excel file angle.xls contains the tables and macros used in this example. We need two macros: One for starting SCOUT and one doing the computation of the data.

 

Macro for starting SCOUT:

 

'              Start SCOUT

' Creates the automation object "Scout" that is used

' in the following

Sub create_server()

  Set scout = CreateObject("scout.scoutole")

  ' This creates the server, i.e. starts SCOUT

  scout.Show

  ' Display the main window such that the user has access to it

End Sub

 

Macro for computing the data:

 

Sub compute_data()

Dim angle, wavelength, wavenumber As Single

' Write the data header'

  Range("data!top").Offset(0, 1) = "Angle dependence of computed spectra"

  Range("data!top").Offset(2, 0) = "Index"

  Range("data!top").Offset(2, 1) = "Wavelength"

  Range("data!top").Offset(2, 2) = "Wavenumber"

 

  'Compute the wavelengths and wavenumbers of the data points (400 ... 900 nm)

  'We need the wavenumber for each wavelength since

  'SCOUT OLE commands need wavenumbers as input

  For i = 0 To 50

     'Loop through 50 data points

     Range("data!top").Offset(3 + i, 0) = i

     'Write the index in the column 0

     wavelength = 400 + i * 10

     'Compute the wavelength from the index

     Range("data!top").Offset(3 + i, 1) = wavelength

     'Write the wavelength in column 1

     Range("data!top").Offset(3 + i, 3) = wavelength

     'Write the wavelength in column 3 also, this will be used for the graph

     wavenumber = 10000000 / wavelength

     'Compute the wavenumber from the wavelength

     Range("data!top").Offset(3 + i, 2) = wavenumber

     'Write the wavenumber in column 2

  Next i

 

  'The angle range is from 0 to 90° in 3° steps

  For j = 0 To 30

   'Iterate through the angle index

     angle = 3 * j

     'Compute the angle from the index

     Range("data!top").Offset(2, 4 + j) = angle

     'Write the angle for each data column in row 2

     scout.incidence_angle(1) = angle

     'Set the angle of incidence for spectrum 1 in the SCOUT spectrum list

     scout.update_data

     'Compute the spectrum for this angle

     For i = 0 To 50

       'Iterate through the wavelength range

        wavenumber = 10000000 / (400 + i * 10)

        'Compute the wavenumber

        Range("data!top").Offset(3 + i, 4 + j) = scout.simulated_spectrum_value(1, wavenumber)

        'Get the simulated reflectivity for this wavenumber

    Next i

  Next j

End Sub