Search code examples
vbscriptadsutil.vbs

'Send the first text line (row) C:\Alexander.txt to C:\Test.vbs to Line (row) n and replace


'i have two files

C:\Alexander.txt and C:\Test.vbs

'in C:\Alexander.txt is list of numbers.

234.6656       
-123.48872
456.75555 
345.56777853
-777.4455666
778.522222245
Etc. in down more.

'in C:\Test.vbs is script command.

WshShell.SendKeys "{TAB}"
WScript.Sleep 1
WshShell.SendKeys "{TAB}"
WScript.Sleep 1
WshShell.SendKeys "360.5"
WScript.Sleep 1
WshShell.SendKeys "{TAB}"
WScript.Sleep 1
WshShell.SendKeys "{TAB}"
WScript.Sleep 1

I want to make.

'C:\Alexander.txt Send the first text line (row) to C:\Test.vbs line four replace 360.5 with 234.6656

 '

'example click 1: 234.6656 Send text to C:\Test.vbs line four replace 360.5 with 234.6656

(or another line to be able modify the line by me)

'after send to C:\Test.vbs delete first line (row) in C:\Alexander.txt

'C:\Alexander.txt Send the first text line (row) to C:\Test.vbs line four replace 234.6656 with -123.48872

 '

'example click 2: -123.48872 Send text to C:\Test.vbs line four replace 234.6656 with -123.48872

(or another line to be able modify the line by me)

'after send to C:\Test.vbs delete first line (row) in C:\Alexander.txt

  Click Your.vbs Send and replace in C:\Test.vbs (one by one (to click mouse)
 'example click 1 Your.vbs: 234.6656
 'example click 2 Your.vbs: -123.48872
 'example click 3 Your.vbs: 456.75555
 'example click 4 Your.vbs: 345.56777853
 'example click 5 Your.vbs: -777.4455666
 'example click 6 Your.vbs: 778.522222245
 'example click 7 Your.vbs: Etc. to end last line C:\Alexander.txt**

After replace in C:\Test.vbs delete first text line (row) in C:\Alexander.txt

I want to Every click mouse to your Your.vbs to send first text line numbers C:\Alexander.txt to Test.vbs to replace....

I need your help Thank you very much for your help.


Solution

  • Try this!

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFileAlexRead = objFSO.OpenTextFile("C:\Alexander.txt", 1)
    
    strTextAlex = objFileAlexRead.ReadAll
    arrFileTextAlex = Split(strTextAlex,Chr(10))
    objFileAlexRead.Close
    
    Set objFileTest = objFSO.OpenTextFile("C:\Test.vbs", 1)
    strTextTest = objFileTest.ReadAll
    
    Set regEx = New RegExp
      regEx.Pattern = """(-*)\d+.\d+\"""
      regEx.IgnoreCase = True
    
    ReplaceTest = regEx.Replace(strTextTest, """" & Trim(Replace(arrFileTextAlex(0), vbCr, "")) & """")
    objFileTest.Close
    
    
    Const removalIndex = 0
    For x=removalIndex To UBound(arrFileTextAlex)-1
        arrFileTextAlex(x) = arrFileTextAlex(x + 1)
    Next
    ReDim Preserve arrFileTextAlex(UBound(arrFileTextAlex) - 1)
    
    Set objFileAlexWrite = objFSO.OpenTextFile("C:\Alexander.txt", 2)
    dim i
    For i = lbound(arrFileTextAlex) to ubound(arrFileTextAlex)  
            objFileAlexWrite.writeline arrFileTextAlex(i)  
        Next  
    objFileAlexWrite.Close
    
    Set objFileTestWrite = objFSO.OpenTextFile("C:\Test.vbs", 2)
    objFileTestWrite.writeline ReplaceTest
    objFileTestWrite.Close