I am having a problem trying to compare a file string to see if the save as file string needs to be overwritten. The logic, I believe, is to compare the 'save as string' with the already open 'file string'. Does this make sense? When the Save File dialog comes up, I need to compare the save as filename with the already open filename, and if its the same name, then ask to be overwritten. I'm not sure where to start. I believe the file extension, '.las' for example, will need to be removed, and then a comparison made. Can anyone help? Thanks in advance
When user opens a file via your code and the common dialog, the file name is retrieved for you and thus you should save that into a variable. From there if user alters the file and selects save, the file name will be the same and the file contents overwritten with the new information. However, if user selects save as, as you have pointed out, then once again the common dialog returns you a path/file name and all you need to do is to compare the two... -
Dim Ans As Integer
-
If OrigFileName = SaveAsFileName Then
-
Ans = MsgBox("Overwrite file?", vbYesNoCancel,"")
-
If Ans = vbYes Then
-
'save code here
-
ElseIf Ans = vbNo Then
-
'reshow saveas dialog here or do a recursive call to whatever function this is
-
ElseIf Ans = vbCancel Then
-
'do nothing
-
End If
-
Else
-
'Save Code goes here
-
End If
-
Good Luck
7 1258
When user opens a file via your code and the common dialog, the file name is retrieved for you and thus you should save that into a variable. From there if user alters the file and selects save, the file name will be the same and the file contents overwritten with the new information. However, if user selects save as, as you have pointed out, then once again the common dialog returns you a path/file name and all you need to do is to compare the two... -
Dim Ans As Integer
-
If OrigFileName = SaveAsFileName Then
-
Ans = MsgBox("Overwrite file?", vbYesNoCancel,"")
-
If Ans = vbYes Then
-
'save code here
-
ElseIf Ans = vbNo Then
-
'reshow saveas dialog here or do a recursive call to whatever function this is
-
ElseIf Ans = vbCancel Then
-
'do nothing
-
End If
-
Else
-
'Save Code goes here
-
End If
-
Good Luck
Thanks for the help. Just what I was looking for.
I keep getting a runtime error '70', access denied. What does this mean? Code is as follows: -
Dim Ans As Integer
-
'check if originalfile matches saveasfilename
-
If tFile = fSave Then
-
Ans = MsgBox(fSave & " already exists. Do you want to overwrite file?", vbquestion+vbYesNoCancel, "Save As")
-
If Ans = vbYes Then
-
'save code here
-
Kill tFile '<<<this is the problem>>>
-
If LCase(Right(fSave, 4)) = ".las" Then
-
' 'copy temp file
-
FileCopy "C:\Temp.dat", fSave
-
Else
-
FileCopy "C:\Temp.dat", fSave & ".las"
-
End If
-
Else If Ans = vbNo Then
-
'reshow saveas dialog here
-
With CommonDialog1
-
.Filter = "All Files|*.las*|"
-
.InitDir = fSave
-
.DialogTitle = "Save File As"
-
.ShowSave
-
End With
-
fSave = CommonDialog1.FileName
-
Else If Ans = vbCancel Then
-
'do nothing
-
End If
-
Else
-
'Save Code goes here
-
FileCopy "C:\Temp.dat", fSave & ".las"
-
End If
-
I'm not really sure how to approach this. The savefile dialog pops up to save the file. If the user selects the same filename, it should overwrite the file, but it doesn't. If the user enters a different name, it saves properly. Any suggestions? Thanks again
Okay, when you first open the file, how do you do it? Open Statement?... -
Open SomeFilePathName For Input As #1
-
Do you close your connection to the opened file?
If not, there is your error as you still have the file open and therefor cannot delete it.
Good Luck
I am using the code below to reference the file: -
Set fso = CreateObject("Scripting.FileSystemObject")
-
Set objstream = fso.opentextfile(tFile, 1, False, 0)
-
tFile is referencing a file such as "C:\Temp\Temp.dat"
Is there any specific way to close the file, if using filesystemobject? I've tried just "Close" so it would close anything opened, but it didn't work. Thanks again.
I had resolved the issue. I just needed to close the fso.objstream:
Thanks for all your help. My software is now 100% completed, thanks to you.
Not a problem, glad you got it solved...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: agent349 |
last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1
== array2)). However, I've been trying to compare two arrays using
pointers with no success. Basically, I want to take three...
|
by: Dr. StrangeLove |
last post by:
Greetings,
Let say we want to split column 'list' in table lists
into separate rows using the comma as the delimiter.
Table lists
id list
1 aa,bbb,c
2 e,f,gggg,hh
3 ii,kk
4 m
|
by: Steve Jorgensen |
last post by:
Hi all,
Frankly, this is such an off-beat thing, I don't know if anyone else here will
ever have the same issue. Just in case anyone does, though...
I needed to be able to search for the...
|
by: theBestFriend |
last post by:
If I type in the vualue && from the standard input and store it into
myInputString variable, I expected that expression if(myInputString ==
"&&") will evaluate to true, but it doesn't.
Can you...
|
by: JSheble |
last post by:
I realise .NET has all these great objects, specifically strings, but is it
really necessary to create a string variable (object) just to compare two
string values?
For example, I'm looking at...
|
by: Trint Smith |
last post by:
Ok,
My program has been formating .txt files for input into sql server and
ran into a problem...the .txt is an export from an accounting package
and is only supposed to contain comas (,) between...
|
by: Opettaja |
last post by:
I am new to c# and I am currently trying to make a program to retrieve
Battlefield 2 game stats from the gamespy servers. I have got it so I
can retrieve the data but I do not know how to cut up...
|
by: Pugi! |
last post by:
hi,
I am using this code for checking wether a value (form input) is an
integer and wether it is smaller than a given maximum and greater then
a given minimum value:
function...
|
by: Andrea |
last post by:
I want to write a program that:
char * strplit(char* str1, char *str2, char * stroriginal,int
split_point)
that take stroriginal and split in the split_point element of the
string the string...
|
by: shadow_ |
last post by:
Hi i m new at C and trying to write a parser and a string class.
Basicly program will read data from file and splits it into lines then
lines to words. i used strtok function for splitting data to...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |