Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I extract some parameters from raw file i.e from notepad(*.txt file) & convert the same in excel?

eg. I have raw file somewhat like this:
FIELD REPORTING COMMAND <TU_>
<

FIELD REPORTING COMMAND <TU_>
<

FIELD REPORTING COMMAND <TU_>
<

FIELD REPORTING COMMAND <TU_>
<

FIELD REPORTING COMMAND <TU_>
<

FIELD REPORTING COMMAND <TU_>
< ZZZZ;
END OF DIALOGUE SESSION

[Connection to 10.131.64.102 closed by foreign host]
rtrwb1>telnet 10.131.0.102
Trying 10.131.0.102 ... Open
GNFMN1
GNFMNO


ENTER USERNAME < GNFMN1
ENTER PASSWORD < ******
MSCi      ASN_GMSC                  2010-10-08  13:05:12


                       WELCOME TO THE DX 200 SERIES DIALOGUE


MAIN LEVEL COMMAND <___>
< ZDRI;

LOADING PROGRAM VERSION 2.10-0
EXECUTION STARTED

MSCi      ASN_GMSC                  2010-10-08  13:05:16

INPUT      STATE      USED INPUT  PRIORITY
----- --------------- ---------- ----------
2M1   CONNECTED           -          3
2M2   CONNECTED           -          2
2M3   CONNECTED           -          5
2M4   CONNECTED           -          4
FS1   CONNECTED          FS1         7
FS2   CONNECTED           -          6
SYNCHRONIZATION UNIT WORKING MODE ......... HIERARCHIC SYNCHRONIZATION
FUNCTION AUTOMATIC RETURN FROM PLESIOCHRONOUS OPERATION ..........  ON
FUNCTION AUTOMATIC USE OF REPAIRED INPUTS ........................  ON
SYNCHRONIZATION UNIT    0 OSCILLATOR CONTROL WORD VALUE .......  32110
SYNCHRONIZATION UNIT    1 OSCILLATOR CONTROL WORD VALUE .......  30146
SYNCHRONIZATION UNIT    0 OSCILLATOR CONTROL MODE ............. NORMAL
SYNCHRONIZATION UNIT    1 OSCILLATOR CONTROL MODE ............. NORMAL
TIMER: SYNCHRONIZATION SIGNAL MALFUNCTION TOLERANCE TIME ...     5 MIN
TIMER: REPAIRED SYNCHRONIZATION INPUT OBSERVATION TIME .....    10 MIN
COMMAND EXECUTED


Out of the same above raw file I need to display columns in excel by use of browse button in which it would ask for path of raw file which would be displayd in in neighbouring textbox & then on clicking Process button it will open up a excel file & display o/p as:

NE Name:ASN_GMSC
Synchronisation Unit: 0 Oscillator Control Word value: 32110
Synchronisation Unit: 1 Oscillator Control Word value: 30146
Timer:13:05:16
Date:2010-10-08

Only these fields are required.
Please update me in code as above required one
Posted
Updated 15-Feb-11 19:43pm
v5
Comments
Dalek Dave 26-Nov-10 4:28am    
Edited for Grammar and Readability.

1 solution

I can't uderstand output, so i will show how to open and read *.txt file line by line using Open dialog box.

Sub GetDX200Data()
Dim sFileName As String, iNumFile As Integer
Dim sTmp As String, dstWsh As Worksheet
Dim iRow As Long

'On error goto Error handler
On Error GoTo Err_GetDX200Data

'set variable for destination worksheet
Set dstWsh = ThisWorkbook.Worksheets(1)
'get *.txt file name
sFileName = GetMyFileName()
'in case of Cancel button was pressed
If sFileName = "" Then GoTo Exit_GetDX200Data

'start import from first row
iRow = 1
'to open *.txt file, get number
iNumFile = FreeFile()
'open *.txt file
Open sFileName For Input As iNumFile
    'until it's not then end of file
    Do While Not EOF(iNumFile)
        'read line to variable sTmp
        Line Input #iNumFile, sTmp
        'insert data into cell
        dstWsh.Range("A" & iRow) = sTmp
        'increase counter
        iRow = iRow + 1
    Loop
'close file
Close #iNumFile

Exit_GetDX200Data:
    On Error Resume Next
    'free memory used for  object variable: worksheet
    Set dstWsh = Nothing
    Exit Sub

Err_GetDX200Data:
    MsgBox Err.Description, vbExclamation, Err.Number
    'goto Exit
    Resume Exit_GetDX200Data
End Sub

And function used for call Open dialog box
'return: file name with path
Function GetMyFileName() As String
Dim sTmp As Variant 'subtype: String

sTmp = Application.GetOpenFilename("Text Files (*.txt),*.txt", 0, "Open DX file...", "Open", False)
'in case of 'Cancel' pressed
If CStr(sTmp) = CStr(False) Then sTmp = ""
GetMyFileName = CStr(sTmp)

End Function
 
Share this answer
 
Comments
kom1234 22-Feb-11 0:10am    
please update my regarding my updations in above question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900