Results 1 to 8 of 8

Thread: Notepad to VB

  1. #1
    Join Date
    Jun 2004
    Posts
    23

    Unanswered: Notepad to VB

    I have this logfile.. which contain alot of Mac Addresses as well as Current Signals, Time, Throughput and Packet Retry.

    Mac Address and Time are list box while the rest are textboxes.

    When I click on a button, it will display every data that is in the textfile.

    The Mac Address listbox is for me to choose the different Mac Address. Eg. When I choose Mac Address 11:22:33:44:55, it will show me the Time, Throughput, Signal Strength and Packet Retry of 11:22:33:44:55.

    And when I choose the Time in the listbox let say 12:52:21 PM, it will show me the Mac Address, Throughput, Signal Strength and Packet Retry that is associate with that time.

    The default value that appear first in all the boxes should be the first data that appear in the textfile.

    See attachment for textfile.

    Can anyone assist me?
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2003
    Location
    Delft, The Netherlands (EU)
    Posts
    447
    The more stable solution would be to define an ODBC datasource, but if your file isn't very large (< 100.000 rows), I'd read the file into memory by defining an array of a type according to your information.

    Hope this helps
    Make everything as simple as possible, but not simpler! - A. Einstein
    DB Problems? DB Explorer, BTrieve Re-engineering, DB Conversions & ETL? Conversion Tool

  3. #3
    Join Date
    Jun 2004
    Posts
    23
    yah i thought abt that too .. but i wasn't too sure on making the mac address appear in the listbox .. i got a rough diea on how it will appear in the textbox but not the listbox ..

  4. #4
    Join Date
    Aug 2003
    Location
    Delft, The Netherlands (EU)
    Posts
    447
    I don't get your problem. You have to use the listbox's method AddItem, adding the MAC address as string, so what's the point?
    Make everything as simple as possible, but not simpler! - A. Einstein
    DB Problems? DB Explorer, BTrieve Re-engineering, DB Conversions & ETL? Conversion Tool

  5. #5
    Join Date
    Apr 2006
    Posts
    12
    I'm not quite understanding where you're having a problem - however I have a suggestion. Since you're working with a text file I would look into the FSO (File System Object). I've used it here and there and it works great with manipulating/retrieving info from a text file. Hope this helps.

  6. #6
    Join Date
    Mar 2006
    Posts
    163
    Why not use a multicolumn listbox with all the information?

    You could hide the columns you don't want to see but use them to display the information when a value is selected.

  7. #7
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Quote Originally Posted by norie
    Why not use a multicolumn listbox with all the information?

    You could hide the columns you don't want to see but use them to display the information when a value is selected.
    My approach would be to open an ado recordset, and, using the microsoft odbc text driver, populate the recordset.

    Then, bind a datagrid to the recordset.

    When you select a column on the datagrid, save the column (field) name you selected, set the datagrid recordset to nothing, sort the recordset based on the selection you just made, and then rebind the datagrid.

    Note: You would need to drop the first line of the file, though, before you could set up the text driver to accept this file. The simplest way would be to copy the file with VB, a line at a time, and just "skip" the first line.

    Also, since the data is tab delimited, you would also need to create a schema.ini file for the text driver to recognize the contents.
    Last edited by loquin; 04-10-06 at 14:29.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  8. #8
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Actually, you won't need to unbind/rebind the datagrid.

    Here's a little something I threw together to illustrate the technique.

    Add a datagrid to the form; rename it to dg.
    add a picture box to the form, change its alignment it to the bottom & rename it to picStat.

    Code:
    Option Explicit
    
      Const sCon As String = "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
        "Dbq=~PATH~;Extensions=asc,csv,tab,txt;DefaultDir=C:\; Extended Properties=TEXT"
      Dim rs As ADODB.Recordset
      Dim cn As ADODB.Connection
      Dim strFileData As String   ' Retain the first line of the file...
      
      Dim strConn As String
      
    Private Sub dg_Click()
      Static iCol As Integer
      Static iColLast As Integer
      Static blReverseSort As Boolean
      
      If dg.SelStartCol >= 0 Then
        iColLast = iCol
        iCol = dg.SelStartCol
      End If
      
      If iCol <> iColLast Then
        rs.Sort = "[" & rs.Fields(iCol).Name & "]"
        blReverseSort = False
      Else
        If blReverseSort Then
          rs.Sort = "[" & rs.Fields(iCol).Name & "]" & " DESC"
        Else
          rs.Sort = "[" & rs.Fields(iCol).Name & "]"
        End If
        blReverseSort = Not (blReverseSort)
      End If
    End Sub
    
      Private Sub Form_Load()
        Dim iFN1 As Integer
        Dim iFN2 As Integer
        Dim N As Integer
        
        Dim strLine As String
        
        ' Copy the source file to a temporary format, without the first line...
        iFN1 = FreeFile
        Open "C:\NodeStatistics.txt" For Input As #iFN1
        iFN2 = FreeFile
        Open "C:\NodeStatistics1.Txt" For Output As #iFN2
        
        N = 1
        Do While Not EOF(iFN1)
          If N > 1 Then
            Line Input #iFN1, strLine   ' Copy the line
            Print #iFN2, strLine
          Else
            Line Input #iFN1, strFileData ' save the line
          End If
          N = N + 1
        Loop
        
        Me.picStat.Cls
        Me.picStat.Print N - 3 & " records in data file " & "C:\NodeStatistics1.Txt"
        
        Close iFN2
        Close iFN1
      
        ' Now, open the file with ADO
        strConn = Replace(sCon, "~PATH~", "C:\")
        Set cn = New ADODB.Connection
        cn.CursorLocation = adUseClient
        
        cn.Open strConn
        
        Set rs = New ADODB.Recordset
        rs.Open "Select * from NodeStatistics1.Txt", cn
    
        ' and display the file
        rs.Sort = rs.Fields(0).Name
        Set Me.dg.DataSource = rs
        Me.dg.HeadFont.Bold = True
        Me.dg.HeadFont.Size = Me.dg.Font.Size + 2
      End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
      rs.Close
      Set rs = Nothing
      
      cn.Close
      Set cn = Nothing
    End Sub
    You can sort by the column by selecting the column header.

    Note: The use of tabs as the delimiter is fine, but, you need to supply schema information to the text driver, in the same folder as the source file. This file must be named Schema.Ini.

    Here is an example Schema.ini file which provides the schema for your particular format.
    Code:
    [NodeStatistics1.Txt]
    FORMAT = TabDelimited
    ColNameHeader = True
    MaxScanRows=10
    The first line contains the name of the source file, inside square brackets. It is required. The second line specifies a tab delimited file, the third line specifies that you are providing column headers as the first line of the source file, and finally, the last line specifies that the text driver will scan the first 10 lines of the source file to determine the field data type definition. Ref msdn
    Last edited by loquin; 04-11-06 at 14:12.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •