Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 16th, 2007, 04:44 AM
Authorized User
 
Join Date: Jul 2006
Location: Kolkata, West Bengal, India.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to lawsoncobol
Default 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
Reply With Quote
  #2 (permalink)  
Old July 16th, 2007, 07:03 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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
Reply With Quote
  #3 (permalink)  
Old July 16th, 2007, 07:52 AM
Authorized User
 
Join Date: Jul 2006
Location: Kolkata, West Bengal, India.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to lawsoncobol
Default

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
Reply With Quote
  #4 (permalink)  
Old July 16th, 2007, 07:58 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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
Reply With Quote
  #5 (permalink)  
Old July 16th, 2007, 08:30 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ZipCode.txt sample extract file beath SQL Server 2005 6 May 17th, 2010 09:42 PM
read any ".txt" file RodrigoGuteriez C# 3 November 18th, 2008 12:07 PM
read txt file from vb6 poupis VB How-To 5 April 23rd, 2008 10:31 PM
How to read simple txt file from URL? takica General .NET 1 August 6th, 2005 01:02 PM
Read data from a text file (*.txt) adriant42 Excel VBA 2 June 4th, 2004 06:32 PM



All times are GMT -4. The time now is 01:09 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.