Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Feb 2005
    Posts
    46

    Unanswered: opening a text file

    I'm looking for a little bit of help regarding VBA and access 2000

    I want to click a button on a form, and for some code to run to import the contents of a text file in to a text box.

    So far I have this;


    Dim sFile As String
    Dim sText As String

    sFile = "c:\arp.txt"
    Text0.SetFocus
    Text0.Text = ""
    Open sFile For Input As #1
    Do While Not EOF(1)
    Input #1, sText
    Loop
    Close #1
    Text0.SetFocus
    Text0.Text = sText

    This will display the last line of the text file, I have tried altering it to:

    Open sFile For Input As #1
    Do While Not EOF(1)
    Input #1, sText
    Text0.SetFocus
    Text0.Text = Text0.text + sText
    Loop
    Close #1

    But when I do this, there are no new lines in between sentances

    Can any one help me out here?

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Uh yeah ... Add vbCrLf to your concatenation ...
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Feb 2005
    Posts
    46
    Thanks got it to work.

    Now that I have the data, I would like to trim something from it, for example, the text that is imported is an arp table that looks like this

    192.168.172.0 00-00-00-00-00 dynamic
    192.168.172.1 11-00-11-00-11 dynaminc

    I want to type in an IP address in to a text box and then display the MAC address in another box, any thoughts?

    M Owen you seem to be the man at access judging by the amount of post you have :-)

  4. #4
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    M Owen you seem to be the man at access judging by the amount of post you have
    oh, sure! Maybe Mike is just OLDER than the rest of us!

    Providing the format of the text remains constant, you can use a couple text editing functions to get what you want. IF the text format is not consistent, you'll have to be a bit more creative to make sure you grab the right stuff.

    strText = "192.168.172.0 00-00-00-00-00 dynamic"
    strIP = Left$(strText,13)
    strMAC = Right$(strText,Len(strText)-14)

    If the IP is not always 13 characters, modify like so:
    intC = InStr(1, strText, " ")
    strIP = Left$(strText,intC-1)
    strMAC = Right$(strText,Len(strText)-intC)

    This is one simple way to do it. It can be done in a query or form by replacing the variable names with control or field names.

    have fun,
    tc

  5. #5
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by tcace
    oh, sure! Maybe Mike is just OLDER than the rest of us!

    Providing the format of the text remains constant, you can use a couple text editing functions to get what you want. IF the text format is not consistent, you'll have to be a bit more creative to make sure you grab the right stuff.

    strText = "192.168.172.0 00-00-00-00-00 dynamic"
    strIP = Left$(strText,13)
    strMAC = Right$(strText,Len(strText)-14)

    If the IP is not always 13 characters, modify like so:
    intC = InStr(1, strText, " ")
    strIP = Left$(strText,intC-1)
    strMAC = Right$(strText,Len(strText)-intC)

    This is one simple way to do it. It can be done in a query or form by replacing the variable names with control or field names.

    have fun,
    tc
    What was that you young whipper-snapper? I couldn't hear you ... Hang on so I can put my hearing aid back in ...

    IP won't always be 13 chars ... Another way to get what you're looking for is to use the Split function with a space token ... Ex:

    Dim SplitArray()

    SplitArray=Split(strText," ",vbTextCompare) ---->Check that last parameter ...

    Then your IP addy is in SplitArray(0) ...
    Back to Access ... ADO is not the way to go for speed ...

  6. #6
    Join Date
    Feb 2005
    Posts
    46
    Cheers for your help chaps, im not sure I get what you guys meen or what i meen or 1+1 = confussion

    On the screen there are 3 texts box one has the arp table (type arp -a too see) in the other two are blank

    I want to type an ip address in ip(text) box and then the mac address to be displayed in the third box

    I would attach a zip file, but I use linux so it become a problem

  7. #7
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by cornish
    Cheers for your help chaps, im not sure I get what you guys meen or what i meen or 1+1 = confussion

    On the screen there are 3 texts box one has the arp table (type arp -a too see) in the other two are blank

    I want to type an ip address in ip(text) box and then the mac address to be displayed in the third box

    I would attach a zip file, but I use linux so it become a problem
    And where are you going to store the data in the mean time? We seem to have a design disconnect here ... Instead of textboxes are you really wanting to use comboboxes? This goes back to the 1st question: where are you going to store the data for your lookups?
    Back to Access ... ADO is not the way to go for speed ...

  8. #8
    Join Date
    Feb 2005
    Posts
    46
    Ok sorry, I think its my comms skills

    There is one table at the moment

    IP
    MAC

    One form that when completed will show the IP and the MAC, if the MAC is not there, I need to click the button to import a text file (which you have done for me, many thanks) and then cut out the relivant data that I need.

    Does this make any sense.
    Come the end of this week I need to have 900 MAC address for the 900 IP's, so far I have 20, I was trying to use the VBA side of Access to create a more simplistic way of doing things

    Does this make sense now?

    Forget where the data is going to be store for the time being, im trying to get the code to do what I want it to do first.

    Thanks for all your help so far

  9. #9
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi

    I would use tc's or Old Mike's function to split the input from the text file and dump it in a table. Join to your table-without-many-MAC-addresses and update the MAC addresses in the second table from the first (where there is no MAC address). Saves buggering about with a form.

    Just my 0.02 Britsh Pounds Stirling
    Testimonial:
    pootle flump
    ur codings are working excelent.

  10. #10
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    Just my 0.02 Britsh Pounds Stirling
    ummm, I believe that 2 cents (assuming .02 American dollars) is only about .01 British pounds stirling

    Unless you're showing off and giving us your 4 cents!

    Cornish:
    If this is a one time action, you may want to do it in Excel or using Queries. To use functions in queries, replace the variable names (like strIP) with field names in square brackets.

    hope this helps,
    tc

  11. #11
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by tcace
    If this is a one time action, you may want to do it in Excel or using Queries. To use functions in queries, replace the variable names (like strIP) with field names in square brackets.
    Jolly good point. If it is a one off there is no need to write a single line of vb. Import the file directly into a table and then use SQL from there on in.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  12. #12
    Join Date
    Feb 2005
    Posts
    46
    Ok I have a attached a copy of the DB

    There are three files arp.txt, myp.bat and the mydatabse.mda

    Copy the arp.txt file to your c:\
    you dont have to copy the bat file, thats justs a simple bat file to ping a device and create the text file,

    When you load it up you and press the command button you will see that it will load the arp.txt file in to the top text file, an IP address for the record will allready be there, I just need it to extract the correct mac address from the top.

    Cheers

    I dont want to create more than one table.

    Many thanks so far

  13. #13
    Join Date
    Feb 2005
    Posts
    46
    Forgot to attach document
    Attached Files Attached Files

  14. #14
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Do you ALWAYS want to update the IP address with the corresponding MAC address or do you want the user to have some control over the process?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  15. #15
    Join Date
    Feb 2005
    Posts
    46
    I will be the only user of this database, the IPs that will be entered are coming from a excluded range on the DHCP so they wont change I just need to get the mac address for each device

Posting Permissions

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