Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the problem?

Status
Not open for further replies.

Gti

Programmer
Jul 23, 2001
99
PT
The Visual Basic gives a "Bad Filename or Number" error...
Usualy this happens when we open a file that is already open, and i think it's not the case!

Here is my code... I expect that someome can help me...



Public Sub ScanFonteFicheiro(Ficheiro As String,dirdestino As String)

Dim FichSaidaHtm, NomeFichTmp, NomeFichHtm, inline, Path, Ficheirocls As String
Dim Decresce, totalchar, FichNum As Integer
Dim infile As Byte

infile = FreeFile

Path = Ficheiro
totalchar = Len(Path)
Decresce = totalchar - 3
NomeFichTmp = Left(Ficheiro, Decresce)
NomeFichHtm = NomeFichTmp & "htm"

FichSaidaHtm = dirdestino & "\" & NomeFichHtm

MsgBox NomeFichHtm

'Open Ficheiro For Input As #infile
Open FichSaidaHtm For Append As #2

FichNum = 1

Print #2, &quot;<html>&quot;
Print #2, &quot;<head>&quot;
Print #2, &quot;<title>&quot; & Ficheirocls & &quot;</title>&quot;
Print #2, &quot;<link rel = 'stylesheet' href = ' Print #2, &quot;</head>&quot;
Print #2, &quot;<body class = 'FixedLeft'>&quot;

Close #2

While Not EOF(Ficheiro)

DeclaracaoPublica inline, FichNum

'Close #infile
'

Wend

End Sub



If anyone can give me an help i will tkx ;-)
 
Hi,

You are using Freefile to open 'Ficheiro', but a fixed number (2) to open 'FichSaidaHtm'. Always use FreeFile!

-------------------------------------------------
InFile= Freefile
open 'myfile.txt' for Input as #InFile

AppFile = FreeFile
open 'appendfile.txt' for append as #AppFile

'Code here

Close InFile, AppFile
-------------------------------------------------

I can see that you have commented one of your open statements out....


Sunaj
 
Tkx sunaj but the error persists :-(

I have done in the way you have said...

Tkx anyway, if you got any ohter ideia... i'm pleased to know it
;-)
 
Public Sub ScanFonteFicheiro(Ficheiro As String, dirdestino As String)

On Error GoTo e_ScanFonteFicheiro

Dim FichSaidaHtm, NomeFichTmp, NomeFichHtm, inline, Path, Ficheirocls As String
Dim Decresce, totalchar, FichNum, appfile As Integer
Dim infile As Byte

infile = FreeFile
appfile = FreeFile

Path = Ficheiro
totalchar = Len(Path)
Decresce = totalchar - 3
NomeFichTmp = Left(Ficheiro, Decresce)
NomeFichHtm = NomeFichTmp & &quot;htm&quot;

FichSaidaHtm = dirdestino & &quot;\&quot; & NomeFichHtm

MsgBox NomeFichHtm

Open Ficheiro For Input As #infile
Open FichSaidaHtm For Append As #appfile

FichNum = 1

Print #appfile, &quot;<html>&quot;
Print #appfile, &quot;<head>&quot;
Print #appfile, &quot;<title>&quot; & Ficheirocls & &quot;</title>&quot;
Print #appfile, &quot;<link rel = 'stylesheet' href = ' Print #appfile, &quot;</head>&quot;
Print #appfile, &quot;<body class = 'FixedLeft'>&quot;

Close #appfile

While Not EOF(Ficheiro)

DeclaracaoPublica inline, FichNum

Close #infile


Wend

e_ScanFonteFicheiro:
ErrHandle &quot;ScanFonteFicheiro&quot;
ErrContinue
Exit Sub
End Sub

----------------------------------------------------

here is my code... already with the changes that you said me to do ;-)
 
You have to open the file before you use freefile again (or freefile will return the same number!):
-------------------------------------------------
InFile= Freefile
open 'myfile.txt' for Input as #InFile

AppFile = FreeFile
open 'appendfile.txt' for append as #AppFile

'Code here

Close InFile, AppFile
-------------------------------------------------
!!NOT!!:
-------------------------------------------------
InFile= Freefile
AppFile = FreeFile

open 'myfile.txt' for Input as #InFile
open 'appendfile.txt' for append as #AppFile

'This is wrong!

Close InFile, AppFile
-------------------------------------------------


Sunaj

 
I dont know if this is your problem or not, but you need to put an EXIT SUB command before your e_ScanFonteFicheiro: label, or your error handler will fire every time !

Dan.
 
The error persists...
The problem isn't with the number of the file, VB gives me a &quot;Bad File or Number&quot;,idon't know sure what this mean, but the numbers now are good and still happen this problem :-(
 
off the top of my head i think the line :

While Not EOF(Ficheiro)

should read :

While Not EOF(#inFile)

Dan.
 
You are also closing the file before the WEND statement :

While Not EOF(Ficheiro)

DeclaracaoPublica inline, FichNum

Close #infile


Wend


should be :

While Not EOF(Ficheiro)

DeclaracaoPublica inline, FichNum

Wend

Close #infile




 


If 'Ficherio' is the input file name including the full path then 'FichSaidaHtm' will come out with the path repeated because you add it:

FichSaidaHtm = dirdestino & &quot;\&quot; & NomeFichHt

Solution: Call the sub with no path and add the path before you open your input file
OR
dont add the path to your output file (append)

Sunaj
 
Tkx to all... but the problem was mine... OPS!
I was putting a variable with &quot;s:\temp\s:\temp&quot;

i feel so stupid :-Anyway tankx to all ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top