INTERCEPT a variable position of string

User avatar
sal21
PlatinumLounger
Posts: 4372
Joined: 26 Apr 2010, 17:36

INTERCEPT a variable position of string

Post by sal21 »

I read a txt file with the tipical:
...
Open Filename$ For Input As #FileHandle
Do While Not EOF(FileHandle)
Line Input #FileHandle, TextLine$
ecc...
...

in txt file i can have a string: RAPP: 14587

I this case RAPP: is in mid 7,5 and i get with othe mid 14587

I have see into txt the position of RAPP: is variable 8,5 or 34,5 or 67,5....

how to intercept teh mid position of RAPP: and get 14587...

i think the first steep is to use instring to intercept RAPP: but the rest of code?

???? :sad: :scratch: :scratch: :scratch:

User avatar
HansV
Administrator
Posts: 78630
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: INTERCEPT a variable position of string

Post by HansV »

Try this:

Code: Select all

    Dim lngPosition As Long
    Dim strExtract As String
    lngPosition = InStr(TextLine, "RAPP:")
    If lngPosition > 0 Then
        strExtract = Mid(TextLine, lngPosition + 6, 5)
    End If
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4372
Joined: 26 Apr 2010, 17:36

Re: INTERCEPT a variable position of string

Post by sal21 »

HansV wrote:Try this:

Code: Select all

    Dim lngPosition As Long
    Dim strExtract As String
    lngPosition = InStr(TextLine, "RAPP:")
    If lngPosition > 0 Then
        strExtract = Mid(TextLine, lngPosition + 6, 5)
    End If
ops... instead RAPP: is RAPPORTO C/C:

User avatar
HansV
Administrator
Posts: 78630
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: INTERCEPT a variable position of string

Post by HansV »

Use

InStr(TextLine, "RAPPORTO C/C:")

and

Mid(TextLine, lngPosition + 14, 5)
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4372
Joined: 26 Apr 2010, 17:36

Re: INTERCEPT a variable position of string

Post by sal21 »

HansV wrote:Use

InStr(TextLine, "RAPPORTO C/C:")

and

Mid(TextLine, lngPosition + 14, 5)
TKS...

In other case resolved my self...
Sorry for thath :grin: :sad:

User avatar
sal21
PlatinumLounger
Posts: 4372
Joined: 26 Apr 2010, 17:36

Re: INTERCEPT a variable position of string

Post by sal21 »

sal21 wrote:
HansV wrote:Try this:

Code: Select all

    Dim lngPosition As Long
    Dim strExtract As String
    lngPosition = InStr(TextLine, "RAPP:")
    If lngPosition > 0 Then
        strExtract = Mid(TextLine, lngPosition + 6, 5)
    End If
ops... instead RAPP: is RAPPORTO C/C:
great routine!
:thankyou: