mersenneforum.org  

Go Back   mersenneforum.org > Prime Search Projects > No Prime Left Behind

Reply
 
Thread Tools
Old 2008-11-09, 14:34   #1
IronBits
I ♥ BOINC!
 
IronBits's Avatar
 
Oct 2002
Glendale, AZ. (USA)

3×7×53 Posts
Default A little help with VBS code

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
IronBits is offline   Reply With Quote
Old 2008-11-09, 18:40   #2
IronBits
I ♥ BOINC!
 
IronBits's Avatar
 
Oct 2002
Glendale, AZ. (USA)

45916 Posts
Default

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
IronBits is offline   Reply With Quote
Old 2008-11-12, 11:59   #3
MyDogBuster
 
MyDogBuster's Avatar
 
May 2008
Wilmington, DE

54228 Posts
Default

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
MyDogBuster is offline   Reply With Quote
Old 2008-11-12, 12:42   #4
Mini-Geek
Account Deleted
 
Mini-Geek's Avatar
 
"Tim Sorbera"
Aug 2006
San Antonio, TX USA

17×251 Posts
Default

Quote:
Originally Posted by MyDogBuster View Post
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.
If you open a .txt file in Metapad it shows how many lines the file has on the status bar (along with what line you're on).
Mini-Geek is offline   Reply With Quote
Old 2008-11-12, 12:57   #5
Patrick123
 
Patrick123's Avatar
 
Jan 2006
JHB, South Africa

157 Posts
Default

Quote:
Originally Posted by MyDogBuster View Post
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.
This is just a blatant plagiarization of IronBits Script, I simply ripped the insides out and added a line count variable.

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
Patrick123 is offline   Reply With Quote
Old 2008-11-12, 13:14   #6
MyDogBuster
 
MyDogBuster's Avatar
 
May 2008
Wilmington, DE

54228 Posts
Default

Thanks guys. Getting to cold to keep taking my shoes off.

Last fiddled with by MyDogBuster on 2008-11-12 at 13:14
MyDogBuster is offline   Reply With Quote
Old 2008-11-12, 14:23   #7
IronBits
I ♥ BOINC!
 
IronBits's Avatar
 
Oct 2002
Glendale, AZ. (USA)

3×7×53 Posts
Default

http://unxutils.sourceforge.net/
Get those ported unix utils and use

wc -l filename ;)
IronBits is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
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

All times are UTC. The time now is 08:54.

Tue Mar 31 08:54:26 UTC 2020 up 6 days, 6:27, 0 users, load averages: 1.15, 1.23, 1.41

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.