![]() |
![]() |
#1 |
I ♥ BOINC!
Oct 2002
Glendale, AZ. (USA)
3×7×53 Posts |
![]()
I'm just learning vbs, and I have this working to my satisfaction, however, I know it's not the best way it can be done, so would appreciate any of you with vbs experience, to take a look and give me some pointers please.
Code:
Option Explicit Const ForReading = 1, ForWriting = 2, ForAppending = 8 Dim oFSO, oInFile, oOutFile Dim str_Input, str_Output, str_CurrentLine, str_CSV, MyArray, MyLine, UserName Dim MyDate, MyMO, MyDD, MyYY, MyDay, MyAMPM Dim MyTIME, MyHH, MyMM, MySS ' the path to the input and output file str_Input = "c:\Results.txt" str_Output = "c:\Results.csv" str_CSV="" Set oFSO = CreateObject("Scripting.FileSystemObject") ' If the file exists If oFSO.FileExists(str_Input) Then ' open the text file for input Set oInFile = oFSO.OpenTextFile(str_Input) ' create the csv file for output Set oOutFile = oFSO.CreateTextFile(str_Output,True) ' for each line in the input file Do While Not oInFile.AtEndOfStream ' read the line str_CurrentLine = oInFile.ReadLine() str_CurrentLine = Replace(str_CurrentLine, Chr(13), "") str_CurrentLine = Replace(str_CurrentLine, Chr(10), "") if Left(str_CurrentLine,5) = "user=" Then MyArray = Split(str_CurrentLine,"=",-1,1) UserName = MyArray(1) End If if Left(str_CurrentLine,1) = "[" Then ' If inStr(1,str_CurrentLine,"[") Then '[08/11/2008 06:55:34 AM] MyLine = Split(str_CurrentLine," ", -1, 1 ) MyDay = Split(MyLine(0),"/", -1 ,1 ) MyMO = Replace( MyDay(0), "[", "" ) MyDD = MyDay(1) MyYY = MyDay(2) MyTime = Split(MyLine(1),":") MyHH = MyTime(0) MyMM = MyTime(1) MySS = MyTime(2) MyAMPM = Replace( MyLine(2), "]", "" ) if MyAMPM = "AM" and MyHH = "12" Then MyHH = "00" End If If MyAMPM = "PM" and MYHH = "00" Then MyHH = "12" End If If MyAMPM = "PM" and MYHH = "01" Then MyHH = "13" End If If MyAMPM = "PM" and MYHH = "02" Then MyHH = "14" End If If MyAMPM = "PM" and MYHH = "03" Then MyHH = "15" End If If MyAMPM = "PM" and MYHH = "04" Then MyHH = "16" End If If MyAMPM = "PM" and MYHH = "05" Then MyHH = "17" End If If MyAMPM = "PM" and MYHH = "06" Then MyHH = "18" End If If MyAMPM = "PM" and MYHH = "07" Then MyHH = "19" End If If MyAMPM = "PM" and MYHH = "08" Then MyHH = "20" End If If MyAMPM = "PM" and MYHH = "09" Then MyHH = "21" End If If MyAMPM = "PM" and MYHH = "10" Then MyHH = "22" End If If MyAMPM = "PM" and MYHH = "11" Then MyHH = "23" End If End If If inStr(1,str_CurrentLine,"not prime.") Then str_CSV = "user=" & UserName & VBCrLf & "[" & MyYY & "/" & MyMO & "/" & MyDD & " " & MyHH & ":" & MyMM & ":" & MySS & "]" & VBCrLf & Str_CurrentLine Wscript.echo str_CSV ' output the data to the csv file oOutFile.WriteLine(str_CSV) End If If inStr(1,str_CurrentLine,"prime!") Then str_CSV = "user=" & UserName & VBCrLf & "[" & MyYY & "/" & MyMO & "/" & MyDD & " " & MyHH & ":" & MyMM & ":" & MySS & "]" & VBCrLf & Str_CurrentLine Wscript.echo str_CSV oOutFile.WriteLine(str_CSV) ' MsgBox "Prime Found!" & VBCr & "by: " & UserName & VbCr & Str_CurrentLine End If str_CSV="" LOOP ' Close the input and output file oInFile.Close oOutFile.Close ' Finished and exit End IF ' Tidy up Set oFSO = Nothing |
![]() |
![]() |
![]() |
#2 |
I ♥ BOINC!
Oct 2002
Glendale, AZ. (USA)
3·7·53 Posts |
![]()
Sorry, parsing this stuff
![]() Code:
user=sm5ymt [08/11/2008 06:02:40 AM] 319*2^587589-1 is not prime. Res64: 3A5C4150EB886509 Time : 951.0 sec. user=sm5ymt [08/11/2008 06:02:43 AM] 321*2^586014-1 is not prime. Res64: 0B4031B0A21DC39E Time : 37975.0 sec. user=sm5ymt [08/11/2008 06:02:43 AM] 313*2^586015-1 is not prime. Res64: 76EFC6E66F27D781 Time : 37973.0 sec. Last fiddled with by IronBits on 2008-11-09 at 18:40 |
![]() |
![]() |
![]() |
#3 |
May 2008
Wilmington, DE
22·23·31 Posts |
![]()
Sorry, not a VBS guy.
I was wondering though, if anyone has a vb script that will tell me how many lines are in a txt file? That or any other means of finding out. Manually is nice, but I keep having to take my shoes off. Last fiddled with by MyDogBuster on 2008-11-12 at 12:05 |
![]() |
![]() |
![]() |
#4 | |
Account Deleted
"Tim Sorbera"
Aug 2006
San Antonio, TX USA
10000101101112 Posts |
![]() Quote:
|
|
![]() |
![]() |
![]() |
#5 | |
Jan 2006
JHB, South Africa
100111012 Posts |
![]() Quote:
Code:
Option Explicit Dim oFSO, oInFile Dim str_Input, str_CurrentLine, Dim LineCount ' the path to the input and output file str_Input = "c:\Results.txt" Set oFSO = CreateObject("Scripting.FileSystemObject") ' If the file exists If oFSO.FileExists(str_Input) Then ' open the text file for input Set oInFile = oFSO.OpenTextFile(str_Input) LineCount = 0; ' for each line in the input file Do While Not oInFile.AtEndOfStream ' read the line str_CurrentLine = oInFile.ReadLine() 'Increment Line Count LineCount = LineCount +1 LOOP ' Close the input and output file oInFile.Close MsgBox "Total Lines: " & LineCount ' Finished and exit End IF ' Tidy up Set oFSO = Nothing Regards Patrick Last fiddled with by Patrick123 on 2008-11-12 at 12:58 Reason: Neatened the indentation |
|
![]() |
![]() |
![]() |
#6 |
May 2008
Wilmington, DE
22×23×31 Posts |
![]()
Thanks guys. Getting to cold to keep taking my shoes off.
Last fiddled with by MyDogBuster on 2008-11-12 at 13:14 |
![]() |
![]() |
![]() |
#7 |
I ♥ BOINC!
Oct 2002
Glendale, AZ. (USA)
3×7×53 Posts |
![]() |
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Rho code | Happy5214 | YAFU | 3 | 2015-11-01 21:54 |
Please help me with my code | daxmick | Programming | 15 | 2014-02-14 11:57 |
Code Help | Andrew | Programming | 12 | 2013-02-16 20:53 |
New Code | JohnFullspeed | Programming | 20 | 2011-09-04 04:28 |
Code | Primeinator | Software | 20 | 2009-06-11 22:22 |