Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows folder--win95 vs. Win98???

Posted on 1998-09-10
3
Medium Priority
?
153 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
[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
3 Comments
 

Accepted Solution

by:
bjbenoit earned 400 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

730 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