Problems with Save Requester

Windows specific forum
Large
User
User
Posts: 56
Joined: Tue Apr 29, 2003 8:24 pm

Problems with Save Requester

Post by Large »

Hi Guys and Gals,

I'm using the code below to save a file from my fax program I am making, but I have a problem it will save a new file ok, but it won't overwrite an old file instead it creates a new one with a double extension.

IE : If I save a file as test.fxm, open the file in my program and make some changes then click save and select the file it creates another file called test.fxm.fxm, I want the save requester to overwrite the file if it exists, can someone please help me ?

Code: Select all

StandardFile$ = docsfolder$   ; set initial file+path to display 
Pattern$ = "Fxm (*.fxm)"
  Pattern = 0    ; use the first of the three possible patterns as standard 
  File$ = SaveFileRequester("Please choose fax to save . . .", StandardFile$, Pattern$, Pattern) 
  If File$
    CreateFile(0, File$+".fxm")
    WriteStringN(recipient$)
    WriteStringN(from$)
    WriteStringN(faxno$)
    WriteStringN(pages$)
    WriteStringN(date$)
    WriteStringN(copy$)
    WriteStringN(subject$)
    
    WriteStringN(message0$)
    WriteStringN(message1$) 
    WriteStringN(message2$)
    WriteStringN(message3$) 
    WriteStringN(message4$)
    WriteStringN(message5$) 
    WriteStringN(message6$)
    WriteStringN(message7$) 
    WriteStringN(message8$)
    WriteStringN(message9$) 
    WriteStringN(message10$)
    WriteStringN(message11$) 
    WriteStringN(message12$)
    WriteStringN(message13$) 
    WriteStringN(message14$)
    WriteStringN(message15$) 
    WriteStringN(message16$)
    WriteStringN(message17$) 
    WriteStringN(message18$)
    WriteStringN(message19$) 
    WriteStringN(message20$)
    WriteStringN(message21$) 
    WriteStringN(message22$)
    WriteStringN(message23$) 
    WriteStringN(message24$)
    WriteStringN(message25$) 
    WriteStringN(message26$)
    WriteStringN(message27$) 
    WriteStringN(message28$)
    WriteStringN(message29$) 
    WriteStringN(message30$)
    WriteStringN(message31$) 
    WriteStringN(message32$)
    WriteStringN(message33$) 
    WriteStringN(message34$)
    WriteStringN(message35$) 
    WriteStringN(message36$)
    WriteStringN(message37$) 
    WriteStringN(message38$)
    WriteStringN(message39$) 
    WriteStringN(message40$)
    WriteStringN(message41$) 
    WriteStringN(message42$) 
    WriteStringN(message43$)
    WriteStringN(message44$) 
    WriteStringN(message45$)
    WriteStringN(message46$) 
    WriteStringN(message47$)
    WriteStringN(message48$) 
    WriteStringN(message49$)
    WriteStringN(message50$) 
    WriteStringN(message51$)
    WriteStringN(message52$) 
    WriteStringN(message53$)
    WriteStringN(message54$) 
    WriteStringN(message55$)
    WriteStringN(message56$) 
    WriteStringN(message57$)
    WriteStringN(message58$) 
    WriteStringN(message59$) 
    WriteStringN(message60$) 
    WriteStringN(message61$)    
    
    CloseFile(0)
    
  EndIf   
Kind regards

Andy ( aka Large )
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post by aszid »

well, it looks like the pattern you set for the filename, is automatically being added to the filename

i would change this line:

Code: Select all

CreateFile(0, File$+".fxm") 
into these few lines:

Code: Select all

if ucase(right(file$,4)) <> ".FXM"
  file$ + ".fxm"
endif
CreateFile(0, File$) 
--Aszid--

Making crazy people sane, starting tomorrow.
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Re: Problems with Save Requester

Post by TerryHough »

Large wrote:..snip.... instead it creates a new one with a double extension.

Code: Select all

... snip...
 File$ = SaveFileRequester("Please choose fax to save . . .", StandardFile$, Pattern$, Pattern) 
  If File$
    CreateFile(0, File$+".fxm")
... snip ...
It is doing exactly what you told it to do. :)

SaveFileRequester returns in File$ the entered filename plus the default extendion you defined.

Then you use File$+".fxm" as your filename to create.

So, just use File$ like CreateFile(0,File$) and you will be OK.

Edited later:
Aszid replied while I was typing apparently and basically told you the
same thing, but there is no need to worry about the case of the
extension since you have already defined it for the SaveFileRequester.
Large
User
User
Posts: 56
Joined: Tue Apr 29, 2003 8:24 pm

Post by Large »

Hi Terry,

If I use just File$ and save a file as 'test' it doesn't add the extension on to the end, which makes the file not recognisable by the system.

If I call the file 'test.fxm' it saves it as a recognisable program file, if I then click on the file it loads back into my program if I make a change to the file and then click save and select 'test.fxm' it doesn't save the changes.

Oh dear ! :cry: Please help me !

Kind regards

Andy
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

Large wrote:Hi Terry,

If I use just File$ and save a file as 'test' it doesn't add the extension on to the end, which makes the file not recognisable by the system.
I should have been more specific I guess.

Try the code below for an example.

It will create an empty Andy.fxm file so there is one to select in the
SaveFileRequester.

The SaveFileRequester() returns the entire
Pathname+Filename+Extension when you select a file from the list.
If you type in just a filename SaveFileRequester returns only the
Pathname+Filename, and it is the same when you accept the default
filename too.

Try the following code both ways to see what happens.

Code: Select all

CreateFile(0,"C:\Temp\Andy.fxm")
CloseFile(0)
Pathname$        = "C:\Temp"
Extension$       = "fxm"
DefaultFilename$ = "test"
Filename$ = SaveFileRequester("Save a Fax file", Pathname$ + DefaultFilename$, "FAX file (*.fxm)|*.fxm|JPEG Format (*.jpg)|*.jpg|BMP Format (*.bmp)|*.bmp|PNG Format (*.png)|*.png", 0)
MessageRequester("Debug","The Filename$ contains: "+Filename$,0)
If Filename$
  Select SelectedFilePattern()
  Case 0                          ; FAX extension selected
    Extension$  = "fxm"
  Case 1                          ; JPG extension selected
    Extension$  = "jpg"
  Case 2                          ; BMP extension selected
    Extension$  = "bmp"
  Case 3                          ; PNG extension selected
    Extension$  = "png"
  EndSelect
  ; Same extension as loaded?
  If LCase(GetExtensionPart(Filename$)) <> Extension$
    Filename$ + "." + Extension$    ; Switched extensions
  EndIf
EndIf 
MessageRequester("Debug","The Filename$ contains: "+Filename$,0)
If CreateFile(0,Filename$)
  WriteStringN("This data is all I am going to write!")
  CloseFile(0)
Endif
Terry
jmf73
User
User
Posts: 10
Joined: Wed Dec 15, 2004 12:21 pm
Location: Australia

File problems

Post by jmf73 »

Hi there,
I came across the same problem and used to following code to fix it.

Code: Select all

       File = SaveFileRequester("Save file as..", StandardFile, Pattern, Patternc)
       If File
           Index = SelectedFilePattern()
           If (index=0) And (GetExtensionPart(File)="")
              File= File +".pop"
           EndIf
       EndIf
John Finney
Post Reply