VB 6.0 - Working with text files

Asked By Mahima Chandani
12-Jan-10 06:56 AM

Hello,

I want to write a code that will read contents of a text file from a particular folder & add the contents into MS-Access database, after reading the file move it to another folder & move on to the next file in the folder.

I already have a code to read the contents of a file but my problem is that for faster execution I want my application to run in multiple instances.

If I run the script as is then the same file will be read by all instances.

Can you help me with a solution that if I run 3 instances of the application then all read different files & not the same file.

 

 

FileStream Lock  FileStream Lock

12-Jan-10 08:21 AM

When you open your file for reading, you can lock the file (assuming you are using FileStream to open the file).  The FileStream object has a Lock method which locks the file so that no other process can access it.

Dim FileSt As FileStream = New FileStream("test.dat", FileMode.Open, FileShare.None)

        Try
            FileSt.Lock(0100)
            Console.WriteLine("Locked")
        Catch Ex As Exception
            Console.WriteLine(Ex.Message)
        End Try

So even if you have multiple instances of your application, check for files if they are locked before you process them.

Regards,
http://www.sql-server-helper.com/sql-server-2008/sqlconnection-connection-string.aspx

FileStream Lock  FileStream Lock

12-Jan-10 09:28 AM

Hello,

Got your point. But will I also be able to use Try, Catch in VBA ??

If no then what will be the command for the same.

Will try using the code snippet you have mentioned & let you know if it works.

 

Regards,

Mahie

VBA Error Handling  VBA Error Handling

12-Jan-10 09:33 AM

In VBA, the equivalent of the Try/Catch is the On Error command:

On Error Goto 0
On Error Resume Next
On Error Goto <label>:

Regards,
http://www.sql-server-helper.com/sql-server-2008/convert-latitude-longitude-to-geography-point.aspx

Create New Account
help
SQL Server Error: 18452 SQL Server Connection failed: SQLState: '28000' SQL Server Error: 18452 [Microsoft][ODBC SQL Server Driver][SQL Server] Login failed for user 'sa'. Reason: Not
Connectivity issue (SQL server error: 53 and 17) SQL Server SQL server 2000 standard edition, Microsoft Windows NT 5.2 (3790) One of my application running Microsoft access database connects to this server. Yesterday I applied a update to the application and now we are not able to
SQL Server Error 5520 SQL Server I am getting the SQL Server Error 5520 when i try to add a FILSTREAM file into a filegroup. I am trying
MSDE on Windows 2003 R2 box, new DL385G6 - Install Fails during SQL Services SQL Server I have been finding that I am having trouble with the Crystal Reports Server XI installation failing when it is dealing with SQL. So, as a thought and in case there was something wrong with my SQL portion of the isntall. I thought ok, I will try installing the actual MSDE application direct from Microsoft. So, I downloaded the MSDE for SQL 2000 (which is msde2000a.exe), set my switches and off to the races. It quit seconds left to the installation and bombed with the same errors as the Crystal Reports Server install. The error is the same whether I try to install MSDE by itself or
Additonal thoughts, you should be able to connect to SQL Server via SQL Server SQL Server Additonal thoughts, you should be able to connect to SQL Server via SQL Server Management Studio. This will provide you with whether or not SQL Server