Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

path

Posted on 1999-08-01
9
Medium Priority
?
251 Views
Last Modified: 2010-04-30
In a VB4 programm, as soon as the form is loaded, a small text-file named c.txt is been examined. The file has to be  in the windows directory and the path of the file is:
c:\windows\c.txt
The code is:

FileNum = FreeFile
Open "c:\windows\c.txt" For Input As FileNum
Close FileNum

But suppose that a user has the Windows installed in another directory, (named win or wingk or something similar and NOT Windows), how could I be sure then that the file c.txt will be found (with the statement OPEN) and be opened?
0
Comment
Question by:ote
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 4

Expert Comment

by:tmack
ID: 1528816
I would by default set up your app to look in the default C:windows directory however when an error occures have the user set this path VIA the commondialog box and thensave this path to a text file locally. You will then just read from this file the path of the c.txt file.
Heres some snitptis of code that may or may not help. I am not sure if these work in VB4 as I am mostly familur with VB 5 & 6 so I am hesitent to place code for you but if you need more just ask and I will throw some in here for you.



Set Fso = CreateObject("scripting.fileSystemObject")
If Fso.FileExist("c:\windows\c.txt") = false then

   if fso.fileexist("c:\appSetUp.text") = false then
      commondialog1.showOpen
      FilePath = Commondialog1.Filename
      Write this path to a text file
   else
      read from the c:\appsetup.text file the path to your c.txt file
   end if
end if

Hope I could be of some help for you.

T

 


0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 1528817
You might want to try the windir environment string.

  environ$("windir")
0
 
LVL 8

Accepted Solution

by:
vettranger earned 200 total points
ID: 1528818
Go to msdn.microsoft.com (no www. in front of this)

use the "search msdn" option

search for "Dirwalk"

You'll find a control that does exactly what you need. You'll need to be a registered VB user (or register when you go there), in order to download the control.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 15

Expert Comment

by:ameba
ID: 1528819
Use GetWindowsDirectory API
0
 
LVL 8

Expert Comment

by:vettranger
ID: 1528820
With respect to the other commenters, just use the Dirwalk control as proposed. I used to do all this other stuff too, and none of it worked reliably or easily (you'd be surprised how many users can't find a file with the Open File dialog control ... or maybe you wouldn't! LOL)

The dirwalk control will just find the file anywhere on the drive, quickly and reliably, and you'll wind up using it in many circumstances ... its already found its way into most of my projects for various uses. (Like to find the location of MSACCESS.EXE, no matter where the user has installed it, when I need to shell to it as a runtime to display a report.)
0
 
LVL 8

Expert Comment

by:vettranger
ID: 1528821
As an afterthought, another idea is to just keep your c.txt file in your application directory. You can ALWAYS easily find it then with :

f$=app.path & "\c.txt"
open f$ for input as #1
0
 

Author Comment

by:ote
ID: 1528822
Thanks for the answer.
I think the "dirwalk" must be the best solution.
The problem is that I cannot find it in the "msdn.microsoft.com"
I use the "search msdn" option looking for Dirwalk but nothing is founded.
Could I have your  help please?
0
 
LVL 8

Expert Comment

by:vettranger
ID: 1528823
Here's the URL (I was having trouble getting logged in to MSDN last night, or I would have included it then ... I was able to find it with the search but not get logged in to get to it. If you have any trouble getting to the URL, send me your Email address.

http://support.microsoft.com/support/kb/articles/Q175/2/14.ASP
0
 

Author Comment

by:ote
ID: 1528824
Thanks again.
I still have a probelm with the URL as I get the message:
"The file you requested could not be found"
My e-mail address is:
giann@techlink.gr

I really appreciate your help.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

688 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