Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - VB search/ find for a value in txt file

Reply
 
Old 07-16-2009   #1 (permalink)
johnthenu


 
 

VB search/ find for a value in txt file

Hi I am trying to pick a value from a txt file which is part of a
URL….

SiTrackTracer(document.URL,"URI=/Sample/Res/RESULTS/
COMPLETE_RESULTS&ALogin_REFERENCE=34&CUSTOMER_ID=90000000054&SESSION_ID=sIFSHw--
oVssUoVmzYLaccQ");

ALogin_REFERENCE=34
CUSTOMER_ID=90000000054

I have to search for the the value in the txt file and return these
values…

I have gone up to…..opening the text file and reading it….but I am
struck with actually searching ans returning the value…

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateTextFile("C:\Code.txt", True)
f.Write(test)
f.Close

Any suggestion folks…

My System SpecsSystem Spec
Old 07-16-2009   #2 (permalink)
Auric__


 
 

Re: VB search/ find for a value in txt file

On Thu, 16 Jul 2009 21:48:42 GMT, johnthenu wrote:
Quote:

> Hi I am trying to pick a value from a txt file which is part of a
> URL….
>
> SiTrackTracer(document.URL,"URI=/Sample/Res/RESULTS/
> COMPLETE_RESULTS&ALogin_REFERENCE=34&CUSTOMER_ID=90000000054&SESSION_ID=s
> IFSHw-- oVssUoVmzYLaccQ");
>
> ALogin_REFERENCE=34
> CUSTOMER_ID=90000000054
>
> I have to search for the the value in the txt file and return these
> values…
>
> I have gone up to…..opening the text file and reading it….but I am
> struck with actually searching ans returning the value…
>
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set f = fso.CreateTextFile("C:\Code.txt", True)
> f.Write(test)
> f.Close
>
> Any suggestion folks…
Split(), then look for "=". Edit this to suit:
x = "your=information&to=be&parsed=here"
y = Split(x, "&")
For z = 0 To UBound(y)
a = InStr(y(z), "=")
If a Then
b = Left(y(z), a - 1)
Select Case b
Case "ALogin_REFERENCE"
ALogin_REFERENCE = Mid(y(z), a + 1)
Case "CUSTOMER_ID"
CUSTOMER_ID = Mid(y(z), a + 1)
End Select
End If
Next

--
- What is life like for you?
- A mystery. But not an unpleasant one.
My System SpecsSystem Spec
Old 07-16-2009   #3 (permalink)
James Whitlow


 
 

Re: VB search/ find for a value in txt file

On Thu, 16 Jul 2009 21:48:42 GMT, johnthenu wrote:
Quote:

> Hi I am trying to pick a value from a txt file which is part of a
> URL..
>
> SiTrackTracer(document.URL,"URI=/Sample/Res/RESULTS/
> COMPLETE_RESULTS&ALogin_REFERENCE=34&CUSTOMER_ID=90000000054&SESSION_ID=s
> IFSHw-- oVssUoVmzYLaccQ");
>
> ALogin_REFERENCE=34
> CUSTOMER_ID=90000000054
>
> I have to search for the the value in the txt file and return these
> values.
>
> I have gone up to...opening the text file and reading it..but I am
> struck with actually searching ans returning the value.
>
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set f = fso.CreateTextFile("C:\Code.txt", True)
> f.Write(test)
> f.Close
>
> Any suggestion folks.
I would suggest using the Regullar Expression object. I have pasted a code
sample below. Please note that there is no error trapping in it.

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oRegEx = CreateObject("VBScript.RegExp")
oRegEx.IgnoreCase = True

sFileName = "C:\TestFile.txt"

sText = oFSO.OpenTextFile(sFileName).ReadAll

oRegEx.Pattern = "ALogin_REFERENCE=(.*?)(?:&|$)"
sALogin_REFERENCE = oRegEx.Execute(sText)(0).Submatches(0)

oRegEx.Pattern = "CUSTOMER_ID=(.*?)(?:&|$)"
sCUSTOMER_ID = oRegEx.Execute(sText)(0).Submatches(0)

MsgBox "ALogin_REFERENCE = " & sALogin_REFERENCE & vbCrLf & _
"CUSTOMER_ID = " & sCUSTOMER_ID


My System SpecsSystem Spec
Old 07-16-2009   #4 (permalink)
Richard Mueller [MVP]


 
 

Re: VB search/ find for a value in txt file


"johnthenu" <gthenappan@xxxxxx> wrote in message
news:6faa1bd4-beb4-47a5-a71a-6a814642fd1a@xxxxxx
Hi I am trying to pick a value from a txt file which is part of a
URL….

SiTrackTracer(document.URL,"URI=/Sample/Res/RESULTS/
COMPLETE_RESULTS&ALogin_REFERENCE=34&CUSTOMER_ID=90000000054&SESSION_ID=sIFSHw--
oVssUoVmzYLaccQ");

ALogin_REFERENCE=34
CUSTOMER_ID=90000000054

I have to search for the the value in the txt file and return these
values…

I have gone up to…..opening the text file and reading it….but I am
struck with actually searching ans returning the value…

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateTextFile("C:\Code.txt", True)
f.Write(test)
f.Close

Any suggestion folks…

-----------
The RegExp object may be the way to go. I can't tell. The "traditional" way
is use the InStr function to find the string, then parse from there to the
next delimiter. In this case, the next delimiter seems to be the "&"
character. However, I assume the parameter could also be the last one, in
which case the next delimiter would be a quote. My solution would be:
=========
Option Explicit
Dim strFile, objFSO, objFile, strLine
Const ForReading = 1

' Specify the file.
strFile = "c:\scripts\code.txt"

' Open the file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)

' Read the file.
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Call FindValue(strLine, "ALogin_REFERENCE=")
Call FindValue(strLine, "CUSTOMER_ID=")
Loop

' Clean up.
objFile.Close

Sub FindValue(ByVal strLine, ByVal strSearch)
' Parse a line for a value.
Dim intStart, intEnd, strValue

' Search for search string.
intStart = InStr(strLine, strSearch)
If (intStart > 0) Then
intStart = intStart + Len(strSearch)
' Assume value delimted by "&" Character
intEnd = InStr(intStart, strLine, "&")
If (intEnd < intStart) Then
' Value must be delimited by quote character.
intEnd = InStr(intStart, strLine, """")
End If
strValue = Mid(strLine, intStart, intEnd - intStart)
Wscript.Echo strSearch & strValue
End If
End Sub
========
I used a Sub to find both search strings. What you use depends on what you
intend to do with the values. You may want a different function for each
search string, or use no methods and search in the main program.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 07-16-2009   #5 (permalink)
billious


 
 

Re: VB search/ find for a value in txt file

johnthenu wrote:
Quote:

> Hi I am trying to pick a value from a txt file which is part of a
> URL….
>
> SiTrackTracer(document.URL,"URI=/Sample/Res/RESULTS/
> COMPLETE_RESULTS&ALogin_REFERENCE=34&CUSTOMER_ID=90000000054&SESSION_ID=sIFSHw--
> oVssUoVmzYLaccQ");
>
> ALogin_REFERENCE=34
> CUSTOMER_ID=90000000054
>
> I have to search for the the value in the txt file and return these
> values…
>
> I have gone up to…..opening the text file and reading it….but I am
> struck with actually searching ans returning the value…
>
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set f = fso.CreateTextFile("C:\Code.txt", True)
> f.Write(test)
> f.Close
>
> Any suggestion folks…
If you're not married to VBS, you can accomplish this in batch:

This solution developed using XP
It may work for NT4/2K

----- batch begins -------
[1]@echo off
[2]for /f "tokens=2,3delims=&" %%i in (testfileurl.txt) do
echo\%%i>code.txt&echo\%%j>>code.txt
------ batch ends --------

Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed

* this assumes that 'testfileurl.txt' contains exactly what you have posted
on one line. The output file 'code.txt' is (re)created by the ">"
redirector; the second line is appended by the ">>" redirector.
* If the text file contains lines other than what you have provided, change
(testfileurl.txt) to ('find "SiTrackTracer(document" ^<testfileurl.txt')
(including the single-quotes;and "SiTrackTracer(document" I've assumed to be
unique to the line-in-question)


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Search can't find a file? Vista General
Solved mpg file comes up in search but cannot find it General Discussion
Search not finding file using 1 word, but will find using another Vista General
Re: File 'Search' function can't find files with specified key wor Vista General
Vista file search don't find any files Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46