Results 1 to 13 of 13

Thread: Pls help..portion of text search & produce output in VB

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    20

    Pls help..portion of text search & produce output in VB

    Hello,

    Pls help me out of my problem while doing the foloowing stuff.

    I have a text file which contains the texts in following format...

    UMTS
    name abc
    street sno road
    ph no 9976543234
    code a34
    location india


    UMTS
    name def
    street sno road
    ph no 9744677867
    code a32
    location india


    UMTS
    name abc
    street sno road
    ph no 9976543234
    code a34
    location india


    UMTS
    name ghk
    street bill road
    ph no 9832373297
    code a77
    location germany



    UMTS
    name abc
    street sno road
    ph no 9976543234
    code a34
    location india




    UMTS
    name abc
    street sno road
    ph no 9904435677
    code a34
    location india


    UMTS
    name abc
    street sno road
    ph no 9976543234
    code a34
    location india

    The name of the text file is record.txt wheree these datas are there.
    I want that VB code should search the ph no in entire text , find the every occurences throughout the text & select the portion (starting from UMTS to location) for that particular number & produce the out put to another text file called recordout.txt.

    i.e the output file should contain in following format

    UMTS
    name abc
    street sno road
    ph no 9976543234
    code a34
    location india


    UMTS
    name abc
    street sno road
    ph no 9976543234
    code a34
    location india


    UMTS
    name abc
    street sno road
    ph no 9976543234
    code a34
    location india


    UMTS
    name abc
    street sno road
    ph no 9976543234
    code a34
    location india

    Please note that for each paragraph UMTS is common starting point. I am unable write the codes. Please help me out of this.

    Thanking you............

    Sajib

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Pls help..portion of text search & produce output in VB

    I would start off by defining a UDT representing the data items that are repeated in the Input.
    Code:
    Option Explicit
    
    Private Type UMTS_Record
        UMTS_Name As String
        UMTS_Street As String
        UMTS_Phone As String
        UMTS_Code As String
        UMTS_Location As String
    End Type
    Then create a dynamic UDT Array into which the data is going to be put.
    Code:
    Private udtUMTS() As UMTS_Record
    Then read the records and populate the UDT, ignoring any blank lines
    Code:
    Private Sub ProcessInput()
    '
    ' Subroutine Reads and Processes the Input file
    ' Populates a Dynamic UDT Array
    '
    Dim intFileIn As Integer
    Dim intI As Integer
    Dim intJ As Integer
    Dim strData As String
    Dim strFileIn As String
    ReDim udtUMTS(100)
    strFileIn = "c:\record.txt"
    intFileIn = FreeFile
    Open strFileIn For Input As intFileIn
    Do
        Line Input #intFileIn, strData
        If strData <> Space(Len(strData)) And strData <> vbNullString Then
            Select Case intJ
                Case 0 ' UMTS - Ignore
                
                Case 1 ' name
                    udtUMTS(intI).UMTS_Name = Mid$(strData, 6)
                Case 2 ' street
                    udtUMTS(intI).UMTS_Street = Mid$(strData, 8)
                Case 3 ' ph no
                    udtUMTS(intI).UMTS_Phone = Mid$(strData, 7)
                Case 4 ' code
                    udtUMTS(intI).UMTS_Code = Mid$(strData, 7)
                Case 5 ' location
                    udtUMTS(intI).UMTS_Location = Mid(strData, 10)
            End Select
            intJ = intJ + 1
            '
            ' After 6 records have been processed re-set the record indicator
            ' and increment the udt element number
            '
            If intJ > 5 Then
                intJ = 0
                intI = intI + 1
            End If
            '
            ' If we've consumed all the elements then
            ' add another 100
            '
            If intI > UBound(udtUMTS) Then ReDim Preserve udtUMTS(intI + 100)
        End If
    Loop Until EOF(intFileIn)
    Close (intFileIn)
    '
    ' Reduce the Array to the correct size
    '
    ReDim Preserve udtUMTS(intI - 1)
    End Sub
    Now loop through the UDT Array looking for the ph no required and write the UDT elements that have matching 'ph no's to the output file
    Code:
    Private Sub DoSearch(strLookFor As String)
    '
    ' Subroutine searches udtUMTS array for strLookFor in the UMTS_Phone item
    '
    Dim intI As Integer
    Dim intFileOut As Integer
    Dim intMatch As Integer
    Dim strFileOut As String
    intFileOut = FreeFile
    strFileOut = "c:\recordout.txt"
    Open strFileOut For Output As intFileOut
    For intI = LBound(udtUMTS) To UBound(udtUMTS)
        If udtUMTS(intI).UMTS_Phone = strLookFor Then
            Print #intFileOut, "UMTS"
            Print #intFileOut, "name " & udtUMTS(intI).UMTS_Name
            Print #intFileOut, "street " & udtUMTS(intI).UMTS_Street
            Print #intFileOut, "ph no " & udtUMTS(intI).UMTS_Phone
            Print #intFileOut, "code " & udtUMTS(intI).UMTS_Code
            Print #intFileOut, "location " & udtUMTS(intI).UMTS_Location
            Print #intFileOut,
            intMatch = intMatch + 1
        End If
    Next intI
    Close intFileOut
    MsgBox "Search Complete" & vbCrLf & CStr(intMatch) & " Matches Found and written to " & strFileOut
    End Sub
    Last edited by Doogle; Aug 29th, 2010 at 02:05 AM.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    20

    Re: Pls help..portion of text search & produce output in VB

    Hi Doggle ..Thank you very much for the code..

    I have created a coomand button under which I have called the 2 founctions that u have posted..there is a text box where I put the ph no..

    But the problem is that whenevr i run the program. no matches found...
    Actually my input file contains the data in the following way..

    UMTS
    name abc [actually there are so many spaces between name &abc ]
    street sno road [so many spaces between street & road]
    ph no 9976543234[so many spaces between ph no & 9976543234]
    code a34 [so many spaces between code & a34]
    location india [so many spaces between location & india]


    I think for this reason no matches are being found. So i am attaching the record.txt file. Now see the file & pls tell me how to get the dats in similar format in recordout.txt

    Thnkx & Rgds
    Attached Files Attached Files

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Pls help..portion of text search & produce output in VB

    OK, you need to get rid of the leading spaces
    Code:
            Select Case intJ
                Case 0 ' UMTS - Ignore
                
                Case 1 ' name
                    udtUMTS(intI).UMTS_Name = LTrim$((Mid$(strData, 6))
                Case 2 ' street
                    udtUMTS(intI).UMTS_Street = LTrim$(Mid$(strData, 8))
                Case 3 ' ph no
                    udtUMTS(intI).UMTS_Phone = LTrim$(Mid$(strData, 7))
                Case 4 ' code
                    udtUMTS(intI).UMTS_Code = LTrim$(Mid$(strData, 7))
                Case 5 ' location
                    udtUMTS(intI).UMTS_Location = LTrim$(Mid(strData, 10))

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    20

    Re: Pls help..portion of text search & produce output in VB

    Ok Doggle. I am trying this modification..

    One thing i need to know frm u that in this case there r only 5 fields..
    i.e
    name
    street
    ph no
    code
    location

    now suppose if there are more than 20 fields. then it's very cumbersome to use udtUMTS(intI).UMTS_Phone or udtUMTS(intI).UMTS_Code to use it every time.

    Is there any way that if the matches found with ph_no then it will get all the datas (may be 20-30 no of fields though in this case only 5 fields) from a particular UMTS . i.e i mean to say that if it is possible to read all the datas line by line until the next UMTS [may be 20-30 fields for each UMTS] then it would be easier..
    I have attched a file
    Pls help ...


    Thnkx & Regds
    Sajib
    Attached Files Attached Files

  6. #6
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Pls help..portion of text search & produce output in VB

    Wouldnt it be better to store this info in an INI file with sections?
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  7. #7
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Pls help..portion of text search & produce output in VB

    Here is an example that uses a fabricated ADO Recordset along with a simple serializable Key/Value collection class.

    It assumes that at least one blank line (or EOF) signals the end of a record, and that Keys and Values are delimited from each other by multiple spaces (at least 2).

    This allows any number of field names (Keys) and optional Values for each. It even allows a field to occur multiple times. Field (Key) names need not be predefined. It does assume however that the filter string field is named "ph no" (or "PH NO" or "Ph No").


    In this example the filtered records are displayed in a multiline TextBox but they could just as easily be written to a file.
    Attached Files Attached Files

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    20

    Re: Pls help..portion of text search & produce output in VB

    Hi dilettante,

    Thnkx for ur pist. Pls tell me how these records can be saved to a output files named recordout.txt.

    Thnkx & regards

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    20

    Re: Pls help..portion of text search & produce output in VB

    Hi Doogle ,

    As per ur guidance I made a programm for a file record.txt
    In object window I have put 1 text box where u need to give callingSubscriberIMSI . After hitting command button it should search for particular callingSubscriberIMSI as usual & should produce the output to recordout.txt....

    But when I am executing the programm, its not able to find.
    I have attached complete file. Pls check & help me.

    Thnkx & Regards










    Quote Originally Posted by Doogle View Post
    OK, you need to get rid of the leading spaces
    Code:
            Select Case intJ
                Case 0 ' UMTS - Ignore
                
                Case 1 ' name
                    udtUMTS(intI).UMTS_Name = LTrim$((Mid$(strData, 6))
                Case 2 ' street
                    udtUMTS(intI).UMTS_Street = LTrim$(Mid$(strData, 8))
                Case 3 ' ph no
                    udtUMTS(intI).UMTS_Phone = LTrim$(Mid$(strData, 7))
                Case 4 ' code
                    udtUMTS(intI).UMTS_Code = LTrim$(Mid$(strData, 7))
                Case 5 ' location
                    udtUMTS(intI).UMTS_Location = LTrim$(Mid(strData, 10))
    Attached Files Attached Files

  10. #10
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Pls help..portion of text search & produce output in VB

    Quote Originally Posted by sajib View Post
    Thnkx for ur pist. Pls tell me how these records can be saved to a output files named recordout.txt.
    I'm sorry, but I've already provided far more of a code handout than is really accepted practice here. This isn't a site offering free custom programming.

    If you can't make the very small changes required you should really consider hiring a programmer to help you.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    20

    Re: Pls help..portion of text search & produce output in VB

    dilettante, I did n't tell u 2 post ur codes. there r lot of programmers coming over here . If u don wanna post then pls don do... bt I request u not 2 comment anyhthing ok...so many people r sharing their thoughts. it's not an issue..

    dont think urself as a super programmer. nobody is perfect in this world....

  12. #12
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Pls help..portion of text search & produce output in VB

    Without wishing to be rude or to be negative, I gave you an idea of an approach to your original problem, you then changed the question and Dilettante gave you a super solution that just needs a little bit of work from you.

    We're here to help you with your code, and it would be nice to see some input from you demonstrating that you understand at least some of what we have posted. If there's something you don't understand then identify it and I'm sure someone will explain it.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    20

    Re: Pls help..portion of text search & produce output in VB

    I posted the codes above. pls find the attachment test.rar
    whenever i m searching through callingSubscriberIMSI, no matches are being found but i have checked it with other sesrching parameters like tAC. It's working fine..
    only callingSubscriberIMSI search parameter is not working...that's why i asked.

    Will it affect if i change udtCDR(1000)? please find test.rar file above that i attached earlier.

Posting Permissions

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



Click Here to Expand Forum to Full Width