![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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. > aValues = Split(oFSO.GetFile("D:\Temp\temp.txt").OpenAsTextStream(1).ReadLine) var1 = aValues(1) var2 = aValues(2) |
My System Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| VLOOKUP | .NET General | |||
| Pictures folder replicating | Vista file management | |||
| Tail functionality? | PowerShell | |||