Solved

cant find new file

Posted on 1998-07-26
2
131 Views
Last Modified: 2010-05-18
Hello I got his pice of code, trying to read a file, I get a path/access error.
Do you know what I am doing wrong.
The should be of anyname.job, and shall show up in the textfield. It is to read an autogenerated file, when it shows up.
It is written in the timer_time proc.


sti = "C:\Guestlog\"

Dir1.Path = sti
Dir1.Refresh
File1.Pattern = "*.*"
File1.Refresh

If File1.ListCount > 0 Then
f = FreeFile
Open sti & File1.filename For Input As f
Text1.Text = Input$(LOF(f), f)
Close

End If
0
Comment
Question by:CATT
2 Comments
 

Author Comment

by:CATT
ID: 1466773
Edited text of question
0
 
LVL 6

Accepted Solution

by:
alamo earned 80 total points
ID: 1466774
One big problem is that File1.filename gives you the selected filename, and File1.refresh clears the selection. Therefore file1.filename is blank and you are trying the equivalent of:

Open C:\Guestlog\" For Input As f

which won't work.

What you want to do is use the Dir function:

fname = Dir(sti & "*.*")
if fname <> "" then
    f = FreeFile
   Open sti & fname For Input As f
    Text1.Text = Input$(LOF(f), f)
    Close
End If

Hope this helps!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now