Hi. I'm Bill Griffith, an application engineer with Agilent Technologies. Today I want to
show you a very simple program written in Visual Basic for Excel. So this program is
really good if you're getting started in Visual Basic for Excel or if you just want
a simple refresher. So to get started, I have the Agilent Connection Expert, which is good
for finding your instrument and also for going ahead and getting the VISA address.
So I'm going to go ahead and connect my instrument with a USB connection.
And the Connection Expert will go ahead and find the instrument.
Great. So it found the instrument. And with it connected, we can go ahead and use the
Interactive I/O that's built into the Connection Expert and we can send a *IDN command and
then read back the response so we can verify that we have a good connection with our instrument.
We'll go ahead and copy the VISA address from the Connection Expert because this is
what we'll need in our Excel program.
And at this point I'm going to go ahead and switch to Excel.
So I'm going to go ahead and drop in the instrument address that we copied. OK.
In addition to that, in Excel I went ahead and I added the developers tab. You can do this.
It's an option in Excel to turn on the developers tab, and this gives you all the controls
for Visual Basic. And so if you're developing programs, you'll want to add the developers
tab in Excel. The other thing is you'll want to make sure that you have the code enabled,
and so you can go ahead and enable the code so that it will run in Excel. And as you can see,
in our simple program, we're going to do a start or initialize to set up our resources.
Then we're going to send a *IDN. We're going to read back the response from
the instrument, and then we'll go ahead and close our connection. So let's go ahead
and look at the code underneath the Excel program. So the first thing we do is we start
by dimensioning all of our variables that we'll use throughout our program. And then
our first subroutine is an initialize routine, which is connected to our start button.
And this will go ahead and open the global resource manager, and it'll assign all of our objects.
We also have some error checking in it, so if there's a time out on the I/O, it will
go ahead and put up a message box and let us know that there was a problem with the I/O.
The next subroutine is going to send the *IDN command and will again, pop up a
message box to let us know that the message has been sent to the instrument. Our third
subroutine will read back the response from the instrument, and then finally we'll go
ahead and close the instrument. So while we're here, I want to show you how easy it is to
create one of these subroutines, so let's go ahead and just copy our subroutine that
sends the *IDN command. So we'll go ahead and copy the whole thing, and then we're
going to go ahead and paste it in at the bottom of our program. And what I'd like to do
is I'd like to change the subroutine to send a reset command, so that's the RST
command. So let's go ahead and change the name of our subroutine to be RST, and then
we'll change the SCPI command that's being sent to the instrument to be RST. And then
we'll change the message box to be RST as well.
Great. So now we've added a new subroutine in Visual Basic.
So let's go back to our spreadsheet and we'll also go ahead and add a button for
our new subroutine. See how easy that is. So we'll use our developer tab.
Then we'll insert a button. We'll put our button right here. OK. And then we'll link it to a
subroutine so we have a choice of the subroutines that we've created. And so I want to link
it to the RST subroutine, so I'll go ahead and choose that one. And then I'd like to
create a label that's a little bit more meaningful, so we'll go ahead and create
a button that says "Send RST". OK.
So we're done. So now we can go ahead and run our program, so we'll go ahead and start it.
So we've initialized our variables and opened our resource manager. We can send the RST
command, and it says the RST command has been sent. We'll send our *IDN. We'll
read back the response, so there's a response back from the instrument. And we'll go ahead
and close our connection at this point.
So that's a very simple Excel program. And I wanted to show you one more thing before
we quit here today, so let's go ahead and see how easy it is to change the I/O interface
on our instruments. So I'm going to go ahead and bring up our Agilent Connection Expert
one more time, and I'm going to switch interfaces. So we're using the 34411A Multimeter, which has
a USB connection on it. It has LAN connection, and it also has GPIB. So we're going to go
ahead and switch to the GPIB interface, so I've gone ahead and made that connection.
And so the Agilent Connection Expert's going to go ahead and find the instrument on GPIB,
which it has now found it. Once again we'll go ahead and grab the GPIB address,
so what we want is we want the VISA address. That's what the Visual Basic for Excel will use.
So I'll go ahead and copy that, and then I'm going to go ahead and paste it in my
program. And again, we can start our program, send the *IDN command, and then read back
the response. So that's just how easy it is to go ahead and change the instrument I/O
using the Connection Expert from Agilent. So as you can see, it's easy to create a
simple Visual Basic program to control your instruments using Visual Basic that comes with Excel.
Thank you very much.