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?
????
INTERCEPT a variable position of string
-
- PlatinumLounger
- Posts: 4372
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 78630
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: INTERCEPT a variable position of string
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
Hans
-
- PlatinumLounger
- Posts: 4372
- Joined: 26 Apr 2010, 17:36
Re: INTERCEPT a variable position of string
ops... instead RAPP: is RAPPORTO C/C: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
-
- Administrator
- Posts: 78630
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: INTERCEPT a variable position of string
Use
InStr(TextLine, "RAPPORTO C/C:")
and
Mid(TextLine, lngPosition + 14, 5)
InStr(TextLine, "RAPPORTO C/C:")
and
Mid(TextLine, lngPosition + 14, 5)
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4372
- Joined: 26 Apr 2010, 17:36
Re: INTERCEPT a variable position of string
TKS...HansV wrote:Use
InStr(TextLine, "RAPPORTO C/C:")
and
Mid(TextLine, lngPosition + 14, 5)
In other case resolved my self...
Sorry for thath
-
- PlatinumLounger
- Posts: 4372
- Joined: 26 Apr 2010, 17:36
Re: INTERCEPT a variable position of string
great routine!sal21 wrote:ops... instead RAPP: is RAPPORTO C/C: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