|
-
Feb 16th, 2000, 01:20 PM
#1
Thread Starter
Junior Member
I run a command netstat -a > text.txt
and get the result as below:
Active Connections
Proto Local Address Foreign Address State
TCP p2:1030 P2:0 LISTENING
TCP p2:80 P2:0 LISTENING
TCP p2:135 P2:0 LISTENING
TCP p2:6543 P2:0 LISTENING
TCP p2:443 P2:0 LISTENING
TCP p2:1032 P2:0 LISTENING
TCP p2:1032 APIITNT:nbsession ESTABLISHED
TCP p2:137 P2:0 LISTENING
TCP p2:138 P2:0 LISTENING
TCP p2:nbsession P2:0 LISTENING
TCP p2:1028 P2:0 LISTENING
TCP p2:1029 P2:0 LISTENING
TCP p2:1031 P2:0 LISTENING
UDP p2:6543 *:*
UDP p2:nbname *:*
UDP p2:nbdatagram *:*
Now I want write a porgram to read the test.txt and
display in a listview with four column, which is same with above.
How can I display the result?
Can anyone help me???
thanks
-
Feb 17th, 2000, 12:00 PM
#2
Sure thing.
Code:
Private Sub Command1_Click()
Dim xColumnHeader As ColumnHeader
Dim xListItem As ListItem
Dim intFFN As Integer
Dim strPath As String
Dim strBuffer As String
Dim arrString() As String
Dim i As Integer
With ListView1
.View = lvwReport
Set xColumnHeader = .ColumnHeaders.Add(, , "Protocol")
Set xColumnHeader = .ColumnHeaders.Add(, , "Local Address")
Set xColumnHeader = .ColumnHeaders.Add(, , "Foreign Address")
Set xColumnHeader = .ColumnHeaders.Add(, , "State")
End With
strPath = "d:\Text.txt"
intFFN = FreeFile
Open strPath For Input As intFFN
Do Until EOF(intFFN)
Line Input #1, strBuffer
arrString = Split(strBuffer, " ")
With ListView1
Set xListItem = .ListItems.Add(, , arrString(0))
For i = 1 To UBound(arrString)
xListItem.SubItems(i) = arrString(i)
Next
End With
Loop
Close #intFFN
End Sub
------------------
Serge
Senior Programmer Analyst
[email protected]
[email protected]
ICQ#: 51055819
-
Feb 17th, 2000, 12:47 PM
#3
Thread Starter
Junior Member
The source code was got compile error
in the line
arrString = Splits(strBuffer, " ")
with the error message
Sub or Function not defined
What happen with it?
I am using visual Basic 5.
-
Feb 17th, 2000, 11:41 PM
#4
Sorry about that. Split funtion is available in VB6 only. So here's the working code (with custom SplitArray function):
Code:
Public Function SplitArray(pString As String, pDelimeter As String) As Variant
Dim iPos As Integer
Dim arrTemp()
Dim i As Integer
Dim strTemp As String
strTemp = pString
iPos = InStr(strTemp, pDelimeter)
Do Until strTemp = ""
ReDim Preserve arrTemp(i)
If InStr(strTemp, pDelimeter) Then
arrTemp(i) = Trim(Left(strTemp, InStr(strTemp, pDelimeter) - 1))
strTemp = Mid(strTemp, InStr(strTemp, pDelimeter) + 1)
Else
arrTemp(i) = Trim(strTemp)
strTemp = ""
End If
i = i + 1
Loop
SplitArray = arrTemp
End Function
Private Sub Command1_Click()
Dim xColumnHeader As ColumnHeader
Dim xListItem As ListItem
Dim intFFN As Integer
Dim strPath As String
Dim strBuffer As String
Dim arrString As Variant
Dim i As Integer
With ListView1
.View = lvwReport
Set xColumnHeader = .ColumnHeaders.Add(, , "Protocol")
Set xColumnHeader = .ColumnHeaders.Add(, , "Local Address")
Set xColumnHeader = .ColumnHeaders.Add(, , "Foreign Address")
Set xColumnHeader = .ColumnHeaders.Add(, , "State")
End With
strPath = "d:\Text.txt"
intFFN = FreeFile
Open strPath For Input As intFFN
Do Until EOF(intFFN)
Line Input #1, strBuffer
arrString = SplitArray(strBuffer, " ")
With ListView1
Set xListItem = .ListItems.Add(, , arrString(0))
For i = 1 To UBound(arrString)
xListItem.SubItems(i) = arrString(i)
Next
End With
Loop
Close #intFFN
End Sub
------------------
Serge
Senior Programmer Analyst
[email protected]
[email protected]
ICQ#: 51055819
-
Feb 21st, 2000, 01:47 AM
#5
Let's try a little bit different approach:
Code:
Public Function SplitArray(pString As String, pDelimeter As String, pArr() As String) As Boolean
Dim iPos As Integer
Dim arrTemp() As String
Dim i As Integer
Dim strTemp As String
Dim iTempUbound As Integer
On Error Resume Next
strTemp = pString
iPos = InStr(strTemp, pDelimeter)
Do Until strTemp = ""
ReDim Preserve arrTemp(i)
If InStr(strTemp, pDelimeter) Then
arrTemp(i) = Trim(Left(strTemp, InStr(strTemp, pDelimeter) - 1))
strTemp = Mid(strTemp, InStr(strTemp, pDelimeter) + 1)
Else
arrTemp(i) = Trim(strTemp)
strTemp = ""
End If
i = i + 1
Loop
iTempUbound = UBound(arrTemp)
If Err.Number = 0 Then
pArr = arrTemp
SplitArray = True
End If
End Function
Private Sub Command1_Click()
Dim xColumnHeader As ColumnHeader
Dim xListItem As ListItem
Dim intFFN As Integer
Dim strPath As String
Dim strBuffer As String
Dim arrString() As String
Dim i As Integer
With ListView1
.View = lvwReport
Set xColumnHeader = .ColumnHeaders.Add(, , "Protocol")
Set xColumnHeader = .ColumnHeaders.Add(, , "Local Address")
Set xColumnHeader = .ColumnHeaders.Add(, , "Foreign Address")
Set xColumnHeader = .ColumnHeaders.Add(, , "State")
End With
strPath = "d:\Text.txt"
intFFN = FreeFile
Open strPath For Input As intFFN
Do Until EOF(intFFN)
Line Input #1, strBuffer
If SplitArray(strBuffer, " ", arrString) = True Then
With ListView1
Set xListItem = .ListItems.Add(, , arrString(0))
For i = 1 To UBound(arrString)
xListItem.SubItems(i) = arrString(i)
Next
End With
End If
Loop
Close #intFFN
End Sub
Although, the first solution is working fine on my machine.
------------------
Serge
Senior Programmer Analyst
[email protected]
[email protected]
ICQ#: 51055819
-
Feb 21st, 2000, 12:12 PM
#6
Thread Starter
Junior Member
The source code was got compile error again
in the line
arrString = SplitArray(strBuffer, " ")
with the error message
Can't assign to array
What happen with it?
-
Feb 21st, 2000, 12:35 PM
#7
Guess you forgot to change
Dim arrString() As String
to
Dim arrString As Variant
------------------
Vincent van den Braken
EMail: [email protected]
ICQ: 15440110
Homepage: http://www.azzmodan.demon.nl
-
Feb 21st, 2000, 12:48 PM
#8
Thread Starter
Junior Member
There is an error in the line
If SplitArray(strBuffer, " ", arrString) = True Then
with the message
compile error
type mismatch:array or user-defined type expected
ps : For Serge,
thanks you because wasting your time for my module.
-
Feb 21st, 2000, 12:56 PM
#9
Thread Starter
Junior Member
I try that before
when i change it into
Dim arrString As Variant
a runtime error '9' occur
with message
subscript out of range
what it mean then???
-
Feb 22nd, 2000, 12:36 PM
#10
How about this. Give me your Email address and I'll send you this code in a module. So you can run exactly what I run.
------------------
Serge
Senior Programmer Analyst
[email protected]
[email protected]
ICQ#: 51055819
-
Feb 22nd, 2000, 11:40 PM
#11
Even though I sent you an email with the solution, I still want to post it here so whoever else want it to use it.
VB5 cannot assign to array like this: Array1 = Array2 if those arrays are not variant data type. So here is the working SplitArray function that was giving the problem.
Code:
Private Function SplitArray(pString As String, pDelimeter As String, pArr() As String) As Boolean
Dim iPos As Integer
Dim arrTemp() As String
Dim i As Integer
Dim strTemp As String
Dim iTempUbound As Integer
On Error Resume Next
strTemp = pString
iPos = InStr(strTemp, pDelimeter)
Do Until strTemp = ""
ReDim Preserve arrTemp(i)
If InStr(strTemp, pDelimeter) Then
arrTemp(i) = Trim(Left(strTemp, InStr(strTemp, pDelimeter) - 1))
strTemp = Mid(strTemp, InStr(strTemp, pDelimeter) + 1)
Else
arrTemp(i) = Trim(strTemp)
strTemp = ""
End If
i = i + 1
Loop
iTempUbound = UBound(arrTemp)
If Err.Number = 0 Then
ReDim pArr(UBound(arrTemp))
For i = LBound(arrTemp) To UBound(arrTemp)
pArr(i) = arrTemp(i)
Next
SplitArray = True
End If
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|