Other topics about Application Programs
The map_drive.vba shows a sample program (VBA program) that demonstrates how to connect a hard disk (a shared folder) of an external PC to the E5061B. This VBA program consists of the following modules:
Object name |
Module type |
Description |
frmMapDrive |
User form |
Connects or disconnects a hard disk |
Module1 |
Standard module |
Displays frmMapDrive |
Load the map_drive.vba and press Macro Run key. The following macro appears.
Shared folder connection macro
Connecting (Mapping)
Enter the drive letter for the shared folder (1), share name of the shared folder (2), user name (3), password (4), and then click Map (5).
Consult your network administrator and enter the settings in the same way as done in the Windows PC operating system. If you enter an incorrect setting, an error might occur and the program might be interrupted.
Disconnecting
Enter the drive letter for the shared folder (1), and then click Disconnect (6).
Click Exit (7) to exit from the program.
The program (object name: frmMapDrive) is described in detail below. The following description is included as a comment in the source code.
This procedure is called when the user clicks the Map button. It checks whether the drive letter is used by using the IsDriveNameInUse procedure. Then the procedure connects the shared folder using the MapDrive procedure if the drive letter is not used or otherwise it displays a message to show the drive in use.
This procedure is called when the user clicks the Disconnect button. The procedure disconnects the shared folder by using the DisconnectDrive procedure.
This procedure checks if the txtDrive.Text (the drive letter specified by 1) is used.
This procedure connects the shared folder as the txtDrive.Text (the drive letter specified by 1) drive by using the parameters: txtShare.Text (the share name specified by 2), txtUser.Text (the user name specified by 3), and txtPasswd.Text (the password specified by 4).
This procedure disconnects the txtDrive.Text (the drive letter specified by 1) drive.
This procedure is called when the user clicks the Exit button. This procedure ends the program.
Connecting the hard disk of an external PC (Object name: frmMapDrive)
'
' This procedure is called when the user clicks the Map button. It checks whether
' the drive letter is used by using the IsDriveNameInUse procedure.
' Then the procedure connects the shared folder using the MapDrive procedure
' if the drive letter is not used or otherwise displays a message to show
' the drive letter is used.
'
Private Sub CommandButton1_Click()
If Not IsDriveNameInUse Then
Call MapDrive
Else
MsgBox "Drive """ & txtDrive.Text & """ is Already used", vb Critical
End If
End Sub
'
' This procedure is called when the user clicks the Disconnect button.
' The procedure disconnects the shared folder by using the DisconnectDrive procedure.
'
Private Sub CommandButton2_Click()
Call DisconnectDrive
End Sub
'
' This procedure checks if the txtDrive.Text is used.
'
Private Function IsDriveNameInUse() As Boolean
Set fso = CreateObject("Scripting.FileSystemObject")
IsDriveNameInUse = fso.DriveExists(txtDrive.Text)
End Function
'
' This procedure connects the shared folder as the txtDrive.Text drive by using the parameters:
' txtShare.Text, txtUser.Text, and txtPasswd.Text.
'
Private Sub MapDrive()
Set network = CreateObject("wscript.network")
Call network.MapNetworkDrive(txtDrive.Text, txtShare.Text, vbFal se, txtUser.Text, txtPasswd.Text)
End Sub
'
' This procedure disconnects the txtDrive.Text drive.
'
Private Sub DisconnectDrive()
Set network = CreateObject("wscript.network")
network.RemoveNetworkDrive txtDrive.Text
End Sub
'
' This procedure is called when the user clicks the Exit button. This procedure ends the program.
'
Private Sub CommandButton3_Click()
Unload Me
End Sub