Results 1 to 9 of 9

Thread: File I/O

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Posts
    17

    Question

    Hi there!!

    This is a question regarding File I/O.
    I created a text file (extension .txt) with the following format:

    abc 123.1.2.3 cbefg 128.1.5.6 vwxyz 224.0.0.0 .... etc

    The file will starts with a name followed by an IP address, this format will carry on till EOF with no newline characters.

    The file format cannot be modified, so the question is how can I extract the names and IP addresses separately?? The names are of different length so the only thing which I can think of is to detect for the spaces in between them, but I am not sure how this can be done.

    I will need the names to be in a combo box and upon selecting a name, the corresponding IP address will be displayed in another textbox.

    Regards

  2. #2
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    I think you would be better off using RANDOM file access, where each record has a set amount and format for the data, in your case it could be:

    Name
    Ip Number 1st Quarter
    Ip Number 2st Quarter
    Ip Number 3st Quarter
    Ip Number 4st Quarter


    and you know this much the name is of STRING format and the numbers are of INTEGER format, so you end up at

    Public Type MyRecordInfo
    Name as string * 30
    Number1 as Integer
    Number2 as Integer
    Number3 as Integer
    Number4 as Integer
    End Type
    Public Type MyRecord as MyRecordInfo

    And you would open it as:
    Open ThisFile for Random Access as #XX Len=Len(MyRecordInfo)

    And you load save records by using:
    to load it
    Get #XX, ThisRecordNumber, MyRecord

    to save it
    Put #XX, ThisRecordNumber, MyRecord

    That way you can pull up any record you wish

    I hope that helps you,
    If you need more info just e-mail me or post a reply


    NOTE:
    For more info look in the help under:
    Open
    Access
    Random
    Type
    User Defined Types



    DocZaf
    {;->





  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Posts
    17
    But my source text file is in a whole string format without any newline characters in between, do u think it can work??

    Thanks!

  4. #4
    Addicted Member JasonGS's Avatar
    Join Date
    May 2000
    Location
    California
    Posts
    155

    Lightbulb

    I frequently get tasked with wierd stuff like this, I would use InStr() and Trim$ to find a space and read back to the space before or BOL (name) and then read from that space to the next one or EOL (IP address) if it were me...

    I would code it out for you but im going to bed, if you still can't get it working, repost and ill code it for you from work tomorrow .

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Posts
    17
    hi Jason!

    Would really appreciate that! cos I really need an example to get going!!

    Thanks alot!!

  6. #6
    New Member
    Join Date
    May 2000
    Posts
    3
    Hey here's an example that might work
    let x= string
    let p() matrix of strings of terrible length (much bigger than size you need)

    dim Array_Index
    dim Counter_Var
    dim Position_Var

    Array_Index = 0
    Position_Var = -1
    while not Position_Var = 0 do
    Position_Var = InStr(x, " ") ' now looking for space
    P(Array_Index) = Mid(x , Position_Var + 1, 15) 'take 15 characters after space
    Array_Index = Array_Index + 1
    Loop

    This is rough but the idea is sound. You will need to check if the thing after the space is a number or not.

    Also this is not a programming approach at all, but if you have spaces or other things seperating this stuff you can do a custom replace in word on this file, you just open up the text file in word and replace all spaces with returns or whatever else you want, why would you do this? ....
    well later on you can actually read a line in and some of them will be the IP addresses which you wanted originally.... this might also work for you...

    Cheers

  7. #7
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554

    Question Question

    What is it that your trying do?

    Are you trying to decipher site traffic logs?

    DocZaf
    {;->

  8. #8
    Junior Member
    Join Date
    May 2000
    Location
    New Delhi, India
    Posts
    18

    Post Use Split Function

    Load the file in a text string by using Open FileName as...Close #FileNum. Then use split function to store it in an array. Do a loop to read values.

    For I = 0 To Strings.UBound Step 2
    lstIP.AddItem Strings(I) & ": " & Strings(I+1)
    Next I

    Assuming that there is an array containing Data and An Listbox in which the Contents will be loaded such as:

    YAHOO!: 202.54.61.1
    VBWIRE: 422.45.31.0
    And so on....
    Kazim Zaidi (the cracker)

  9. #9
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    You could write your own code to break up the string or use the built in function
    http://www.informit.com/content/0789...html#Heading10
    "People who think they know everything are a great annoyance to those of us who do."

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