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
Solved

Windows folder--win95 vs. Win98???

Posted on 1998-09-10
3
149 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
MS Access - Capture pressed key onclick 4 41
Excel Automation VBA 19 88
Send outlook email from VBS Script 2 42
checkbox to hide entire section 10 40
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

839 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