Parsing a paragraph

charliemopps

Registered User.
Local time
Today, 11:50
Joined
Feb 24, 2009
Messages
40
I need some help parsing a paragraph. If someone could give me some quick example code I'd appreciate it.


This is an example of what will be on a memo field called "Txt_26" on my form. And I just want each data set in a sepperate part of an array so I can pick out the IP, phone, etc...

Code:
    NS Identifier:    1099999         Dsl Phone Number:    555-555-5555         ATM Interface:    ATM1/0    
        
         NAS IP:    216.050.0.1         VPI:    20         VCI:    5225    
        
         Connection Type:    ATM         Wan CIDR:              Lan CIDR:         
        
         Provisioning ID:    555555         DSA Assigned:    45505
 
Do you need everything parsed out or just a few elements?
 
Do you need everything parsed out or just a few elements?


I need specific parts of this memo field and another memo field.
In this one I need the phone number.
In another field I need an IP address.
I know how to do this in a scripting language I use, but I'm a VB noob. So I think if you get me started I can prolly figure out the rest.
 
In vba there are string functions like right(), left(), mid(). I think you need to start with instr() which will find the occurance of one string in another. It will return the starting charactor postion. Using this you could use mid() to extract the pc of the string you need. If you google vba string functions you should get some good help....
 
But, if you notice, these values are tab sepperated. wouldn't it be easier to parse it out that way?
 
If it is tab delimited you can use the Split Function to get what you want.

Code:
Function ReturnIP(strInputText As String) As String
  Dim varSplit As Variant
  
varSplit = Split(strInputText, Chr(9))

ReturnIP = varSplit(7)
End Function

That is, if the text is standard and the items are all there each time. You can play with it to see what you can get.
 
The best thing would be to post a sample with a few hundred records and let us see it instead of guessing... :)
 
I think I got it. with the STR and mid functions

But I have a new question, is there a way to search for a LINE of text?


Like:

Red 2
blue 3
green 5
orange 6

Search for blue
and then return the entire line that has blue in it as a text variable?
 
Hope you get this working - I'm bailing out :)
 
Charlie,

You can use the split function:

Dim varArray As Variant
varArray = Split(Me.txt_26, vbCrLf)

varArray(2) is the third line, the array is zero-based.

You can also use the split function again:

varOther = Split(varArray(2), vbTab)

Wayne
 
If the data is in a text file, lines containing a search string can be found by reading the file line by line in a loop and applying the InStr function.

The line number can be found by incrementing a counter in the loop.
 

Users who are viewing this thread

Back
Top Bottom