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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file problem

Status
Not open for further replies.

Oostwijk

Technical User
Oct 19, 2003
82
NL
What am I doing wrong here ?
I've got a Drivelistbox named Drive2 and a Dirlistbox named Dir2. Now I want to store a file in the selected drive and directory. I tried it with:

Dim Dezedir As String
Dezedir = Dir2.Path + "\mdw.tst"
bestandsnummer = FreeFile
Open Dezedir For Output As bestandsnummer

but it gives me the error:
bad file name or number

 
Dim Dezedir As String
Dim bestandsnummer As String

Dezedir = Dir2.Path + "\mdw.tst"
bestandsnummer = FreeFile
Open Dezedir For Output As #bestandsnummer

Have a look at thread thread222-720427 I just replied to for more code!

Hope it helps.
 
hmmm, nope
I still get the same error.
 
bestandsnummer should be an integer, but it worked as a string for me also, I tried this code and it works...

Private Sub Command1_Click()
Dim Dezedir As String
Dim bestandsnummer As Integer

Dezedir = Dir2.Path + "\mdw.tst"

Debug.Print Dezedir 'See what filename it prints

bestandsnummer = FreeFile
Open Dezedir For Output As #bestandsnummer
Print #bestandsnummer, "hello"
Close #bestandsnummer
End Sub

Tell me that doesnt work ... ?? lol
 
eh, well I tried but it didn't help.

this is my exact code:

Private Sub Dir2_Change()
Dim Asperge As Integer, Dezedir As String
Text2.Text = ""
Dir1 = Dir1.List(Dir1.ListIndex)
bestandsnummer = FreeFile
Dezedir = Dir2.Path + "\mdw.tst"
Debug.Print Dezedir
MyFile = Dir(Dezedir)
If MyFile <> &quot;&quot; Then
Open Dezedir For Input As #bestandsnummer
Do
Line Input #bestandsnummer, aa$
xxx = InStr(aa$, &quot;@&quot;)
Bestandsnaam = RTrim$(Left$(aa$, xxx - 1))
If Bestandsnaam = Dir2.Path Then Text2.Text = Right$(aa$, Len(aa$) - xxx)
Loop Until EOF(bestandsnummer)
Close bestandsnummer
End If
End Sub
 
Here you go...

Private Sub Dir2_Change()
Dim Asperge As Integer
Dim Dezedir As String
Dim bestandsnummer As Integer
Dim aa As String
Dim xxx As Integer
Dim Bestandsnaam As String

Text2.Text = &quot;&quot;
Dir1 = Dir1.List(Dir1.ListIndex)
bestandsnummer = FreeFile

Dezedir = Dir2.Path
If Right(Dezedir, 1) <> &quot;\&quot; Then
Dezedir = Dezedir & &quot;\&quot; 'Make sure ends with &quot;\&quot;
End If
Dezedir = Dezedir + &quot;mdw.tst&quot;
Debug.Print Dezedir
MyFile = Dir(Dezedir)
If MyFile <> &quot;&quot; Then
Open Dezedir For Input As #bestandsnummer
Do
Line Input #bestandsnummer, aa$
xxx = InStr(aa$, &quot;@&quot;)
Bestandsnaam = RTrim$(Left$(aa$, xxx - 1))
If Bestandsnaam = Dir2.Path Then Text2.Text = Right$(aa$, Len(aa$) - xxx)
Loop Until EOF(bestandsnummer)
Close bestandsnummer
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top