Hey there scripting geniuses, please note I am still learning VBScript and I am fully ready for the lashings. So, I will research anything you ask me to as long as I have direction to go for.
I searched through the suggested questions and I found one that might be what I needed but it was "closed" with no link to go look for the other like it.
Here is what I am trying to accomplish. I need to take a text file and load the data into an array (if that is correct). This data contains Pc name, Pc location. It will carry about 2000 records (or lines) and I need to load each one into a variable. The PC name will have no spaces but the Pc Location may. Like example:
Laptop, my bathroom
Desktop, kitchen
I want to load this information into a variable I can use WshShell.SendKeys and pass key commands. I have been able to make it "kinda" work with two text files and send that data to an excel sheet (because it can take tab and enter). But rather than match one to one it matches one to 10. So If PC.txt had 10 pc names and Location.txt had 10 locations on it (which match each file in line order), my script would give me a 100 results, not 10. So, I know I am doing this all wrong and need some guidance. Here is my failed attempt and I am ready for the laughter hehhee..
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile1 = objFSO.OpenTextFile("C:\pc.txt", ForReading1)
Set objFile = objFSO.OpenTextFile("C:\Location.txt", ForReading)
'test is my excel file title test, this will allow tabs and enters
WshShell.AppActivate "test"
Const ForReading1 = 1
Dim arrFileLines1()
i = 0
Do Until objFile1.AtEndOfStream
Redim Preserve arrFileLines1(i)
arrFileLines1(i) = objFile1.ReadLine
i = i + 1
Loop
objFile1.Close
Const ForReading = 1
Dim arrFileLines()
i = 0
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
For Each strLine1 in arrFileLines1
For Each strLine in arrFileLines
WshShell.SendKeys strLine1
WshShell.SendKeys "{TAB}"
WshShell.SendKeys strLine
WshShell.SendKeys "{ENTER}"
Next
Next
I have been researching about splitting this data based off the "," but I need to get that into a Variable that I can use and repeat the key strokes, Like:
Laptop {TAB} My kitchen {ENTER} Desktop {TAB} Bathroom {ENTER} ...........ETC till the end.
uniquekey here to sort. You may first load pc names into a 1D array. You mayReDimmeans re-dimensioned it to a 2D array. Then use the pc name as a key to match and retrieve matching location data and store them in the array. Now in terms of splitting it by delimeter: If you have no idea of the delimeters file may contain or if the delimeters are random, then you may store all possible delimeters in another array. Take a look at this VBA post code for delimeters part..