www.pudn.com > NetMgrSamp1.rar > frmSNMP2.frm


VERSION 5.00 
Begin VB.Form frmSNMP2  
   BorderStyle     =   5  'Sizable ToolWindow 
   Caption         =   "NetMgr -- Sample 2" 
   ClientHeight    =   5130 
   ClientLeft      =   60 
   ClientTop       =   300 
   ClientWidth     =   4725 
   LinkTopic       =   "Form1" 
   MaxButton       =   0   'False 
   MinButton       =   0   'False 
   ScaleHeight     =   5130 
   ScaleWidth      =   4725 
   ShowInTaskbar   =   0   'False 
   StartUpPosition =   2  'CenterScreen 
   Begin VB.ListBox lstResults  
      Height          =   1035 
      ItemData        =   "frmSNMP2.frx":0000 
      Left            =   0 
      List            =   "frmSNMP2.frx":0007 
      TabIndex        =   18 
      Top             =   4080 
      Width           =   4695 
   End 
   Begin VB.Frame fmeHostInfo  
      Caption         =   "Host Information" 
      Height          =   1575 
      Left            =   0 
      TabIndex        =   9 
      Top             =   0 
      Width           =   4695 
      Begin VB.CommandButton cmdGo  
         Caption         =   "Go!" 
         Height          =   375 
         Left            =   3840 
         TabIndex        =   20 
         Top             =   360 
         Width           =   735 
      End 
      Begin VB.TextBox txtRetries  
         Height          =   285 
         Left            =   3480 
         TabIndex        =   13 
         Text            =   "2" 
         Top             =   1080 
         Width           =   375 
      End 
      Begin VB.TextBox txtTimeout  
         Height          =   285 
         Left            =   1680 
         TabIndex        =   12 
         Text            =   "1000" 
         Top             =   1080 
         Width           =   855 
      End 
      Begin VB.TextBox txtCommSTr  
         Height          =   285 
         Left            =   1680 
         TabIndex        =   11 
         Text            =   "public" 
         Top             =   720 
         Width           =   1575 
      End 
      Begin VB.TextBox txtAgent  
         Height          =   285 
         Left            =   1680 
         TabIndex        =   10 
         Text            =   "localhost" 
         Top             =   360 
         Width           =   1575 
      End 
      Begin VB.Label lblTimeout  
         Alignment       =   1  'Right Justify 
         Caption         =   "Timeout [ms]" 
         Height          =   255 
         Left            =   240 
         TabIndex        =   17 
         Top             =   1080 
         Width           =   1335 
      End 
      Begin VB.Label lblRetries  
         Alignment       =   1  'Right Justify 
         Caption         =   "Retries" 
         Height          =   255 
         Left            =   2640 
         TabIndex        =   16 
         Top             =   1125 
         Width           =   735 
      End 
      Begin VB.Label lblCommStr  
         Alignment       =   1  'Right Justify 
         Caption         =   "Community String" 
         Height          =   255 
         Left            =   240 
         TabIndex        =   15 
         Top             =   720 
         Width           =   1335 
      End 
      Begin VB.Label lblAgent  
         Alignment       =   1  'Right Justify 
         Caption         =   "SNMP Agent " 
         Height          =   255 
         Left            =   240 
         TabIndex        =   14 
         Top             =   390 
         Width           =   1335 
      End 
   End 
   Begin VB.Frame fmeSpecs  
      Caption         =   "OID Specifications" 
      Height          =   2295 
      Left            =   0 
      TabIndex        =   0 
      Top             =   1680 
      Width           =   4695 
      Begin VB.CommandButton cmdAddItem  
         Caption         =   "Add Item" 
         Height          =   375 
         Left            =   3720 
         TabIndex        =   21 
         Top             =   240 
         Width           =   855 
      End 
      Begin VB.ListBox lstOID  
         Height          =   840 
         ItemData        =   "frmSNMP2.frx":0017 
         Left            =   120 
         List            =   "frmSNMP2.frx":001E 
         TabIndex        =   19 
         Top             =   1320 
         Width           =   4455 
      End 
      Begin VB.CheckBox chkSetInteger  
         Caption         =   "Integer" 
         Enabled         =   0   'False 
         Height          =   255 
         Left            =   2760 
         TabIndex        =   5 
         Top             =   620 
         Visible         =   0   'False 
         Width           =   855 
      End 
      Begin VB.TextBox txtSetVal  
         Enabled         =   0   'False 
         Height          =   285 
         Left            =   1440 
         TabIndex        =   4 
         Top             =   600 
         Width           =   1215 
      End 
      Begin VB.OptionButton optOps  
         Caption         =   "Set" 
         Height          =   195 
         Index           =   2 
         Left            =   2040 
         TabIndex        =   3 
         Top             =   960 
         Width           =   615 
      End 
      Begin VB.OptionButton optOps  
         Caption         =   "Get" 
         Height          =   195 
         Index           =   0 
         Left            =   1440 
         TabIndex        =   2 
         Top             =   960 
         Width           =   615 
      End 
      Begin VB.TextBox txtOID  
         Height          =   285 
         Left            =   1440 
         TabIndex        =   1 
         Text            =   ".1.3.6.1.2.1.1.3.0" 
         Top             =   240 
         Width           =   2175 
      End 
      Begin VB.Label lblSetVal  
         Alignment       =   1  'Right Justify 
         Caption         =   "Set Value" 
         Height          =   255 
         Left            =   120 
         TabIndex        =   8 
         Top             =   645 
         Width           =   1215 
      End 
      Begin VB.Label lblOps  
         Alignment       =   1  'Right Justify 
         Caption         =   "Operations" 
         Height          =   255 
         Left            =   120 
         TabIndex        =   7 
         Top             =   960 
         Width           =   1215 
      End 
      Begin VB.Label lblOID  
         Alignment       =   1  'Right Justify 
         Caption         =   "Object Identifier" 
         Height          =   255 
         Left            =   120 
         TabIndex        =   6 
         Top             =   285 
         Width           =   1215 
      End 
   End 
End 
Attribute VB_Name = "frmSNMP2" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
' Global variable declarations 
' ---------------------------- 
Private intOps As Integer 
 
Private Sub cmdAddItem_Click() 
    lstOID.AddItem txtOID.Text & " => " & IIf(intOps = 2, txtSetVal.Text, "[N/A]") 
End Sub 
 
Private Sub cmdGo_Click() 
    ' Local variable declarations 
    ' ------------------------------ 
    Dim tObj        As New NETMGRLib.SNMPv1     ' NetMgr Object 
    Dim varInOID    As Variant                  ' Encapsulates OIDs being passed in 
    Dim varOutOID   As Variant                  ' Represents OIDs coming out 
    Dim varInValues As Variant                  ' Contains values tied to varInOID 
    Dim strAgentVal As String                   ' Utility string variable 
    Dim strTmpOID   As String                   ' Utility string variable 
    Dim intRetVal   As Integer                  ' Utility integer variable 
    Dim intCounter  As Integer                  ' Counter 
    Dim intListElem As Integer                  ' Total elements in lstOID 
     
    ' Initialize local variables 
    intListElem = lstOID.ListCount - 1 
     
    ' Remove all results 
    lstResults.Clear 
     
    ' =Initialize and populate var(In|Out)OID and varInValues array 
    ' == Initialize varInOID array as string 
    ReDim varInOID(0 To intListElem) As String 
         
        ' Populate varInOID Array 
        For intCounter = 0 To intListElem 
            strTmpOID = lstOID.List(intCounter) 
            varInOID(intCounter) = Mid(strTmpOID, 1, InStr(1, strTmpOID, " => ", 1) - 1) 
        Next 
     
    ' ==Begin Initialization and/or population of var(InValues|OutOID) array 
    If intOp = 0 Then 
        ' Get Operation so varOutOID is redim'd as a string 
        ReDim varOutOID(0 To intListElem) As String 
    Else 
        If chkSetInteger.Value = 0 Then 
            ' Set Operation but string based 
            ReDim varInValues(0 To intListElem) As String 
             
            ' Populate varInValues with string based elements 
            For intCounter = 0 To intListElem 
                strTmpOID = lstOID.List(intCounter) 
                varInValues(intCounter) = CStr(Mid(strTmpOID, InStr(1, strTmpOID, " => ", 1) + 4)) 
            Next 
        Else 
            ' Set Operation but integer based 
            ReDim varInValues(0 To intListElem) As Integer 
             
            ' Populate varInValues with string based elements 
            For intCounter = 0 To intListElem 
                ' Initialize local variable 
                strTmpOID = CStr(Mid(lstOID.List(intCounter), InStr(1, lstOID.List(intCounter), " => ", 1) + 4)) 
                 
                ' Determine if current counter value can be considered numeric 
                If Not IsNumeric(strTmpOID) Then 
                    ' Inform user that only numeric entries are permitted 
                    lstResults.AddItem "> All element values must be integer based" 
                    lstResults.AddItem "> Halting procedure..." 
                     
                    ' Exit routine without proceeding 
                    Exit Sub 
                Else 
                    varInValues(intCounter) = CInt(strTmpOID) 
                End If 
            Next 
        End If 
    End If 
     
    ' Open connection and return value of oid -> operation 
     With tObj 
        ' Opening Connection and add item to list view 
        strAgentVal = .Open(txtAgent.Text, txtCommStr.Text, CInt(txtTimeout.Text), CInt(txtRetries.Text)) 
        lstResults.AddItem "> " & strAgentVal 
             
        ' Get value for OID if no error is returned 
        If InStr(1, strAgentVal, "Error:", 1) < 1 Then 
            ' Execute statements in accordance with selected operation 
            If intOps = 0 Then 
                varOutOID = .Get(varInOID) 
                    With lstResults 
                        ' =Determine if varOutOID is an array 
                        ' ==If it's not an array, this means that an error 
                        '   occured within the execution -- varOutOID will 
                        '   then be the error 
                        If IsArray(varOutOID) Then 
                            ' Report total elements 
                            .AddItem "== Total Elements: " & UBound(varOutOID) 
                                ' =Determine if elements were returned in array 
                                If UBound(varOutOID) > 0 Then 
                                    For intCounter = 0 To UBound(varOutOID) 
                                        .AddItem "=E" & intCounter & "= " & varInOID(intCounter) & " => " & varOutOID(intCounter) 
                                    Next 
                                End If 
                        Else 
                            ' Report error 
                            .AddItem "=E= " & varOutOID 
                        End If 
                    End With 
            Else 
                ' Initiate communication with Agent for our Set Operation 
                strAgentVal = .Set(varInOID, varInValues) 
                 
                ' Report response from agent 
                lstOID.AddItem "=S= " & strAgentVal 
            End If 
        End If 
         
        ' Close connection and return result 
        lstResults.AddItem "> " & IIf(.Close = 0, "Closed connection successfully", "Error with closing connection") 
     End With 
         
    ' Destory object 
    Set tObj = Nothing 
End Sub 
 
Private Sub Form_Load() 
    ' Clear items from list view 
    lstResults.Clear 
    lstOID.Clear 
     
    ' Assign default to Operation Options and global 
    ' variable intOps 
    optOps(0).Value = True 
    intOps = 0 
End Sub 
 
Private Sub Form_Resize() 
    ' Upon resizing of form, make sure listview and lines 
    ' change with the form 
    If (lstResults.Top < Me.Height) Then 
        lstResults.Width = Me.Width - lstResults.Left - 100 
        lstResults.Height = Me.Height - lstResults.Top - 100 
    End If 
     
    fmeHostInfo.Width = lstResults.Width - 25 
    fmeSpecs.Width = lstResults.Width - 25 
End Sub 
 
Private Sub optOps_Click(Index As Integer) 
    ' Local variable declarations 
    Dim boolOptSet As Boolean 
     
    ' Assign index to global variable intOps 
    intOps = Index 
     
    ' Clear list view 
    lstOID.Clear 
     
    ' Execute commands based upon which option is chosen 
    boolOptSet = (Index = 2) 
    txtSetVal.Enabled = boolOptSet 
    chkSetInteger.Visible = boolOptSet 
    chkSetInteger.Enabled = boolOptSet 
    chkSetInteger.Value = 0 
End Sub