Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Visual Basic





See Related Forum Messages: Follow the Links Below to View Complete Thread

OpenTextFile
Is there a possibility to avoid the Error if a text file doesnt exist?

This is the line:
Set text = fso.OpenTextFile("text.txt", 1, 0)

And I dont want to Use the Error# because it's to general. I need a different solution.

Can anyone help me?

Anita

OpenTextFile
HI.

I keep getting runtime error 5 on other
computers.. and I was wondering if I
need a reference to use the code

Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile(WindowsDir & "folter.ini", 1)

File.ReadLine
sDates(0) = GetDate
sDates(1) = nDecrypt(File.ReadLine)


File.Close

?

Question Regarding OpenTextFile
The following example read the first line of the file, which contains multiple lines. How do I move to the next line?

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.OpenTextFile("C:Endicia-output.prn", ForReading, TristateUseDefault)
    x = f.ReadLine

Thanks.

Alex

OpenTextFile In Notepad???
Hi all, how can I open a textfile in my program with notepad???

I've tried to find examples but I can't find some straight simple code that will help me.

Thanks for any help

Open FileName For Input Vs. FileSystemObject.OpenTextFile
Have strange issue at work. Need to read a report that has been saved as a .txt file, pull out certain info and save in an Excel file for my user.

Using Mid function to grab very specific data from each line read in from input file.

Using the old Open FileName For Input As #1, my app gets tripped up when it encounters some non-ascii characters that are in a specific column of the input file.

However, if I use FileSystemObject as follows, I can access all info I need without any issues whatsoever with the non-ascii values:


Code:
Set fs = New FileSystemObject
Set input_file = fs.OpenTextFile(strMFM032Path, ForReading, TristateFalse)
Do While Not input_file.AtEndOfStream
strFullRecord = input_file.ReadLine
Can anyone explain why that might be?

Open FileName For Input Vs. FileSystemObject.OpenTextFile
Have strange issue at work. Need to read a report that has been saved as a .txt file, pull out certain info and save in an Excel file for my user.

Using Mid function to grab very specific data from each line read in from input file.

Using the old Open FileName For Input As #1, my app gets tripped up when it encounters some non-ascii characters that are in a specific column of the input file.

However, if I use FileSystemObject as follows, I can access all info I need without any issues whatsoever with the non-ascii values:


VB Code:
Set fs = New FileSystemObjectSet input_file = fs.OpenTextFile(strMFM032Path, ForReading, TristateFalse)Do While Not input_file.AtEndOfStream        strFullRecord = input_file.ReadLine


Can anyone explain why that might be?

Locking The Name Of A File
Is there a way that I can set the name of an excel file in VBA and 'lock' it so that users cant change the name of the file?

Locking A File
Hi....I am working on a an application that needs files to be locked when they are being read......so that other function that tries to delete file cannot do it......In my case now it gives error when I try to delete a file that is being used at that time.....some way to lock the file

Rome was not built in a day......and by a single person...so lets get together

ADO Locking Mdb File
Since I am using ADO in a mdb (VBA) application, the mdb file often becomes blocked to changes because another user (myself) is owning the database. I suspect this is related to ADO multiuser recordsets, but have no idea about how to start tracking the problem and unlocking the mdb without exiting (so losing all changes made in source code)

any clue, please?

thanks

File Locking
Hi,

I'm building a backup server with specific demands. The most important demand is safety.

The question to you guys is:
How can I preform safe file locking? (by safe I mean virus safe)

I know there is the "Open For Binary Access Lock Read Write" method, but doesn't that load everything to memory?

The idea is kind of like building a virus vault.

I hope anyone can help me

Thanks,

File Locking
Does anybody know how to check the locked status of a file in VB6

Locking A File
What is the easiest way to lock a file from someone deleting it or changing the contents while my program is running?

Prefer a way that wont hog memory

Locking A File
Hi everyone

Just a simple thing realy, My program refers to a certain txt file, when the program is running I DONT want the user to be
able to browse to the file and open it (with notepad or somthing).

Is there a better way of doing this other than just opening an instance of the file in vb eg:

Code:
open "C:file.txt" for input as #1


Thanks
Oly



Edited by - blade_240 on 11/6/2003 1:18:58 PM

File Locking
Hello,

I have a macro that looks for a datasource which is a TXT file in a certain directory. Sometimes an error occurs saying that the source cannot be found, but it is there. The Data Source is being generated by another program and I am thinking that the external program is locking the file to long, and when the macro kicks in as the file is locked the macro cannot open it.

Has anyone got some code that I can put into my VBA macro to detect when the Data Source is unlocked.

Thanks

BazzaW.

Locking A File With VB 6.0
I am currently involved in developing a biometric security program which works on the basis of finger print identification . I am only a begginner and have no idea how to interface my sw with system so that i could some how lock and unlock files.
I have absolutely no idea how to do this so plz help plz
contact acmbtcs@yahoo.com

File Locking
I was wondering if any of you VB gurus could help me find a way
to lock certain files so that they cannot be written to or
deleted while the program is not running so that no one can
tamper with any files that the program uses or creates.
Something similar to the file sharing lock used in locking
databases, but that will remain locked even when the program ends until the program later unlocks
them. If anyone has any ideas at all then please e-mail me at
encina@oxy.edu.
Thanks in advance,

Locking A Text File
Hi
I have a .csv file that I am locking in code using Lock intFileNum. This is fine and locks the file if the file is opened usiong the code. But I need to know if the file has been opened manually by a user. Does anyone know a way I can check if a .csv file is been manually opened.

Thanks

Paul

VB File Locking On Novell Vs. W2K
I have a VB6 program that is run on a network. The program tries to open and lock a file (OPEN FNAME$ FOR BINARY LOCK READ WRITE) when it is started. When the program is located on a Novell server hard drive (F, it runs just fine when executed by network workstation computers (F:APPMAIN.EXE). When the program is located on a Windows 2000 server hard drive, the first executed copy of the program runs fine. But the second and each additional executed copy of the program pauses for almost 10 seconds while the program is trying to lock the file that is already locked. Does anyone know why the locking works just fine on a Novell server but causes an annoying delay on a Windows 2000 server? My guess is that there is some 'retry lock' or 'open file timeout' setting that is higher on Windows than on Novell. Is there some setting on a Windows 2000 server or some VB statement that will fix this lock delay problem?

Locking A Text File
Is there any way I can protect(from being deleted) text files created by my program

Locking A Folder Or File
I want to lock a folder (or a file if it canīt be done with a folder) that can only be accessed by entering a password and when youīre done with the folder/file it locks again.

Have tried to do programs that uses the open statement (that opens the file directly after you entered the p-word) or open dialog box which pops up when you have entered the password.

Problem here are that the folder/file arenīt that protected, if you know itīs location you can just simply open it (unless you hid it well )

Donīt know if this can be solved with subclassing, I hope not since I donīt know anything about it.

Thankful for all help

VB6 And MSAccess - File Locking
Hi all.

Question: In a multiuser environment, using VB6 as the client front end, class files, project ADO reference set, with ADO objects and MSAccess as the database. What are the settings in the ADO object to properly set the file locks to avoid inconsisent data across the various clients?

Is this correct:

Dim oRs As ADODB.Recordset
Dim lvArrayReturn As Variant

Set oRs = New ADODB.Recordset

oRs.ActiveConnection = oConn
oRs.CursorLocation = adUseServer
oRs.CursorType = adOpenDynamic
oRs.LockType = adLockOptimistic


I had been creating the object and passing it a valid SQL statement and once the data was retrived I destroyed this object. I assume once the object was destroyed the lock was gone (is this correct)?

Using ADO objects is there a "proper" way to maintain file locking to keep the data consistent across all clients or atleast advise the client a record they wish to modify has been or is in the process of being modiied by another user?

Note: I'd much prefer to avoid using the ADO data control.

Thanks

Brent

Methods For Locking A File
Can someone give me as many methods for locking a file as possible(with examples)? To me, locking a file mean that it can't be read or written to, by any program. Thanks

Locking Database File *.mdb
hello friends,

I am developing a database project of 'fees collection'.So I want to lock my database file(*.mdb) so it cant be accessed by the user without password through my project as well as through the Microsoft Access.So help me for How to lock the database file and access through the VB code.

Locking A .pdf File To An Individual IP
Is it possible to lock down a .pdf file (or even an .exe) to a particular IP address during a download???

So if someone wanted a certain file or program they could download it from my site and wouldn't be allowed to share or distriubute it. Without obtaining a release code or authorization from myself? Could the program limit the number of times it is shared or distributed from a certain IP address?

Just curious... I think this would be a cool tool to develop. Thanks!

Locking MS-Access MDB File
I have a msaccess Mdb file.I am using it through VB.I
want that I want to use this mdb file through Vb
alone.if i open through Msaccess.It should not be
accessed .is it possible to do it?

Locking The File Or Folder
is there any API function which let not a folder or file be visible on hard drive?

File Locking Error
Hello All

I am working on a program that uses ado to update an access 2000 database. The program crashes with the error "File Sharing Lock Count Exceeded". If I contiune the program from the debug point it contiunes to run for a few minutes before it crashes again. Does anybody have any Ideas?? Here is a sample of the code

Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strTemp1 as String
Dim strTemp2 as String
Set con = New ADODB.Connection
con.Open ("Provider=Microsoft.jet.oledb.4.0; data source=c:db1")

Set rst = New ADODB.Recordset

rst.Open "Test", con, adOpenDynamic, adLockPessimistic

Do Until rst.EOF
If rst(1).Value <> "" Then
strTemp1 = rst(1).Value
strTemp2 = Trim$(strTemp1)
'Other Functions are preformed here
'
'
If strTemp1 <> strTemp2 Then

rst.Update rst.Fields(1).Name, strTemp2 'Always Crashes Here

End If
End If
rst.MoveNext
Loop
End Sub


Thanks

Peter

Locking A File From Opening?
I'm want to have a file that a person will not be able to open it but they will have to make a copy of that file to get it open. Is it possible to do it in VB? If yes, how? Thanks

File Locking Override
Is there a way to override the OS file locked protection? i.e. an ldb got hooked, no one is really using it, but Access is still thinking that someone has the database open... the only way out is restarting the pc where the database resides so it could be freed and then repaired.

PD, already got all ms tools and as far as I know none of them cuts or clears the ldb. ...

Problems With File Locking
Hi,

To retain compatibility with an old system i need to use byte range file locking on a random access file. Ive tryed to do it using the code below but i cannot get it to work as the handle request doesnt work in 32 bit mode ? anyone have any ideas

'
'
Declare Function lockfile Lib "Kernel32" Alias "LockFile" (ByVal hFile As Long, ByVal dwFileOffsetLow As Long, ByVal dwFileOffsetHigh As Long, ByVal nNumberOfBytesToLockLow As Long, ByVal nNumberOfBytesToLockHigh As Long) As Long
'
'
'
' buffer is previously opened data file.
Sub bmfilelock(buffer, record, rc)
Dim sizeoffile As Long
Dim hdl
sizeoffile = LOF(buffer) + record
hdl = FileAttr(buffer, 2) '' error hear.
rc = lockfile(hdl, sizeoffile, 0, 1, 0)
End Sub
'
'
'

File Locking / Open Mode
Hi All

Consider the following:

Code:
Open "C:FileName.Ext" For Input As #FileNumber

Will VB lock the file "C:FileName.Ext" when calling the above? I have an application that reads a template file from a server into a string array, but if the file is locked and two clients try to generate the same template at the same time, will it fail?

I know that VB locks a file when using "Open for OUTPUT" or "APPEND", but I have never had an issue with the "INPUT" mode. (Or rather, have never tested this scenario )

If VB locks a file when reading, is there a way to specify that VB should use a "shared" read mode for the file? Perhaps a "wait for file to be available" mode will also do?

Any help appreciated.

Record-locking File Not Being Deleted
Hi,

I have a small application that connects to an Access database, makes a change in one row, then disconnects. While it's connected, it creates a record-locking file (.ldb), but this doesn't seem to be removed when the user disconnects from the database. The only way to clear it is to open and close the database in Access.

This is the code (in a module):

VB Code:
Option Explicit 'The connection object for the database, used throughout the applicationPublic objConn As ADODB.Connection 'A function to create the database connection'-Requires a path to the database (strPath)'-Requires a password for the database (strDatabasePassword)'-Returns true if connection made'-Returns false if no connection as database does not existFunction ConnectToDatabase(ByVal strPath As String, _  ByVal strDatabasePassword As String) As Boolean    'Change the pointer to an hourglass    Screen.MousePointer = vbHourglass        'If the database exists    If Dir(strPath) <> "" Then        'Make objConn a new instance of the ADODB.Connection class        Set objConn = New ADODB.Connection            'Define the connection string for the database        '-Microsoft Jet 4.0 is the Provider        '-The database path is passed as an argument to the function        '-Access mode is not limited to prevent errors        '-The user connects as Admin to allow any changes to be made        objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _          "Data Source=" & strPath & ";" & _          "Mode=Share Deny None;" & _          "User ID=Admin;"              'The password for the database is passed as an argument to the function        objConn.Properties("Jet OLEDB:Database Password") = strDatabasePassword         'Open the connection object        objConn.Open                'Connection made        ConnectToDatabase = True    Else        'If the database does not exist, return false        ConnectToDatabase = False    End If        'Set the pointer back to normal    Screen.MousePointer = vbDefaultEnd Function 'Routine to disconnect from the databaseSub DisconnectFromDatabase()    'Check that the connection is not already closed    If objConn.State <> adStateClosed Then        'Close the connection        objConn.Close    End If        'Set it to nothing    Set objConn = NothingEnd Sub


Any ideas?

Document And File Locking Using Class
By using this code:

VB Code:
Open FileName For Input Lock Read Write As #FF

We're able to lock that file, however, the file number will reach
its limit when more files are added.

So I guess writing a class which every instance of it run on its
own and so there's no file number limit...hehe

I post this thread because I remember there're many threads
which asked for file locking method, apart from manipulating
the FAT entry, which VB is quite uncapable

Disabling File Locking In MS Access?
Is there a way to disable file locking? I have a database that links to tables in SQL Server, so it can't be a backend. The problem with this is, the database can only be opened by one user. This is MS Access 2003 (defaults to MS Access 2000 format), "Shared" and "No Locks" are clicked.

This is the way the database is laid out -

- The database has two parts, job notices and resumes.
- There is a web application where clients can search job notices, but can add/edit resumes.
- The database end is only used by supervisors who can add/edit job notices.
- There is a third part in which uses a DTS packages that reads from two databases (originally two MS Access databases until I moved it to SQL Server) which generates two reports for a 3rd party software.

I'm not the main programmer of this database (we're actually short on programmers due to a couple retiring), but I do help out with it. Now, I recently found out (and the thing's supposed to go into use this week) that multiple people are supposed to use the MS Access database. The problem is that it will say someone else has the database open.

I've tried the following -

1 - Backend. This works great if the actual tables are in the backend, but... if the web application tries to access a table that the Access database is using (i.e., a bound combo box in a search form on the MS Access database), it will say it can't lock the file. (Now, I've noticed that if I have several instances of the web application running, and loop through accessing the database a few hundred times, it will "break" the locked file... atleast until the server with the database is rebooted...) It also seems that two MS Access files can access the same data, and it doesn't care, but when the web application tries to use it, it gets the error. It seems MS Access doesn't like sharing with .NET very well.

Just to note, this database has quite a few fields that are bound directly to the table. I've removed some, since refreshing the page (i.e., when they wanted categories and subcategories) would add new records, for example.

2 - System DSN file. This works great since the web application can access the tables without worrying about locked files. However, MS Access can't have a backend with linked tables to a SQL Server database. So, it's stuck with 1 MS Access database file which only one person can use at a time.


So, how can I disable the locked file? (without resorting to breaking the locked file with multiple instances of a web application with a database connection loop) I also don't want to edit the registry, as other databases are on the same server, too.



Edited by - mdprogrammer on 3/5/2007 6:54:35 AM

File Locking Conflict When Creating .HTM
I am using VBA within Excel2003. The VBA creates an HTM version of my spreadsheet page, using commands as shown below.

Set rngConvert = wrkFile1("NH_PROD.xls").ActiveSheet.Range("a1:h84")

strHTMFilePath = "\NR-fp06GroupsSHARENH_PROD1.htm"

intResult = htmlconvert(rngConvert, False, False, _
False, 1252, strHTMFilePath)

The problem is that when the VB is run, it should always overwrite the old HTM file with the new file. (Note: the HTM file is always in use, open 24 hours a day, 7 days a week and being displayed by Internet Explorer. Internet Explorer is occasionally refreshed, which reloads the page and the problem with content is then seen)

However, sometimes when the VB is run it just appends the new HTML content to the end of the old HTML content, giving me a webpage that is twice as long as it should be, with a mix of old and new content! I always want the new HTM file to completely overwrite the old HTM file. I think I have a "file locking conflict" (?) What code snippet can I use to resolve this? Thanks

Locking An Excel File After A Period Of Time
I am trying to put a time dependant password on an Excel workbook/file so that after a certain amount of time/ or date the workbook totally locks itself and becomes unusable.

I want to do this to protect the intellectual property within it after someone has checked over the logic.

Is this possible? does anyone have any ideas about how I might do it?

(PS I'm not a VB expert so please be gentle!!)

Random Access File, Record Locking
My code uses the Lock #n,lrn% statement to lock a record while it is modified - the code is a follows:

Open tFName$ for Random Access Read Write Shared as #1 Len=Len(RecType)
Lock #1, 2
Get #1, 2, RecType
'update record code
Put #1, 2, RecType
Unlock #1, 2
Close #1

However, when another instance of the program (run across the network) tries to access record number 2, the system seems to hang for a long time (10 seconds) before returning with the error Err = 70 (Permission denied).

I would like to be able to shorten the time this takes - I guess its some sort of timeout value somewhere...

Does anyone have any ideas?

Thanks
Jez

Multiple User File Queueing / Locking
I'm sure there's an api to see if a file is locked, but I don't know what it is. That's why we have error handling. You should get an error 70 (Permissioned denied) if the file is locked.

Also, you're only locking it for reading, but not for writing. That means another user can write to the file.

You may want to change the line to Lock Read Write.

VB App : NT File Locking (which Users Have Files Open) HELP!
I have to write an app in VB5 to query files on a network and report back which user's currently have them open.

NT Server Manager does it but in an ugly clunky way. I was wondering if anyone know of a cool way to do it.

I have looked through the WinAPI and there are a couple of almost useful things in there.

Thanks for your time,

Stuey, Liverpool, England

(Forever Everton)

Locking Excel File So It Cannot Be Opened While Processing
My little app will create a new spreadsheet from a template. There are two issues I have:

1. If someone open the new file while my app still processing/importing data, then the app will crash. Is there a way to lock the file so it cannot be opened (or can only be opened read-only). Or maybe there is a better way than .save?
Code:Public Sub Init(ByVal TemplateFile As String, ByVal ReportFile)
    Set oBook = oExcel.Workbooks.Add(TemplateFile)
    oBook.SaveAs ReportFile
    'processing
    'oBook.Save
    'processing
    'oBook.Save
    ....
    'oBook.Save

2. Is there a "best practice" to avoid ghost excel process (in task manager) when the app crash? What kind of error handling is considered "best practices?"

Thanks!

Locking Textbox Without Locking Scrollbars
ok here's the thing i need to prevent even the cursor from being inside a text box due to a bit of a text problem the text box will start outputting text at wherever the cursor is creating a problem for stupid users. so i need to lockdown the textbox AND the cursor. not a big deal normally but i also need the scrollbars from the scrollbar property inside the text box to be operational even when everything else is locked down. I have tried setting the enabled property of the text box to false but that kills the scrollbars too i have also tried putting the text box in a picture box and disabling the picture box to lock it down but once again it kills the scrollbars. i'm trying to avoid using an outside scrollbar object. any ideas?

HOW TO : Use The Record Locking (not Page Locking) With VB 6.0 And Jet 4.0
Hi,

Is is possible to use the real record locking (not page locking) with VB 6.0 and Jet 4.0 ?

If yes, how to that ?

Thank you,

Michael
http://members.xoom.com/mcrcompany

Overflow Problem When Locking A Range In A Binary File
Hello

I have a small problem with VB6 and the lock and unlock commands. The code is

dim nFile as integer
Dim nStart as double
Dim nEnd as double

Open (cfilename) for Binary Access Read Write Shared as #nfile
nStart = 4000000001#
nEnd = 4000001001#
lock #nfile, nStart to nEnd

This generates an overflow and the lock cannot happen.

The above example works if the nStart and nEnd is dropped down to 200000XXXX when nStart and nEnd are Declared as long

I assume this is a limit to VB6 and it cannot handle locks of files with files over 2,147,483,647 bytes or have i made a mistake ?

Any help would be appreciated.

File Locking Conflict When Create HTML Page
I am using VBA within Excel2003. The VBA creates an HTM version of my spreadsheet page, using commands as shown below.

Set rngConvert = wrkFile1("NH_PROD.xls").ActiveSheet.Range("a1:h84")

strHTMFilePath = "\NR-fp06GroupsSHARENH_PROD1.htm"

intResult = htmlconvert(rngConvert, False, False, _
False, 1252, strHTMFilePath)

The problem is that when the VB is run, it should always overwrite the old HTM file with the new file. (Note: the HTM file is always in use, open 24 hours a day, 7 days a week and being displayed by Internet Explorer. Internet Explorer is occasionally refreshed, which reloads the page and the problem with content is then seen)

However, sometimes when the VB is run it just appends the new HTML content to the end of the old HTML content, giving me a webpage that is twice as long as it should be, with a mix of old and new content! I always want the new HTM file to completely overwrite the old HTM file. I think I have a "file locking conflict" (?) What code snippet can I use to resolve this? Thanks

File Locking Application Windows Xp Sp2 Error 0xC0000005
Hello,

I am getting 0xC0000005 error when I try to create a copy of new file and save the new file in temp folder.

Please help me, have installed windows xp sp2.

Need Help For Cross-platform File Locking In Visual Basic
Hi, Anybody know how to play around this:

We have application which runs on Windows 98/2K/XP.
Multiple user can run it at same time.
When one user wants to update data, data file will be locked
at this moment nobody is allowed to update it until first updating is finished.
This file is on Windows NT/2000 Server.

When a user whose computer system is Windows 98 updates file,
other users can not update, however when a user whose OS is other than Windows
98
update this file, the windows 98 user can updates file at same time.

any body had meet this problem? And anybody has any ideas how can I play around
it.

We used VB6 to develop this application on Windows 2000.

Thanks

Fred

Locking Up
I have made 2 games now but everytime i run one of them it seems that they all lock up. for Pong it makes it work up until it gets to make the ball and paddle to put on... And then it doesnt work. they keys dont work on it either (escape, up and down etc.). i made it make the sprite but i took out the rending part because there is no animation to it and it kept being a pain with errors. that could be the problem though. then. for my monster shooter game. it s done but when it loads the game i have 2 forms. one where you press the button. Start. Then once that form is hidden. They are both invisible and it freezes my pc. what should i do?

Locking ???
hii all,
Is begintransaction locks the whole table or row level locking.???
pls help it out

Row Locking
I'm writing a multi-user application in VB6. I pull a record from a table using an ADO recordset (forward and readonly), display it, and close the recordset. Then the user has the option to make changes to this record (they have to press a button to enter this mode), so at this point I'd like to lock the record (one row) so no one can make changes to it, but I would like to allow other users to read it. Now, if a second user reads the same record and then tries to click on the Edit button I want to tell them that the record is locked. Is there a simple way to do this?. I'm using SQL 7, and all my selects, inserts and updates are done through stored procedures, I even use .BeginTrans/.CommitTrans to make sure that my updates/inserts are not half way done.
Thanks a lot,

Monica

Copyright Đ 2005-08 www.BigResource.com, All rights reserved