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


VERSION 5.00 
Begin VB.Form frmSNMP1  
   BorderStyle     =   5  'Sizable ToolWindow 
   Caption         =   "NetMgr -- Sample 1" 
   ClientHeight    =   4530 
   ClientLeft      =   60 
   ClientTop       =   300 
   ClientWidth     =   4695 
   LinkTopic       =   "Form1" 
   MaxButton       =   0   'False 
   MinButton       =   0   'False 
   ScaleHeight     =   4530 
   ScaleWidth      =   4695 
   ShowInTaskbar   =   0   'False 
   StartUpPosition =   2  'CenterScreen 
   Begin VB.Frame fmeSpecs  
      Caption         =   "OID Specifications" 
      Height          =   1575 
      Left            =   0 
      TabIndex        =   10 
      Top             =   1800 
      Width           =   4695 
      Begin VB.TextBox txtOID  
         Height          =   285 
         Left            =   1440 
         TabIndex        =   19 
         Text            =   ".1.3.6.1.2.1.1.3.0" 
         Top             =   240 
         Width           =   2295 
      End 
      Begin VB.OptionButton optOps  
         Caption         =   "Get" 
         Height          =   195 
         Index           =   0 
         Left            =   1440 
         TabIndex        =   18 
         Top             =   960 
         Width           =   615 
      End 
      Begin VB.OptionButton optOps  
         Caption         =   "GetNext" 
         Height          =   195 
         Index           =   1 
         Left            =   2160 
         TabIndex        =   17 
         Top             =   960 
         Width           =   975 
      End 
      Begin VB.OptionButton optOps  
         Caption         =   "Set" 
         Height          =   195 
         Index           =   2 
         Left            =   1440 
         TabIndex        =   16 
         Top             =   1200 
         Width           =   615 
      End 
      Begin VB.OptionButton optOps  
         Caption         =   "Walk" 
         Height          =   195 
         Index           =   3 
         Left            =   2160 
         TabIndex        =   15 
         Top             =   1200 
         Width           =   735 
      End 
      Begin VB.TextBox txtSetVal  
         Enabled         =   0   'False 
         Height          =   285 
         Left            =   1440 
         TabIndex        =   14 
         Top             =   600 
         Width           =   1215 
      End 
      Begin VB.CheckBox chkFullWalk  
         Caption         =   "Full Walk" 
         Height          =   255 
         Left            =   3360 
         TabIndex        =   13 
         Top             =   1170 
         Visible         =   0   'False 
         Width           =   1095 
      End 
      Begin VB.CommandButton cmdGo  
         Caption         =   "Go!" 
         Height          =   375 
         Left            =   3840 
         TabIndex        =   12 
         Top             =   240 
         Width           =   735 
      End 
      Begin VB.CheckBox chkSetInteger  
         Caption         =   "Integer" 
         Enabled         =   0   'False 
         Height          =   255 
         Left            =   2880 
         TabIndex        =   11 
         Top             =   615 
         Visible         =   0   'False 
         Width           =   855 
      End 
      Begin VB.Label lblOID  
         Alignment       =   1  'Right Justify 
         Caption         =   "Object Identifier" 
         Height          =   255 
         Left            =   120 
         TabIndex        =   22 
         Top             =   285 
         Width           =   1215 
      End 
      Begin VB.Label lblOps  
         Alignment       =   1  'Right Justify 
         Caption         =   "Operations" 
         Height          =   255 
         Left            =   120 
         TabIndex        =   21 
         Top             =   960 
         Width           =   1215 
      End 
      Begin VB.Label lblSetVal  
         Alignment       =   1  'Right Justify 
         Caption         =   "Set Value" 
         Height          =   255 
         Left            =   120 
         TabIndex        =   20 
         Top             =   645 
         Width           =   1215 
      End 
   End 
   Begin VB.Frame fmeHostInfo  
      Caption         =   "Host Information" 
      Height          =   1575 
      Left            =   0 
      TabIndex        =   1 
      Top             =   120 
      Width           =   4695 
      Begin VB.TextBox txtAgent  
         Height          =   285 
         Left            =   1680 
         TabIndex        =   5 
         Text            =   "localhost" 
         Top             =   360 
         Width           =   1575 
      End 
      Begin VB.TextBox txtCommSTr  
         Height          =   285 
         Left            =   1680 
         TabIndex        =   4 
         Text            =   "public" 
         Top             =   720 
         Width           =   1575 
      End 
      Begin VB.TextBox txtTimeout  
         Height          =   285 
         Left            =   1680 
         TabIndex        =   3 
         Text            =   "1000" 
         Top             =   1080 
         Width           =   855 
      End 
      Begin VB.TextBox txtRetries  
         Height          =   285 
         Left            =   3480 
         TabIndex        =   2 
         Text            =   "2" 
         Top             =   1080 
         Width           =   375 
      End 
      Begin VB.Label lblAgent  
         Alignment       =   1  'Right Justify 
         Caption         =   "SNMP Agent " 
         Height          =   255 
         Left            =   240 
         TabIndex        =   9 
         Top             =   390 
         Width           =   1335 
      End 
      Begin VB.Label lblCommStr  
         Alignment       =   1  'Right Justify 
         Caption         =   "Community String" 
         Height          =   255 
         Left            =   240 
         TabIndex        =   8 
         Top             =   720 
         Width           =   1335 
      End 
      Begin VB.Label lblRetries  
         Alignment       =   1  'Right Justify 
         Caption         =   "Retries" 
         Height          =   255 
         Left            =   2640 
         TabIndex        =   7 
         Top             =   1125 
         Width           =   735 
      End 
      Begin VB.Label lblTimeout  
         Alignment       =   1  'Right Justify 
         Caption         =   "Timeout [ms]" 
         Height          =   255 
         Left            =   240 
         TabIndex        =   6 
         Top             =   1080 
         Width           =   1335 
      End 
   End 
   Begin VB.ListBox lstResults  
      Height          =   1035 
      ItemData        =   "frmSNMP.frx":0000 
      Left            =   0 
      List            =   "frmSNMP.frx":0007 
      TabIndex        =   0 
      Top             =   3480 
      Width           =   4695 
   End 
End 
Attribute VB_Name = "frmSNMP1" 
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 cmdGo_Click() 
    ' Local variable declarations 
    ' ------------------------------ 
    Dim tObj        As New NETMGRLib.SNMPv1     ' NetMgr Object 
    Dim matchOID    As Variant                  ' Used for OID comparison in SNMP walks 
    Dim varOID      As Variant                  ' Encapsulates OID 
    Dim strAgentVal As String                   ' Utility string variable 
    Dim intRetVal   As Integer                  ' Utility integer variable 
    Dim intCounter  As Integer                  ' Counter 
         
    ' Remove all results 
    lstResults.Clear 
     
    ' Assign value to varOID 
    varOID = txtOID.Text 
     
    ' 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 
            Select Case intOps 
                Case 0                      ' Operation -> Get 
                    lstResults.AddItem "=== " & varOID & " : " & .Get(varOID) 
                 
                Case 1                      ' Operation -> GetNext 
                    strAgentVal = .GetNext(varOID) 
                    lstResults.AddItem "=== " & varOID & " : " & strAgentVal 
                     
                Case 2                      ' Operation -> Set 
                    ' =Validate if the Integer checkbox is checked 
                    ' ==Not Checked therefore assume String type 
                    If chkSetInteger.Value = 0 Then 
                        lstResults.AddItem "=== " & varOID & " : " & .Set(varOID, txtSetVal.Text) 
                    Else 
                    ' ==Checked therefore assume Integer type 
                        ' Double text box and sure it is an integer 
                        If IsNumeric(txtSetVal.Text) Then 
                            lstResults.AddItem "=== " & varOID & " : " & .Set(varOID, CInt(txtSetVal.Text)) 
                        Else 
                            lstResults.AddItem "=== " & varOID & " does not appear to be an integer" 
                        End If 
                    End If 
                     
                Case 3                      ' Walk 
                    ' Initialize walk 
                    strAgentVal = tObj.Get(varOID) 
                    lstResults.AddItem "=S= " & varOID & " : " & strAgentVal 
                    intCounter = 2 
                     
                    ' Grab first oid/value pair after txtOID.text 
                    strAgentVal = CStr(.GetNext(varOID)) 
                    matchOID = Mid(varOID, 1, InStr(1, varOID, ".", 1)) 
                    lstResults.AddItem "=1= " & varOID & " : " & strAgentVal 
                     
                    ' Loop through all oid's in criteria 
                    Do Until (InStr(1, strAgentVal, "Error", 1) > 0 Or InStr(1, varOID, ".iso.", 1) > 0) 
                        ' Get Next Value 
                        strAgentVal = CStr(.GetNext(varOID)) 
                            ' Validate life cycle of walk 
                            If chkFullWalk.Value = 0 Then 
                                ' When using the SnmpMgrOidToStr function in the WinSNMP API, the LPSTR 
                                ' returned is the the actual name of the OID.  The purpose of statements 
                                ' dealing with matchOID is to make sure that we're staying within the same 
                                ' area IF the Full Walk check box is unchecked. 
                                If Mid(varOID, 1, InStr(1, varOID, ".", 1)) <> matchOID Then 
                                    matchOID = Mid(varOID, 1, InStr(1, varOID, ".", 1)) 
                                    Exit Do 
                                End If 
                            End If 
                             
                        ' Add item to list view 
                        lstResults.AddItem "=" & intCounter & "= " & varOID & " : " & strAgentVal 
                         
                        ' Increment counter 
                        intCounter = intCounter + 1 
                         
                        ' Make sure list view gets updated 
                        DoEvents 
                    Loop 
            End Select 
        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 
     
    ' 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) 
    ' Assign index to global variable intOps 
    intOps = Index 
     
    ' Execute commands based upon which option is chosen 
    Select Case Index 
        Case 2                          ' Operation -> Set 
            txtSetVal.Enabled = True 
            chkSetInteger.Visible = True 
            chkSetInteger.Enabled = True 
            chkFullWalk.Visible = False 
            chkFullWalk.Value = 0 
             
        Case 3                          ' Walk 
            txtSetVal.Enabled = False 
            chkSetInteger.Visible = False 
            chkSetInteger.Enabled = False 
            chkSetInteger.Value = 0 
            chkFullWalk.Visible = True 
         
        Case Else                       ' All other operations 
            txtSetVal.Enabled = False 
            chkSetInteger.Visible = False 
            chkSetInteger.Enabled = False 
            chkSetInteger.Value = 0 
            chkFullWalk.Visible = False 
            chkFullWalk.Value = 0 
    End Select 
End Sub