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 - Replicating vlookup functionality

Reply
 
Old 01-20-2009   #1 (permalink)
Michael


 
 

Replicating vlookup functionality

I am usually in the excel forum, however, I am currently working with a
software named upstream. It uses vb script to accomplish mappings.
What I need to do is write a code that loops through a 3 column text file,
and reads
column 1 and returns the percentage value from columns 2 and 3 into a
variable.

Line sample:
1.0.000.1004 0.084412 0.915588

Expected result:
var1= 0.084412
var2= 0.915588

Thanks in Advance
Michael Arch.



My System SpecsSystem Spec
Old 01-20-2009   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: Replicating vlookup functionality


"Michael" <Michael@xxxxxx> wrote in message
news:3DD4743E-70CE-4286-910E-AE716355E4B7@xxxxxx
Quote:

>I am usually in the excel forum, however, I am currently working with a
> software named upstream. It uses vb script to accomplish mappings.
> What I need to do is write a code that loops through a 3 column text file,
> and reads
> column 1 and returns the percentage value from columns 2 and 3 into a
> variable.
>
> Line sample:
> 1.0.000.1004 0.084412 0.915588
>
> Expected result:
> var1= 0.084412
> var2= 0.915588
>
> Thanks in Advance
> Michael Arch.
>
Maybe something like this:
aValues =
Split(oFSO.GetFile("D:\Temp\temp.txt").OpenAsTextStream(1).ReadLine)
var1 = aValues(1)
var2 = aValues(2)



My System SpecsSystem Spec
Old 01-20-2009   #3 (permalink)
Michael Arch


 
 

Re: Replicating vlookup functionality

How does it know where each Column begins and ends?

Michael Arch.




"Pegasus (MVP)" wrote:
Quote:

>
> "Michael" <Michael@xxxxxx> wrote in message
> news:3DD4743E-70CE-4286-910E-AE716355E4B7@xxxxxx
Quote:

> >I am usually in the excel forum, however, I am currently working with a
> > software named upstream. It uses vb script to accomplish mappings.
> > What I need to do is write a code that loops through a 3 column text file,
> > and reads
> > column 1 and returns the percentage value from columns 2 and 3 into a
> > variable.
> >
> > Line sample:
> > 1.0.000.1004 0.084412 0.915588
> >
> > Expected result:
> > var1= 0.084412
> > var2= 0.915588
> >
> > Thanks in Advance
> > Michael Arch.
> >
>
> Maybe something like this:
> aValues =
> Split(oFSO.GetFile("D:\Temp\temp.txt").OpenAsTextStream(1).ReadLine)
> var1 = aValues(1)
> var2 = aValues(2)
>
>
>
>
My System SpecsSystem Spec
Old 01-20-2009   #4 (permalink)
Michael Arch


 
 

Re: Replicating vlookup functionality

Never mind, I found out how....

Thanks for your help I will give it a shot
--
If this posting was helpful, please click on the Yes button.
Regards,

Michael Arch.




"Michael Arch" wrote:
Quote:

> How does it know where each Column begins and ends?
>
> Michael Arch.
>
>
>
>
> "Pegasus (MVP)" wrote:
>
Quote:

> >
> > "Michael" <Michael@xxxxxx> wrote in message
> > news:3DD4743E-70CE-4286-910E-AE716355E4B7@xxxxxx
Quote:

> > >I am usually in the excel forum, however, I am currently working with a
> > > software named upstream. It uses vb script to accomplish mappings.
> > > What I need to do is write a code that loops through a 3 column text file,
> > > and reads
> > > column 1 and returns the percentage value from columns 2 and 3 into a
> > > variable.
> > >
> > > Line sample:
> > > 1.0.000.1004 0.084412 0.915588
> > >
> > > Expected result:
> > > var1= 0.084412
> > > var2= 0.915588
> > >
> > > Thanks in Advance
> > > Michael Arch.
> > >
> >
> > Maybe something like this:
> > aValues =
> > Split(oFSO.GetFile("D:\Temp\temp.txt").OpenAsTextStream(1).ReadLine)
> > var1 = aValues(1)
> > var2 = aValues(2)
> >
> >
> >
> >
My System SpecsSystem Spec
Old 01-20-2009   #5 (permalink)
ekkehard.horner


 
 

Re: Replicating vlookup functionality

Michael schrieb:
Quote:

> I am usually in the excel forum, however, I am currently working with a
> software named upstream. It uses vb script to accomplish mappings.
> What I need to do is write a code that loops through a 3 column text file,
> and reads
> column 1 and returns the percentage value from columns 2 and 3 into a
> variable.
>
> Line sample:
> 1.0.000.1004 0.084412 0.915588
>
> Expected result:
> var1= 0.084412
> var2= 0.915588
[...]
If you want to lookup data in a file of more than one line, you
may look at this:

Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sFSpec : sFSpec = ".\mmarch\mmarch01.txt"
Dim dicData : Set dicData = parseMMarch( sFSpec )
Dim aTests : aTests = Array( _
"1.0.000.1004", "2.0.000.1004", "1.0.000.1006", "1.0.000.1005" _
)

WScript.Echo String( 30, "-" )
WScript.Echo oFS.OpenTextFile( sFSpec ).ReadAll
WScript.Echo String( 30, "-" )

Dim sKey
For Each sKey In aTests
If dicData.Exists( sKey ) Then
WScript.Echo Join( dicData( sKey ), ", " )
Else
WScript.Echo sKey, "not found."
End If
Next

Function parseMMarch( sFSpec )
Dim dicData : Set dicData = CreateObject( "Scripting.Dictionary" )
Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim oRE : Set oRE = New RegExp
oRE.Global = True
oRE.Multiline = True
' 1.0.000.1004 0.084412 0.915588
oRE.Pattern = "^([\d.]+)\s+(\d+\.\d+)\s+(\d+\.\d+)$"
Dim oMTS : Set oMTS = oRE.Execute( oFS.OpenTextFile( sFSpec ).ReadAll )
Dim oMT
For Each oMT In oMTS
dicData( oMT.Submatches( 0 ) ) = Array( _
oMT.Submatches( 0 ), oMT.Submatches( 1 ), oMT.Submatches( 2 ) _
)
Next
Set parseMMarch = dicData
End Function

output:

=== lookupTXT: vblookup (MMarch) ==========
------------------------------
1.0.000.1004 0.084412 0.915588
1.0.000.1005 0.055555 0.555555
1.0.000.1006 0.066666 0.666666

------------------------------
1.0.000.1004, 0.084412, 0.915588
2.0.000.1004 not found.
1.0.000.1006, 0.066666, 0.666666
1.0.000.1005, 0.055555, 0.555555
=== lookupTXT: 0 done (00:00:00) ==========



My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
VLOOKUP .NET General
Pictures folder replicating Vista file management
Tail functionality? PowerShell


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