Need to display part of a string in flexgrid

I have an msflexgrid on my project within a form called Blocked Sites.  If you select a date range, it displays the sites within the grid, but the problem is that the content looks confusing.  I only need the information to the right of the :  on each record so that only the website is displayed.

Is it possible to edit the string to display only this information in the flexgrid?
CB.zip
al4629740Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Private Sub Command2_Click()
Dim iFiles As Long, sFirstFile$, sLastFile$, sFile$
Dim f As Integer
Dim strLine As String
Dim lngLines As Long
Dim arrKeys() As String
Dim bFound As Boolean
Dim bFirst As Boolean
Dim intCount As Integer
Dim strParts() As String
Dim intTot As Integer
Dim intPos As Integer
Dim strText As String

bFirst = True
f = FreeFile

MSFlexGrid1.Cols = 3
MSFlexGrid1.ColWidth(0) = 800
MSFlexGrid1.ColWidth(2) = 1200
MSFlexGrid1.ColWidth(1) = MSFlexGrid1.Width - (MSFlexGrid1.ColWidth(0) + MSFlexGrid1.ColWidth(2) + 360)
MSFlexGrid1.FixedCols = 0
MSFlexGrid1.FixedRows = 1
MSFlexGrid1.TextMatrix(0, 0) = "#Blocked"
MSFlexGrid1.TextMatrix(0, 1) = "Site"
MSFlexGrid1.TextMatrix(0, 2) = "IP Address"

sFirstFile = Format(DTPicker1.Value, "yymmdd")  'May 22, 2014  = 140522
sLastFile = Format(DTPicker2.Value, "yymmdd")   'June 15, 2014 = 140615
intCount = 0
ReDim arrKeys(1, 0)
For iFiles = Val(sFirstFile) To Val(sLastFile)  'loop will proceed if starting number <= ending number
   ' this is required since we're reading the YY first...
   sFile = Right(iFiles, 4) & Left(iFiles, 2)     'take the YY and put it at the end as in 140522 to 052214
   '// now construct the current filename FQN
   sFile = App.Path & "\test\" & sFile & ".txt"
   '// skip to the next file loop if current file does not exist
    
      If (Dir(sFile) <> "") Then
      Open sFile For Input As #f
      Do Until EOF(f)
         Line Input #f, strLine
         bFound = False
         If InStr(strLine, "BlockedIP") > 0 Then
            intTot = intTot + 1
            strParts = Split(strLine, "keyword")
            For lngLines = 0 To intCount - 1
               If arrKeys(1, lngLines) = strParts(1) Then
                  arrKeys(0, lngLines) = arrKeys(0, lngLines) + 1
                  bFound = True
                  Exit For
               End If
            Next
            If Not bFound Then
               If Not bFirst Then
                  ReDim Preserve arrKeys(1, intCount)
               End If
               arrKeys(1, intCount) = strParts(1)
               arrKeys(0, intCount) = 1
               bFirst = False
               intCount = intCount + 1
            End If
         End If
      Loop
      Close
   End If
Next iFiles

For lngLines = 0 To intCount - 1
    MSFlexGrid1.TextMatrix(lngLines + 1, 0) = arrKeys(0, lngLines)
    strText = Split(arrKeys(1, lngLines), " -> ")(0)
    intPos = InStr(1, strText, ":")
    MSFlexGrid1.TextMatrix(lngLines + 1, 1) = Mid$(strText, intPos + 2)
    MSFlexGrid1.TextMatrix(lngLines + 1, 2) = Split(arrKeys(1, lngLines), " -> ")(1)
    MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
Next

MSFlexGrid1.Rows = MSFlexGrid1.Rows - 1

MSFlexGrid1.Col = 2
MSFlexGrid1.ColSel = 0
MSFlexGrid1.Sort = flexSortGenericDescending


'Debug.Print "Total number found " & intTot
'Debug.Print "Total reported "; intIW
End Sub

Open in new window


Entries like the following wind up like 31.media.tumblr.com (right-justified because it starts with numbers)
BlockedIP response sent, keyword tumblr.com: 31.media.tumblr.com. -> 192.168.1.100

In cases like that would you like the .31 removed?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
al4629740Author Commented:
it might be good if we can consolidate the number of times of the media.tumblr.com  into one.  for example

5     31.media.tumblr.com  192.168.1.100
2     24.media.tumblr.com  192.168.1.100  
4     42.media.tumblr.com   192.168.1.100

would translate to:

11   media.tumblr.com  192.168.1.100
0
Martin LissOlder than dirtCommented:
Is it possible that there could be other sites like that or is it specific to media.tumblr?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

al4629740Author Commented:
I believe it is entirely possible for a site to start with a number, so we may want to stick with the format below...unless you have any other ideas

4     42.media.tumblr.com   192.168.1.100
0
Martin LissOlder than dirtCommented:
Well what you propose is certainly the easiest since that's what it does now, but another alternative is to summarize all sites that start with numbers into sets. In other words if the input contained

5     31.media.tumblr.com  192.168.1.100
2     24.media.tumblr.com  192.168.1.100  
4     42.media.tumblr.com  192.168.1.100
1     11.blah.yada.com  192.123.1.100
2     22.blah.yada.com  192.123.1.100  
3     33.blah.yada.com  192.123.1.100

the grid would show
11   media.tumblr.com  192.168.1.100
6   blah.yada.com   192.123.1.100
0
al4629740Author Commented:
I prefer the second one:

11   media.tumblr.com  192.168.1.100
6   blah.yada.com   192.123.1.100


However, what would happen if the site's name was   123.com   or 123.test.com
0
Martin LissOlder than dirtCommented:
Good catch, that would be a problem. However if you want there could be an internal "summarization" table that would indicate which sites should be summarized, and for now it would contain only "media.tumblr.com". In the future (in another question) a method for you to maintain that table could be implemented.

Let me know if for now you want me to summarize  "media.tumblr.com".
0
al4629740Author Commented:
I think it would be good not to summarize at this point due to the fact it will require too much unnecessary tracking.  If it appears that too many of those sites get "out of control" then maybe later.
0
Martin LissOlder than dirtCommented:
OK so is there  anything else you need here?
0
al4629740Author Commented:
Yes, but its not related to this question.  I'll post it later.  It has to do with if I choose a long date range I get an error.
0
Martin LissOlder than dirtCommented:
OK, so please don't forget to accept my answer here.
0
al4629740Author Commented:
Thought i graded already.  sorry
0
al4629740Author Commented:
One more thing.  Some of the records are not left justified.  How do I get all the records to be left justified in the grid?  New Q?
0
Martin LissOlder than dirtCommented:
They are the ones that start with numbers so they are normally right-justified, but I'll see what I can do.
0
Martin LissOlder than dirtCommented:
I added lines 76 to 78.
Private Sub Command2_Click()
Dim iFiles As Long, sFirstFile$, sLastFile$, sFile$
Dim f As Integer
Dim strLine As String
Dim lngLines As Long
Dim arrKeys() As String
Dim bFound As Boolean
Dim bFirst As Boolean
Dim intCount As Integer
Dim strParts() As String
Dim intTot As Integer
Dim intPos As Integer
Dim strText As String

bFirst = True
f = FreeFile

MSFlexGrid1.Cols = 3
MSFlexGrid1.ColWidth(0) = 800
MSFlexGrid1.ColWidth(2) = 1200
MSFlexGrid1.ColWidth(1) = MSFlexGrid1.Width - (MSFlexGrid1.ColWidth(0) + MSFlexGrid1.ColWidth(2) + 360)
MSFlexGrid1.FixedCols = 0
MSFlexGrid1.FixedRows = 1
MSFlexGrid1.TextMatrix(0, 0) = "#Blocked"
MSFlexGrid1.TextMatrix(0, 1) = "Site"
MSFlexGrid1.TextMatrix(0, 2) = "IP Address"

sFirstFile = Format(DTPicker1.Value, "yymmdd")  'May 22, 2014  = 140522
sLastFile = Format(DTPicker2.Value, "yymmdd")   'June 15, 2014 = 140615
intCount = 0
ReDim arrKeys(1, 0)
For iFiles = Val(sFirstFile) To Val(sLastFile)  'loop will proceed if starting number <= ending number
   ' this is required since we're reading the YY first...
   sFile = Right(iFiles, 4) & Left(iFiles, 2)     'take the YY and put it at the end as in 140522 to 052214
   '// now construct the current filename FQN
   sFile = App.Path & "\test\" & sFile & ".txt"
   '// skip to the next file loop if current file does not exist
    
      If (Dir(sFile) <> "") Then
      Open sFile For Input As #f
      Do Until EOF(f)
         Line Input #f, strLine
         bFound = False
         If InStr(strLine, "BlockedIP") > 0 Then
            intTot = intTot + 1
            strParts = Split(strLine, "keyword")
            For lngLines = 0 To intCount - 1
               If arrKeys(1, lngLines) = strParts(1) Then
                  arrKeys(0, lngLines) = arrKeys(0, lngLines) + 1
                  bFound = True
                  Exit For
               End If
            Next
            If Not bFound Then
               If Not bFirst Then
                  ReDim Preserve arrKeys(1, intCount)
               End If
               arrKeys(1, intCount) = strParts(1)
               arrKeys(0, intCount) = 1
               bFirst = False
               intCount = intCount + 1
            End If
         End If
      Loop
      Close
   End If
Next iFiles

For lngLines = 0 To intCount - 1
    MSFlexGrid1.TextMatrix(lngLines + 1, 0) = arrKeys(0, lngLines)
    strText = Split(arrKeys(1, lngLines), " -> ")(0)
    intPos = InStr(1, strText, ":")
    MSFlexGrid1.TextMatrix(lngLines + 1, 1) = Mid$(strText, intPos + 2)
    MSFlexGrid1.TextMatrix(lngLines + 1, 2) = Split(arrKeys(1, lngLines), " -> ")(1)
    'new
    MSFlexGrid1.Row = lngLines
    MSFlexGrid1.Col = 1
    MSFlexGrid1.CellAlignment = flexAlignLeftBottom 'flexAlignLeftCenter

    MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
Next

MSFlexGrid1.Rows = MSFlexGrid1.Rows - 1

MSFlexGrid1.Col = 2
MSFlexGrid1.ColSel = 0
MSFlexGrid1.Sort = flexSortGenericDescending


'Debug.Print "Total number found " & intTot
'Debug.Print "Total reported "; intIW
End Sub

Open in new window

0
al4629740Author Commented:
Excellent.  Thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.