From: Al Dunbar on


<bcastaing(a)gmail.com> wrote in message
news:0c09e83e-e107-4458-8224-6a7361e07eb3(a)m31g2000yqd.googlegroups.com...
> On 8 f�v, 12:27, "Pegasus [MVP]" <n...(a)microsoft.com> wrote:
>> <bcasta...(a)gmail.com> said this in news
>> itemnews:389dabc3-ca3b-440b-b55a-a93ca9221025(a)w16g2000yqw.googlegroups.com...
>>
>> > Hello to everybody
>>
>> > I would like to read a value in a txt file. For example, the value
>> > will following the egual sign. So I want to look for language and get
>> > "fr" as value.
>>
>> > language = fr
>> > country = france
>>
>> > Thank you by advance and have a nice day.
>>
>> The Split function is your answer:
>> sString = "language = fr"
>> aString = split(sString, "=")
>> wscript.echo trim(aString(2))
>
> Thank you very much for your quick answer.
> But my text file will have many lines, and I would like to find a
> value for each parameter I look for.

Then, perhaps that is what you should have asked for, rather than just
saying "I would like to read a value in a text file". Pegasus showed you how
to do precisely that.

> For example, if I look for language, I want to get fr, If I look for
> country, I will have france ....

What would you expect to get for the country if this text was present in the
file:

country = france
country = germany

Perhaps if you explained what the file is and what it means, it would be
easier for someone to provide an answer that meets your unstated
expectations.


/Al


From: bcastaing on
On 9 fév, 05:27, "Al Dunbar" <aland...(a)hotmail.com> wrote:
> <bcasta...(a)gmail.com> wrote in message
>
> news:0c09e83e-e107-4458-8224-6a7361e07eb3(a)m31g2000yqd.googlegroups.com...
>
>
>
>
>
> > On 8 fév, 12:27, "Pegasus [MVP]" <n...(a)microsoft.com> wrote:
> >> <bcasta...(a)gmail.com> said this in news
> >> itemnews:389dabc3-ca3b-440b-b55a-a93ca9221025(a)w16g2000yqw.googlegroups..com...
>
> >> > Hello to everybody
>
> >> > I would like to read a value in a txt file. For example, the value
> >> > will following the egual sign. So I want to look for language and get
> >> > "fr" as value.
>
> >> > language = fr
> >> > country = france
>
> >> > Thank you by advance and have a nice day.
>
> >> The Split function is your answer:
> >> sString = "language = fr"
> >> aString = split(sString, "=")
> >> wscript.echo trim(aString(2))
>
> > Thank you very much for your quick answer.
> > But my text file will have many lines, and I would like to find a
> > value for each parameter I look for.
>
> Then, perhaps that is what you should have asked for, rather than just
> saying "I would like to read a value in a text file". Pegasus showed you how
> to do precisely that.
>
> > For example, if I look for language, I want to get fr, If I look for
> > country, I will have france ....
>
> What would you expect to get for the country if this text was present in the
> file:
>
>     country = france
>     country = germany
>
> Perhaps if you explained what the file is and what it means, it would be
> easier for someone to provide an answer that meets your unstated
> expectations.
>
> /Al- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -

Hello everybody,

Thanks to you I could manage my code, you are right, pegasus put me on
the track with the split function.
My need is to read in a text file different value that will be used to
configure an application

the txt file will look

country = france
language = fr
info1 = value
.....


So now with the split function I can put all the string in an array
and look for the wanted value.


Set objFile = objFSO.OpenTextFile("\\c:\script\param.txt", ForReading)
strContents = objFile.ReadAll
objFile.Close
arrWords = Split(strContents, vbcrlf)
intStart = 0
IntFindLine = 0
For Each strWord in arrWords
If InStr(strWord, value) Then
intStart = intStart + 1
End If

If intStart > 0 Then
intFindLine = IntFindLine + 1
strLine = strLine & strWord
if intFindLine > 0 then exit For
End If
Next
arrWords = Split(strLine, " = ")
strValue = (arrWords(1))
Wscript.Echo strValue