Solved

Windows folder--win95 vs. Win98???

Posted on 1998-09-10
3
144 Views
Last Modified: 2011-10-03
I have the need to capture into a variable the path to the
Windows folder--that is, the folder where windows.exe and
.ini files are stored. I've tried this approach to get it:

     WinPath = environ("windir")

which I picked up from a help file somewhere. It works fine
when run on any PC with Windows 95, but it crashes with
the following error message when run on a Windows 98 PC:

     "Can't find project or library"

After this, VBA goes into the debug mode and highlights my
line with the environ() function. Is Windows 98 structured
significantly different from Windows 95 (I have Win95 on my
PC)? Microsoft does not seem to care about documenting
arguments usable with environ(), so I'm stuck.

Anybody know what's going on here?
0
Comment
Question by:JimKirby
3 Comments
 

Accepted Solution

by:
bjbenoit earned 100 total points
ID: 1434209
you may want to consider using the Windows API to get the informaion.

Private Declare Function GetWindowsDirectory _
  Lib "kernel32" _
  Alias "GetWindowsDirectoryA" _
  (ByVal lpBuffer As String, _
    ByVal nSize As Long) _
  As Long

0
 
LVL 2

Expert Comment

by:wj7ster
ID: 1434210
Declare this is the declaration section of a form:


Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long


Put this code somewhere in a procedure:
   
Dim sBuffer     As String
Dim lSize       As Long
Dim lRet        As Long
Dim sWinDir     As String
Dim sSysDir     As String

' * * * * * * *

    lSize = 255
    sBuffer = String$(lSize, Chr$(0))
   
    ' Get Windows Directory
    lRet = GetWindowsDirectory(sBuffer, lSize)
    sWinDir = Left$(sBuffer, lRet)
   
    ' Reset buffer
    sBuffer = String$(lSize, Chr$(0))
   
    ' Get System Directory
    lRet = GetSystemDirectory(sBuffer, lSize)
    sSysDir = Left$(sBuffer, lRet)
   
    ' You can now use the variables 'sWinDir' and 'sSysDir'


I believe that this should work under Win98 as well, although I haven't tested it under Win98.

Hope this helps...

0
 

Author Comment

by:JimKirby
ID: 1434211
The code in bjbenoit's answer works perfectly in Win95
environment. I've sent it out for testing by a friend who has
Win98, but I can't see why it shouldn't work the same there.

Now, I must progress to an understanding of the mysteries
of the Windows API and the syntax of the Declare statement.

Thank you, bjbenoit!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

759 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

20 Experts available now in Live!

Get 1:1 Help Now