parse text from file

A

Arnie

Morning all

i am reading in data from a text file as below

strFile = "C:\Folder\text.txt"
intFile = FreeFile()
Open strFile For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strBuffer
intEqualSign = InStr(strBuffer, "=")
Select Case strBuffer
Case "[pcconfiguration]"
StrSectionName = "pcconfiguration"
Case "[ipconfiguration]"
StrSectionName = "ipconfiguration"
End Select
If intEqualSign > 0 Then
strBefore = Left$(strBuffer, intEqualSign - 1)
strAfter = Mid$(strBuffer, intEqualSign + 1)
Select Case strBefore
Case "ComputerName"
If StrSectionName = "pcconfiguration" Then
StrMyComputerName = strAfter
Else
StrIPComputerName = strAfter
End If
Case "DomainName"
If StrSectionName = "pcconfiguration" Then
StrMyDomainName = strAfter
Else
StrIFPMDomainName = strAfter
End If

Case "IPAddress"
strIPAddress = strAfter

End Select

End If
Loop
Close #intFile

Then the code to pass it to the table required my problem is when i read
in the ip address (in the text file)

IPAdress=172.200.132.181

i can read in after the = sign but the rest i want to read in in chunks ie

ip1 172
ip2 200
ip3 132
ip4 181

i cant seem to get the right code
also if one of the ip address chunks is only 2 digits or 1 digit ie
172.20.132.200 how do i account for that, i do understand the best way is to
read in to the (.) but not sure how to execute it.

thanks in advance

Arnie
 
A

Arnie

Alex

Marvelous thank you v.much

Alex Dybenko said:
Hi,
something like this:

dim a as variant

strIPAddress = strAfter
a=split(strIPAddress,".")
strIP1=a(0)
strIP2=a(1)
strIP3=a(2)
strIP4=a(3)


--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com

Arnie said:
Morning all

i am reading in data from a text file as below

strFile = "C:\Folder\text.txt"
intFile = FreeFile()
Open strFile For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strBuffer
intEqualSign = InStr(strBuffer, "=")
Select Case strBuffer
Case "[pcconfiguration]"
StrSectionName = "pcconfiguration"
Case "[ipconfiguration]"
StrSectionName = "ipconfiguration"
End Select
If intEqualSign > 0 Then
strBefore = Left$(strBuffer, intEqualSign - 1)
strAfter = Mid$(strBuffer, intEqualSign + 1)
Select Case strBefore
Case "ComputerName"
If StrSectionName = "pcconfiguration" Then
StrMyComputerName = strAfter
Else
StrIPComputerName = strAfter
End If
Case "DomainName"
If StrSectionName = "pcconfiguration" Then
StrMyDomainName = strAfter
Else
StrIFPMDomainName = strAfter
End If

Case "IPAddress"
strIPAddress = strAfter

End Select

End If
Loop
Close #intFile

Then the code to pass it to the table required my problem is when i read
in the ip address (in the text file)

IPAdress=172.200.132.181

i can read in after the = sign but the rest i want to read in in chunks ie

ip1 172
ip2 200
ip3 132
ip4 181

i cant seem to get the right code
also if one of the ip address chunks is only 2 digits or 1 digit ie
172.20.132.200 how do i account for that, i do understand the best way is
to
read in to the (.) but not sure how to execute it.

thanks in advance

Arnie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top