SAP GUI VBScript to cut & paste in chunks with data alteration - vbscript

To get around a runtime error I need to read from an SAP table AGR_1251 in chunks using VBScript when I run a (SE16 | AGR_1251) query. I get this error TSV_TNEW_PAGE_ALLOC_FAILED - No more storage space available for extending an internal table.
As a work around, we manually copy 750 roles from the user by roles at a time, add a "*" to those that end with a certain character, then paste this back into the multiple select dialog to get the the AGR_1251 extract results in chunks.
I can't figure out how to do this in vbscript. How do I programmatically chunk this data? Ideally I would deduplicate it as well, but its not required.
The code has to run on both vbscript and in javascript, so I can't use excel or other windows tools like wscript. The best idea I have so far is to scroll through and copy just the roles to a file, read them back into an array and dedupe as I read them, then alter them, then loop back through the list to chuck out the results.
This is WAY above my nearly nonexistant vbscript skills. I can't be the only one who has had this problem. Can anyone point me to examples code that does this?
I'm open to suggestions on a better approach as well. I think my solution is fugly to say the least.

OK, this code is fugly with some unneeded variables, but it works.
Sub Save_AGR_1251s(Tcodes_array,Chunk_size)
Go_AGR_1251
writelog("Processing " & ubound(Tcodes_array) & " Tcodes in AGR_1251...")
k = 0
s = Chunk_size
max = ubound(Tcodes_array)
part = 0
roles_processed = 0
For i = 0 To max Step s
Go_AGR_1251
session.findById("wnd[0]/usr/txtMAX_SEL").text = ""
session.findById("wnd[0]/usr/txtMAX_SEL").setFocus
session.findById("wnd[0]/usr/txtMAX_SEL").caretPosition = 11
session.findById("wnd[0]/usr/btn%_I1_%_APP_%-VALU_PUSH").press
k = i + s
counter = 0
part = part + 1
If k > max Then k = max End If
For j = i To k-1
' writelog("Save_AGR_1251s Processing Tcode: " & Tcodes_array(j))
If (Tcodes_array(j) <> "STMS" or Tcodes_array(j) <> "SCC4") Then
'NOTE: The slow insert is used on XXXX Prod as a work around to odd UI behavior - change with caution - But SLOW!!
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,7]").setFocus
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,7]").text = Tcodes_array(j)
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,7]").caretPosition = 1
'VKey 13 = Shift-F1 (insert new row)
session.findById("wnd[1]").sendVKey 13
If Debug_flag = True Then
writelog("i=" & i & " j=" & j & " k=" & k & " s=" & s &" max=" & max &" counter= " & counter)
writelog("part =" & part & " roles= " & roles & "roles_processed="& roles_processed & " Tcodes_array= " & Tcodes_array(j))
End If ' Debug_flag
counter = counter + 1
roles_processed = roles_processed + 1
End If ' Tcodes_array
Next 'for j to k
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,1]").setFocus
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,1]").caretPosition = 13
session.findById("wnd[1]/tbar[0]/btn[8]").press
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 45
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").select
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").setFocus
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxtDY_PATH").text = dir
file_name = AGR_1251_filename & "_Part_" & part & c_dash & postfix & Datafile_ext
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = file_name
writelog("Saving file: " & dir & file_name)
session.findById("wnd[1]/usr/ctxtDY_FILE_ENCODING").text = File_encoding
session.findById("wnd[1]/usr/ctxtDY_PATH").setFocus
session.findById("wnd[1]/usr/ctxtDY_PATH").caretPosition = 16
session.findById("wnd[1]").sendVKey 11
Go_Home
Next ' For i
End Sub
Note that you can do this much faster on most systems by simply doing this
for i = 1 to 100
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1," & 7 & "]").text = "Test " & i
next 'for i

Related

vbscript objExplorer.Document.Body.innerhtml does not work as local user from 3rd partry app

Ok gurus,
I am in no way a vbscript guy... and so need some serious hand-holding here!
I have a third-party program that allows custom actions via vbscript. I have this set up to open a web page as a pop-up like so (Just the piece that isn't working- code is much longer):
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExplorer = CreateObject("InternetExplorer.Application")
Do
crt.Sleep 100
Loop While objExplorer.Busy
szHTMLBody = _
"<font color='red'><b>Specify tech and truck:</b></font>" & _
"<hr>" & _
"<b><u>T</u>ech:</b>" & _
"<input type="text" name='tech' size='40' maxlength='512'>" & _
"<br>" & _
"<b><u>T</u>ruck:</b>" & _
"<input type=text name='truck' size='40' maxlength='512'>" & _
"<hr>" & _
"<button name='OK' AccessKey='O'><u>O</u>K</button>" & _
" " & _
"<button name='Cancel' AccessKey='C'><u>C</u>ancel</button>"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 200
objExplorer.Height = 500
objExplorer.Navigate "file://D:\test\Option.htm"
objExplorer.Document.Body.innerHTML = szHTMLBody
s = objExplorer.Document.Body.innerhtml
objExplorer.Visible = 1
objShell.AppActivate objExplorer
intMessage = Msgbox(s,4096+4, "Schedule")
This works just fine if I run the code from an elevated command prompt, changing the innerHTML. If I launch this by way of the third party app it runs ok but will not change the inner HTML. I added the 's' variable to try and catch the current innerhtml and that msgbox displays blank when run from the app but shows the correct text when run from that elevated prompt.
MORE DETAILS:
The vbs file being called resides on a server with the 3rd party app. The app itself is run from a Remote Desktop Server. The html file exists on the Remote Desktop server - and I have tried moving it to the server with the vbs file with no change.
I also tried creating a "launcher" script to run this script using Shellexecute runas; if I enter the Admin user/password it works as expected. So I then found and added a script to the "launcher" script that showed the user that launched the program. This (at least in my head) verified this permission issue.
I have no idea where to even begin with this; ideally this will be "headless" so any user can click the button calling the vbs script and it will run, modifying the html accordingly before the user sees the popup.
I have a similar popup, but I've used True and False for my objects instead of 1 and 0.
Function Main()
'Create blank Internet Explorer window
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "about:blank"
'Create list that will display specific details within the window
GrpType = Left(strPA, 5)
If GrpType <> "TTTT," And GrpType <> "3AYE," And InStr(GrpType, "NO,") = 0 Then
New_Type = GrpType
MyArray = Split(strPA, ",")
GrpType = MyArray(1)
n = 20
objIE.document.body.innerHTML = "<title>TIN NOT FOUND</title><p class='msg'>TIN Not found: <span>" & _
TIN & "</span></p><p class='not'>" & GrpType & _
"</p><p class='ctrl'><input type='hidden' id='Submit' name='Submit' value='0'><input type='submit' value='OK' id='SubmitButton' onclick='document.all.Submit.value=1' autofocus></p>"
Else
strPA = Replace(strPA, GrpType, "")
MyArray = Split(strPA, ",")
End If
o = 1
z = 1
'This sets up the list data to resemble an Excel spreadsheet
If GrpType = "TTTT," Or GrpType = "3AYE," Or InStr(GrpType, "NO,") <> 0 Then
For n = 0 To UBound(MyArray)
If Disp_Type = "simple" Then
If o = 6 And n <> UBound(MyArray) Then
FormRow = MyArray(n) & "</td></tr><tr><td>" & ""
o = 0
ElseIf n = UBound(MyArray) Then
FormRow = MyArray(n) & "</td></tr><table>"
Else
If o = 1 Then
FormRow = z & "</td><td>" & ""
z = z + 1
n = n - 1
Else
FormRow = MyArray(n) & "</td><td>" & ""
End If
End If
Else
If o = 10 And n <> UBound(MyArray) Then
FormRow = MyArray(n) & "</td></tr><tr><td>" & ""
o = 0
ElseIf n = UBound(MyArray) Then
FormRow = MyArray(n) & "</td></tr><table>"
Else
If o = 1 Then
FormRow = z & "</td><td>" & ""
z = z + 1
n = n - 1
Else
FormRow = MyArray(n) & "</td><td>" & ""
End If
End If
End If
o = o + 1
List = List & FormRow
Next
End If
'Set up the window metrics
objIE.Toolbar = False
objIE.StatusBar = False
objIE.Width = 1200
objIE.Height = 1800
objIE.Top = 50
objIE.Left = 50
'Set up the innerHTML code to display the list within the window
objIE.document.body.innerHTML = "<title>GROUP TYPE " & MyArray(2) & " FOUND</title><p class='msg'>Group Type " & MyArray(2) & " Returned for TIN: <span>" & _
TIN & "</span></p><table border=0><tr><th>Seq#</th><th>Group Name</th><th>MPIN</th><th>Group Type</th><th>Group Start Date</th><th>Group Term Date</th></tr><tr><td>" & List & _
"<p class='ctrl'><input type='hidden' id='Submit' name='Submit' value='0'><input type='submit' value='OK' id='SubmitButton' onclick='document.all.Submit.value=1' autofocus></p>"
'Allow the window to be viewed at this point
objIE.Visible = True
'Do this procedure until the user has clicked the OK/Submit button
Do Until FormExit = "GO"
If objIE.document.all.Submit.Value = 1 Then
objIE.Quit
SetEverythingToNothing
Exit Function
End If
Loop
End Function
What you get is a popup like this:
This can be ran from pretty much any application. I do my debugging in Excel VBA, but I've used Macro Express Pro to run it as well as running it as a stand alone script.
Well,
turns out after much head-banging that AppActivate and Visible were competing with one another somehow. Changing the order in the vb script has solved the problem.

vb6 winsock connection instead unlimited clients per devide to be reduced to 2

Hello ive got a client/server 2d mmorgp game plaing by us frinds and due to to many copies of the client ive tried to reduce the client to be opened to 2 clients per device but is not per device its on the network 2 clients . maybe i do somewhere mistake.
Sub ConnectionRequestCon(ByVal requestID As Long)
On Error Resume Next
Dim check As Integer
Dim LoggedOn As Integer
Dim NewIndex As Integer
Dim RandomCheck As Integer
NewIndex = GetFreeIndex
LogOutProcedure NewIndex
RandomizeConLandLaunch NewIndex
Load Main.Server(NewIndex)
Load Main.EngageTimer(NewIndex)
Main.Server(NewIndex).Accept requestID
AddServerLogText NewIndex & ": Connected [" & Main.Server(NewIndex).RemoteHostIP & "]"
RandomCheck = RandomNumber(1000, 30000)
SetConAuthNumber NewIndex, RandomCheck
Main.Server(NewIndex).SendData "1,Welcome To Xiaspora - " & TotalLogedInUsers & " Users Online" & Chr(13) & "34," & RandomCheck & Chr(13)
DoEvents
Do
check = check + 1
If Main.Server(check).State = 7 And Main.Server(check).RemoteHostIP = Main.Server(NewIndex).RemoteHostIP Then LoggedOn = LoggedOn + 1
Loop Until check = Main.Server.Count
If LoggedOn >= 4 Then CloseCon NewIndex 'with the number 4 reduce the clients per device . when is 7 is unlimited
End Sub
You are looping check from 1 to Main.Server.Count and check each Main.Server(check).State but you probably have unloaded socket controls already.
You have On Error Resume Next at the top of the code but consider that similar code like this
Dim lCount As Long
On Error Resume Next
If 1 / 0 > 0 Then lCount = lCount + 1
Debug.Print lCount
. . . prints 1 i.e. from If expression OERN gets "next" statement inside the If, no matter that it's on the same line as the If expression.
Now consider what happens when Main.Server(check).State is checked on an unloaded control. Because of the OERN this one will be counted towards LoggedOn which is clearly not what you want to do.
With OERN in this case you might want to reverse the If expression like this
If Main.Server(check).State <> 7 Then
'--- do nothing
ElseIf Main.Server(check).RemoteHostIP = Main.Server(NewIndex).RemoteHostIP Then
LoggedOn = LoggedOn + 1
End If
. . . so that when accessing Main.Server(check).State bombs out it "enters" the If block and there is nothing to do there.

Access VBA slow after first run

I have a general question. I think it is not code related.
I have a small access program using forms, SQL and VBA.
The VBA mainly calculate pretty simple things, but with a lot of data and some SQL runs. I have a status bar where i can see "percentage done".
I start the script by clearing all tables and after that running all queries to make sure they're empty.
I then run through the data. It works good.
It takes around 2 mins.
I then do it again.
But now it takes 10 mins. For the same procedure.
If i restart access, it takes 2 mins the first time, then 10 mins afterwards.
When i restart access, the tables are still filled. So it is not because they are empty.
Is there a command to clear all memory or whatever might be needed?
Any suggestions?
The code that runs 10x slower:
For counter = 1 To n_bins
Application.Echo False
DoCmd.OpenQuery "q_PowerBinned"
If DCount("*", "q_PowerBinned") = 0 Then
DoCmd.OpenQuery "q_000"
DoCmd.RunSQL "DELETE * FROM q_000"
DoCmd.Close
strTMP = (counter - 1) * [Forms]![f_main]![PowerBinCombo] & " - " & counter * [Forms]![f_main]![PowerBinCombo] & " kW"
strSQL = "INSERT INTO q_000 (Bin, Zero1, Zero2, Zero3, Zero4, Zero5) VALUES ('" & strTMP & "','0','0','0','0','0');"
DoCmd.RunSQL strSQL
DoCmd.OpenQuery "q_Move000"
DoCmd.Close
Else
DoCmd.Close
End If
DoCmd.OpenQuery "q_Average_Temp"
DoCmd.Close
DoCmd.OpenQuery "q_MoveAverage"
DoCmd.OpenQuery "q_PowerBinned_VG"
If DCount("*", "q_PowerBinned_VG") = 0 Then
DoCmd.OpenQuery "q_000_VG"
DoCmd.RunSQL "DELETE * FROM q_000_VG"
DoCmd.Close
strTMP = (counter - 1) * [Forms]![f_main]![PowerBinCombo] & " - " & counter * [Forms]![f_main]![PowerBinCombo] & " kW"
strSQL = "INSERT INTO q_000_VG (Bin, Zero1, Zero2, Zero3, Zero4, Zero5) VALUES ('" & strTMP & "','0','0','0','0','0');"
DoCmd.RunSQL strSQL
DoCmd.OpenQuery "q_Move000_VG"
DoCmd.Close
Else
DoCmd.Close
End If
DoCmd.OpenQuery "q_Average_Temp_VG"
DoCmd.Close
DoCmd.OpenQuery "q_MoveAverage_VG"
Application.Echo True
' Theoretical of Measured Power Curve
Percentage = ((counter) / (n_bins)) * 100
strStatus = "Binned " & Percentage & " %"
Call dsp_progress_AfterUpdate
Me.Refresh
dsp_progress.SetFocus
dsp_progress.SelStart = 0
dsp_progress.SelLength = 0
DoEvents
Next counter
This happens for one of my access databases. I find that if I do a compact & repair after the appropriate tables have been emptied, the vba run-time returns to the short time again. Not the most elegant of solutions I must admit.

How do I find a repeating set of cells in Excel?

I Have a 2100 Rows and 6 Columns Table
Throughout the table there are only 12 Possible values, say A,B,C,D,E,F,G,H,I,J,K,L
The 12th value L is just a blank filler. It denotes blank cell.
Since there are only 11 possible values througout the table, patterns are observed.
First a Pattern Appears and it is later repeated somewhere in the table.
There can be any number of Patterns, but i have a specific format for a pattern which is to found and reported that way.
Solutions in EXCEL-VBA, PHP-MYSQL or C are welcome.
I have attached an example of what Iam looking for. Suggestions are most welcome to refine
the questions.
Information & Format : http://ge.tt/8QkQJet1/v/0 [ DOCX File 234 KB ]
Example in Excel Sheet : http://ge.tt/69htuNt1/v/0 [ XLSX File 16 KB ]
Please comment for more information or specific requirement.
Please try the code below, change the range to what you need it to be and the sheet number to the correct sheet number (I wouldn't put your full range in just yet because if you have 1000 pattern finds, you'll have to click OK on the message box 1000 times, just test with a partial range)
This will scan through the range, and find any pattern of two within a 10 row range, if you need it to find bigger patterns, youll need to add the same code again with an extra IF statement checking the next offset.
This will only find it if the same pattern exists and the same column structure is present, but its a start for you
Works fine on testing
Sub test10()
Dim rCell As Range
Dim rRng As Range
Set rRng = Sheets("Sheet1").Range("A1:I60") '-1 on column due to offset
'Scan through all cells in range and find pattern
For Each rCell In rRng.Cells
If rCell.Value = "" Then GoTo skip
For i = 1 To 10
If rCell.Value = rCell.Offset(i, 0).Value Then
If rCell.Offset(0, 1).Value = rCell.Offset(i, 1) Then
MsgBox "Match Found at: " & rCell.Address & ":" & rCell.Offset(0, 1).Address & " and " & rCell.Offset(i, 0).Address & ":" & rCell.Offset(i, 1).Address
End If
End If
Next i
skip:
Next rCell
End Sub
***UPDATE***
I have updated my code, the following now finds the pattern wherever it may appear in the next 10 rows:
Sub test10()
Dim rCell As Range
Dim rRng As Range
Dim r1 As Range
Dim r2 As Range
Set rRng = Sheets("Sheet1").Range("A1:I50") '-1 on column due to offset
i = 1 'row length
y = 0 'column length
'Scan through all cells in range and find pattern
For Each rCell In rRng.Cells
If rCell.Value = "" Then GoTo skip
i = 1
Do Until i = 10
y = 0
Do Until y = 10
xcell = rCell.Value & rCell.Offset(0, 1).Value
Set r1 = Range(rCell, rCell.Offset(0, 1))
r1.Select
ycell = rCell.Offset(i, y).Value & rCell.Offset(i, y + 1).Value
Set r2 = Range(rCell.Offset(i, y), rCell.Offset(i, y + 1))
If ycell = xcell Then
Union(r1, r2).Font.Bold = True
Union(r1, r2).Font.Italic = True
Union(r1, r2).Font.Color = &HFF&
MsgBox "Match Found at: " & rCell.Address & ":" & rCell.Offset(0, 1).Address & " and " & rCell.Offset(i, y).Address & ":" & rCell.Offset(i, y + 1).Address
Union(r1, r2).Font.Bold = False
Union(r1, r2).Font.Italic = False
Union(r1, r2).Font.Color = &H0&
End If
y = y + 1
Loop
i = i + 1
Loop
skip:
Next rCell
End Sub

Faster Way To Examine Text in AutoIt?

I'm attempting to use AutoIt to examine a text file and output select lines into a CSV. The problem I keep running into is that it takes forever. The current method examines a single line at a time. It can burn through 5-10 lines per second, but I'm looking for something much faster within the AutoIt framework.
Code:
#include <File.au3>
$xnConfirm = False
$xnConfirmMsg = 0
while $xnConfirm = False
$xnFile = FileOpenDialog("File to Examine...","%userprofile%","All (*.*)") ;InputBox("File???", "Which file do you want to review?","C:\")
If FileExists($xnFile) = True Then
$xnConfirm = True
Else
$xnConfirmMsg = msgbox(1,"File Not Found...",$xnFile & " does not exist." & #crlf & "Please select another file.")
EndIf
WEnd
$xnConfirm = False
$xnConfirmMsg = 0
while $xnConfirm = False
$xnTargetFile = FileOpenDialog("Location to Save to...",$xnFile & " - output.csv","All (*.*)");"%userprofile%\Documents\output.csv"
;FileSaveDialog("Location to Save to...","%userprofile%","All (*.*)",16,"output - " & $xnFile & " - output.csv") ;
Consolewrite("Outputting to " & $xnTargetFile & #crlf)
if fileexists($xnTargetFile) then
$xnConfirmMsg = msgbox(4,"Overwrite?","Are you sure you want to overwrite " & #crlf & $xnTargetFile)
if $xnConfirmMsg = 6 Then
$xnConfirm = True
filedelete($xnTargetFile)
EndIf
Else
$xnConfirm = True
EndIf
WEnd
progresson("Line count","Verifying the number of lines in " & $xnFile)
$xnFileLine = _FileCountLines($xnFile) ;InputBox("Number of lines","How many lines are in this document?",10000)
consolewrite("Loading "& $xnFile & " with " & $xnFileLine & " total lines." & #crlf)
progressoff()
local $hfl = FileOpen($xnFile,0)
FileWrite($xnTargetFile,"")
FileOpen($xnTargetFile, 1)
$i = 1
ProgressOn("Creating CSV","Extracting matching data.","",0,0,16)
$xnTargetLine = 1
FileWriteLine($xnTargetFile,"Timestamp,Message,Category,Priority,EventId,Severity,Title,Machine,App Domain,ProcessID,Process Name,Thread Name,Win32 ThreadId")
While $i < $xnFileLine
;$xnCurrentLine = FileReadLine($xnFile,$i) ;Old Settings
$xnCurrentLine = FileReadLine($hfl,$i)
;MsgBox(1,"",$xnCurrentLine)
Select
Case stringinstr($xnCurrentLine,"Timestamp:")
$xnTargetLine = stringmid($xnCurrentLine,12,stringlen($xnCurrentLine) - 12 + 1) & ","
Case stringinstr($xnCurrentLine,"Message:")
$xnTargetLine = $xnTargetLine & stringmid($xnCurrentLine,10,stringlen($xnCurrentLine) - 10 + 1) & ","
Case stringinstr($xnCurrentLine,"Category:")
$xnTargetLine = $xnTargetLine & stringmid($xnCurrentLine,11,stringlen($xnCurrentLine) - 11 + 1) & ","
Case stringinstr($xnCurrentLine,"Win32 ThreadId:")
$xnTargetLine = $xnTargetLine & stringmid($xnCurrentLine,16,stringlen($xnCurrentLine) - 16 + 1) & #crlf
FileWriteLine($xnTargetFile,$xnTargetLine)
case Else
consolewrite("Nothing on line " & $i & #crlf)
EndSelect
$i = $i + 1
ProgressSet(round($i/$xnFileLine * 100,1),$i & " of " & $xnFileLine & " lines examined." & #cr & "Thank you for your patience.")
WEnd
ProgressOff()
To address the question of what this is doing, I'm reading a log file similar to a trace log. I want the events to output to a CSV so I can examine trends. The format in the log file looks like this:
Timestamp: 9/26/2013 3:33:23 AM
Message: Log Event Received
Category: Transaction
Win32 ThreadId:2872
I know that's the code format, but I hope it's easier to read.
(I wanted to add a comment asking for a sampling of the data being read in, however I don't have enough points yet...)
Depending on the size of the input file I recommend reading the entire file into an array in one swoop using _FileReadToArray() and then looping through the array in memory (instead of keeping access to the file open during the entire process). In addition, I wouldn't write to the output file each time either - I'd write to a string and then save the string when completed.
Something like:
$outputFileData = ""
$inputFileData = _FileReadToArray($xnFile)
For $Counter = 1 to $inputFileData[0]
$tmpLine = $inputFileData[$Counter]
Select
Case stringinstr($tmpLine,"Timestamp:")
$outputFileData = stringmid($tmpLine,12,stringlen($tmpLine) - 12 + 1) & ","
Case stringinstr($tmpLine,"Message:")
$outputFileData &= stringmid($tmpLine,10,stringlen($tmpLine) - 10 + 1) & ","
Case stringinstr($xnCurrentLine,"Category:")
$outputFileData &= stringmid($tmpLine,11,stringlen($tmpLine) - 11 + 1) & ","
Case stringinstr($xnCurrentLine,"Win32 ThreadId:")
$outputFileData &= stringmid($tmpLine,16,stringlen($tmpLine) - 16 + 1) & #CRLF
case Else
ConsoleWrite("Nothing on line " & $i & #crlf)
EndSelect
Next
FileWriteLine($xnTargetFile, $outputFileData)
(Please note I didn't include any error checking nor did I check it for errors :)
Im not sure if it would be really faster but, you could use Regexp.
If you could tell me a little bit more what the rules are here:
Case stringinstr($xnCurrentLine,"Timestamp:")
$xnTargetLine = stringmid($xnCurrentLine,12,stringlen($xnCurrentLine) - 12 + 1) & ","
Case stringinstr($xnCurrentLine,"Message:")
$xnTargetLine = $xnTargetLine & stringmid($xnCurrentLine,10,stringlen($xnCurrentLine) - 10 + 1) & ","
Case stringinstr($xnCurrentLine,"Category:")
$xnTargetLine = $xnTargetLine & stringmid($xnCurrentLine,11,stringlen($xnCurrentLine) - 11 + 1) & ","
Case stringinstr($xnCurrentLine,"Win32 ThreadId:")
$xnTargetLine = $xnTargetLine & stringmid($xnCurrentLine,16,stringlen($xnCurrentLine) - 16 + 1) & #crlf
FileWriteLine($xnTargetFile,$xnTargetLine)
case Else
consolewrite("Nothing on line " & $i & #crlf)
and if you could give me 2 or 3 example lines i could try to make you a, Regexp function wich i think will be much faster.
Edit:
I Made an example Script.
If the Input File looks something like this:
Timestamp: 9/26/2013 3:33:23 AM
Message: Log Event Received
Category: Transaction
Win32 ThreadId:2872
Then This Script works just fine
#include <Array.au3>
Local $file = FileOpen("InputFile.txt", 0)
$sText = FileRead($file)
$aSnippets = StringRegExp($sText,"(?:Timestamp:|Message:|Category:|Win32 ThreadId:)(?: )?(.+)",3)
_ArrayDisplay($aSnippets)
The result is an array Containing the Following things:
[0] = 9/26/2013 3:33:23 AM
[1] = Log Event Received
[2] = Transaction
[3] = 2872
etc.
If you want to combine these 4 lines in one, try to use a for loop (if you want to, i can make you one)
For 100 Lines he Needs 0.490570878768441 Miliseconds to store every Value in one array.
There is an other possible idea.
You could copy the Input File, rename it, and then Delete every useles Data out of it.
That would be very easy with RegularExpressions and probably even faster.
If you show me a example of the Input File and how the Output file should look like i could try :)

Resources