-
Oct 5th, 2017, 03:48 AM
#1
Thread Starter
Member
Word vector with repited words
Hi! I am programming the following script:
I have a Textbox where I read some MAC directions. Then I have to order the MACs and enumerate it without repetition in one table (only one time each MAC)
For instance, if the MACs are:
F0:E12:C3:B4:A5
B1:F26:C1:B4:A5
F0:E12:C3:B4:A5
F0:E12:C3:B4:A5
A3:E12:C3:B4:A5
The result in the table would be:
1 F0:E12:C3:B4:A5
2 B1:F26:C1:B4:A5
3 A3:E12:C3:B4:A5
I have this code but it does not work
Code:
Private Sub Update_MacTable_Click()
Grid2.Visible = True
Grid2.Cols = 4
Grid2.Clear
Grid2.TextMatrix(0, 0) = "Device"
Grid2.TextMatrix(0, 1) = "MAC"
Dim i As Integer
Dim j, k, n As Integer
Dim mArray() As String
mArray = Split(txtOut.text, "<<EOS>>") 'Primero se divide el texto en varios textos separados por el <EOS>> --> Diferentes dispositivos
Dim sString, sString2 As String
Dim mArray2() As String
Dim Rowcounter As Integer
Dim Hora As String
Dim MAC_VECTOR() As String
Rowcounter = 0
Grid2.Rows = 50
For i = 0 To UBound(mArray)
sString = mArray(i) 'sString es un bloque de texto que llega hasta <<EOS>>
mArray2 = Split(mArray(i), vbCrLf) 'Cojo este bloque de texto y lo divido en lĂneas
For k = 0 To UBound(mArray2)
sString2 = mArray2(k)
If Mid(sString2, 4, 4) = "mac-" Then
Rowcounter = Rowcounter + 1
j = InStrRev(sString2, "=")
Grid2.TextMatrix(Rowcounter, 0) = Rowcounter
For n = 0 To UBound(MAC_VECTOR)
MAC_VECTOR(n) = Mid(sString2, j + 1)
If MAC_VECTOR(Rowcounter - 1) = MAC_VECTOR(n) Then
Grid2.TextMatrix(Rowcounter, 0) = n + 1
else
Grid2.TextMatrix(Rowcounter, 0) = Rowcounter
End If
Next n
Grid2.TextMatrix(Rowcounter, 1) = Mid(sString2, j + 1) '
End If
Next k
Next i
Grid2.ColAlignment(1) = 2
End Sub
Thanks!
-
Oct 5th, 2017, 05:51 AM
#2
Re: Word vector with repited words
Hi,
here a sample that opens a Textfile, then checks for Duplicates,
then writes a new File without duplicates.
Code:
Private Sub Command1_Click()
Set cn = New ADODB.Connection
With cn
.Open "Provider=Microsoft.Jet" _
& ".OLEDB.4.0;Data Source= c:\" _
& ";Extended Properties=""text;HDR=YES;FMT=Delimited"""
End With
Set rs = New Recordset
rs.CursorLocation = adUseClient
'select Distinct Names from file
strSQL = "Select Distinct Name from TestFile.txt"
rs.Open strSQL, cn, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = rs
Dim FNr As Integer
Dim strPath As String
strPath = "C:\outputtest.txt"
FNr = FreeFile
Open strPath For Output As FNr
Do While rs.EOF = False
If Not IsNull(rs!Name) Then Print #FNr, rs!Name
'create Optputfile without Duplicate
rs.MoveNext
DoEvents
Loop
Close #FNr
rs.Close
Set rs = Nothing
End Sub
regards
Chris
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Oct 5th, 2017, 06:03 AM
#3
Re: Word vector with repited words
Here's an Old-School, Sledgehammer approach:
Code:
Dim sList as String : sList = "|"
Dim eLine as Variant ' String
For Each eLine in Split( Text1.Text, vbCrLf )
' If we've not seen this MAC before ...
If ( 0 = Instr( sList, "|" & eLine & "|" ) ) Then
' ... process it, then ...
DoSomethingWith eLine
' ... make a note that we've seen this one.
sList = sList & eLine & "|"
End If
Next
Regards, Phill W.
-
Oct 7th, 2017, 09:56 AM
#4
Re: Word vector with repited words
And yet another simplistic method using a collection. This is not case-sensitive and shouldn't be when comparing mac addresses.
Code:
Dim c As Collection, lIndex As Long
Set c = New Collection
On Error Resume Next
For lIndex = 0 to UBound(yourArray)
x = c.Item(yourArray(lIndex))
If Err Then
Err.Clear
c.Add lIndex, yourArray(lIndex)
End If
Next
On Error GoTo 0
' the collection now has indexes into the array items, no duplicates
For lIndex = 1 to c.Count
' do what you want with array item yourArray(c.Item(lIndex))
Next
And there are probably a dozen or more other methods of filtering out duplicate data. A simple search in this forum should have proved useful.
-
Oct 9th, 2017, 03:28 PM
#5
Thread Starter
Member
Re: Word vector with repited words
Thank you for your ideas. I will use it
Tags for this Thread
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
|