 |
Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

July 16th, 2007, 04:44 AM
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
need sample code for read txt file
Hi all,
I want a sample code, which can read data from txt file and store it in a table , actually my requirement is to count lines of code i have written in a txt file ( total lines of code - comments lines (* at seventh column )
Please help
mail id : sparsh_mba2003@yahoo.com
Thanks and Regards
Lawson, COBOL
__________________
Thanks and Regards
Lawson, COBOL
|

July 16th, 2007, 07:03 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Can you post a couple lines from the text file? This will help in knowing how to capture the data. Then post what the table will look like that you want to store the data in, WITH some sample data. For example, if your file is:
SampleTextFile001.txt
- line of code
- line of code
- //comment line
- line of code
And your table is:
tblCodeFile
CodeFileID - autonumber PK
FileNameAndPath - text
LinesOfCode - number
And your sample data is:
tblCodeFile
1
C:\SampleData\SampleTextFile001.txt
3
then it will be easier to write knowing this structure and outcome.
To get started, you will want to use Scripting.FileSystemObject, which is documented on MSDN.
mmcdonal
|

July 16th, 2007, 07:52 AM
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Text file name - C301PD ( it does not have extension as txt )
location C:\c
- line of code
000500 C301S1-TRANSACTION SECTION 10.
000600******************************************** ********************
000700 C301S1-START.
000800
000900 PERFORM 200-EDIT-TRAN
001000 THRU 200-END.
001100
001200 IF (NO-ERROR-FOUND)
001300 PERFORM 400-PROCESS-TRAN
001400 THRU 400-END.
001500
001600 GO TO C301S1-TRANSACTION-END.
001700
001800******************************************** ********************
001900 200-EDIT-TRAN.
002000******************************************** ********************
002100
002200 PERFORM 210-EDIT-ACCESS
002300 THRU 210-END.
002400
002500 IF (ERROR-FOUND)
002600 GO TO 200-END.
//commented line
where ever there is * in seventh column( place) starting from left that is commented line
example
001800******************************************** ********************
is a commented line above
My Table defination would be
1.field1-line number in the file (Primary key )
2. field2-char in 7th column of file
ignore rest of it
My requirement
To count what is excat number of lines of code
= Total number of lines - commented lines count
so i need to find count of lines which has * at the seventh place in file in each line
Thanks and Regards
Lawson, COBOL
|

July 16th, 2007, 07:58 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
You can do this without storing every single line in the table. The code counter can be made to do this arithmetic for you. From this sample, it could return and store 19 (22-3=19). Do you want it to store this value? Or do you want it to store every complete line of code, or do you want it to store every line of code at the 7th chraracter, etc? Answer that question and I can post the code.
mmcdonal
|

July 16th, 2007, 08:30 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
This code returns 19 from your sample text file:
sFile = "C:\SampleCodeFile.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(sFile) Then
Set objFile = objFSO.OpenTextFile(sFile, 1)
Do Until objFile.AtEndOfStream
sLine = objFile.ReadLine
iComment = InStr(sLine, "*")
If iComment = 0 Then
iCount = iCount + 1
End If
Loop
End If
iCount = 19.
Are you using DAO or ADO to add this to a table? I use ADO so would do this:
sSQL = "SELECT * FROM tblMyTextCounterTable"
Set rs = New ADODB.Recordset
rs.Open sSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
rs.AddNew
rs("FileNameAndPath") = sFile
rs("LinesOfCode") = iCount
rs.Update
rs.Close
mmcdonal
|
|
 |