Do more with
Option Explicit
Class ServerClass
Private m_ServerName
Private m_ServerStatus
Private m_ServerStatusTime
Public Property Get ServerName
ServerName = m_ServerName
End Property
Public Property Let ServerName (i_ServerName)
m_ServerName = i_ServerName
End Property
Public Property Get ServerStatus
ServerStatus = m_ServerStatus
End Property
Public Property Let ServerStatus (i_ServerStatus)
m_ServerStatus = i_ServerStatus
End Property
Public Property Get ServerStatusTime
ServerStatusTime = m_ServerStatusTime
End Property
Public Property Let ServerStatusTime (i_ServerStatusTime)
m_ServerStatusTime = i_ServerStatusTime
End Property
End Class
'Function GetServerName(ByVal i_Index)
' If i_Index < LBound(ServerArray) Or i_Index > UBound(ServerArray) Then
' Exit Function
' End If
' ServerName= ServerArray(i_Index).ServerName
'End Function ' GetServerName(ByVal i_Index)
Sub AddServerName (ByVal i_Index, ByVal i_ServerName)
WScript.Echo "Setting ServerName at Index " & i_Index & " to " & i_ServerName
If i_Index < LBound(ServerArray) Then
Exit Sub
End If
If i_Index > UBound(ServerArray) Then
ReDim Preserve ServerArray(i_Index)
WScript.Echo "ServerArray Redim to index " & i_Index & " complete"
Set ServerArray(i_Index) = New ServerClass
WScript.Echo "New instance of ServerClass created for ServerArray(" & i_Index & ")"
End If
WScript.Echo "Before Setting ServerName at Index " & i_Index & " to " & i_ServerName
ServerArray(i_Index).ServerName = i_ServerName
ServerArray(i_Index).ServerStatus = "Unknown"
ServerArray(i_Index).ServerStatusTime = Now
WScript.Echo "After Setting ServerName at Index " & i_Index & " to " & i_ServerName
WSCript.Echo "Value in array at index " & i_Index & " is " & ServerArray(i_Index).ServerName & _
" with status " & ServerArray(i_Index).ServerStatus & " at " & ServerArray(i_Index).ServerStatusTime
End Sub ' AddServerName (ByVal i_Index, ByVal i_ServerName)
Function GetMaxIndex
GetMaxIndex = UBound(ServerArray)
End Function ' MaxIndex()
Dim ServerArray()
Dim ServerName, ServerIndex, ServerMaxIndex
ReDim ServerArray(0)
WScript.Echo "ServerArray Redim to 0 complete"
Set ServerArray(0) = New ServerClass
WScript.Echo "New instance of ServerClass created for ServerArray(0)"
ServerName = "Server1"
ServerIndex = 0
WScript.Echo ""
WScript.Echo "Server Name " & ServerName & " has Index " & ServerIndex
AddServerName ServerIndex, ServerName
ServerName = "Server2"
ServerIndex = 1
WScript.Echo ""
WScript.Echo "Server Name " & ServerName & " has Index " & ServerIndex
AddServerName ServerIndex, ServerName
ServerName = "Server3"
ServerIndex = 2
WScript.Echo ""
WScript.Echo "Server Name " & ServerName & " has Index " & ServerIndex
AddServerName ServerIndex, ServerName
WScript.Echo ""
WScript.Echo "Get Max Index"
ServerMaxIndex = GetMaxIndex
WScript.Echo "Loop through array"
For ServerIndex = 0 to ServerMaxIndex
WScript.Echo "ServerArrary at Index " & ServerIndex & _
" has value " & ServerArray(ServerIndex).ServerName
ServerName = ServerArray(ServerIndex).ServerName
WScript.Echo "GetServerName for Index " & ServerIndex & _
" returns value " & ServerName
Next
WScript.Echo "End of loop"
Premium Content
You need an Expert Office subscription to comment.Start Free Trial