We help IT Professionals succeed at work.

Command 'Dir' / VisualStudioC++ 6

kayrak
kayrak asked
on
389 Views
Last Modified: 2008-02-20
Hi experts,

I'm programming a VB-macro for the MS developer studio VC++6.
An error occurs by using the 'Dir'-command like shown below ( but I used it successfully in Excel). The error: "Typen unverträglich: 'Dir' " - means the parameter-type "path" has the wrong type for use with 'Dir' (but in my eyes it has the right type for use with Dir, its string).

path = "C:\product\fk\*.h"   ' set path
name = Dir(path, vbDirectory) ' get first ".h"-name

Who can help me quickly?
Thank You
Volkan    
Comment
Watch Question

Commented:
I suspect the variable 'name'. Does this work?

path = "C:\product\fk\*.h"   ' set path
MsgBox Dir(path, vbDirectory) ' show first ".h"-name

Ture Magnusson
Karlstad, Sweden

Commented:
Volkan,

I suspect the variable 'name'. Does this work?

path = "C:\product\fk\*.h"   ' set path
MsgBox Dir(path, vbDirectory) ' show first ".h"-name

Ture Magnusson
Karlstad, Sweden

Author

Commented:
I tried this, too:

path = "C:\product\fk\*.h"   ' set path
Dir path                             ' show first ".h"-name

it did not work.
your suggestion with MsgBox did'n work, too.
Sorry
Volkan

Author

Commented:
Sorry Ture,

the same error occurs. Even

path = "C:\product\fk\*.h"
Dir path

is not accepted by the interpreter.
Something must be wrong with path.
Volkan

Commented:
Volkan,

This works all right on my machine. VB6. But I wouldn't use Name as a variable, because it is used for other purposes.

Private Sub Command1_Click()
  Dim path As String
  Dim name As String
  path = "C:\product\fk\*.h"
  name = Dir(path, vbDirectory)
  MsgBox name
End Sub

/Ture

Author

Commented:
Hi Ture,

this works all right on my machine for example in Excel, too - I tried this before. But I need this to be running in Microsofts DeveloperStudio for C++ Version 6.
Believe me, this macro does not work in this studio. Thats why I'm asking this answer worth 55 points.


Volkan

Commented:
Volkan,

Sorry - I missed the 'C++' text in your question. Perhaps you should post this qustion in the C++ topic area instead?

https://www.experts-exchange.com/Computers/Programming/Languages/C++/

/Ture

Author

Commented:
Hi Ture,

this works all right on my machine for example in Excel, too - I tried this before. But I need this to be running in Microsofts DeveloperStudio for C++ Version 6.
Believe me, this macro does not work in this studio. Thats why I'm asking this answer worth 55 points.


Volkan
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
The 'C++'-text was hidden in my question as follows: VC++6 (V = Visual).

Thank You for Your suggestions.
I'll try my luck in the C++-Corner.

Volkan

Commented:
VBGuru,

Please don't mix up VBScript with VBA.

Visual Basic Scripting Edition is not nearly as complete as the Visual Basic for Applications language that is provided with the MS Office applications.

The Dir function IS available in VBA and has been so since it's first release in Excel 5.

/Ture

Author

Commented:
The 'C++'-text was hidden in my question as follows: VC++6 (V = Visual).

Thank You for Your suggestions.
I'll try my luck in the C++-Corner.

Volkan

Author

Commented:
VBGuru,

looks interesting. Can you tell me something about the parameter of GetFolder(folderspec)?

How must I declare/initialise folderspec?

HRESULT GetFolder(
  LPMAPIFOLDER FAR * ppFolder  
);
 
Volkan

Commented:
To Ture,
Here is the content from the C++ help file
Overview: VBScript Macros
Home Page (Macros) | How Do I Topics | FAQ | Reference

With VBScript macros or Developer Studio add-ins, you can automate routine Developer Studio tasks. For example, you can update a project by automatically opening the project, changing some project files, saving the changes, and then rebuilding the project.

You automate tasks by using Automation (formerly OLE Automation). With Automation, Developer Studio and its components become objects you can control programmatically. For example, windows become objects you can activate and size programmatically. Similarly, documents become objects you can open, edit, and close programmatically.

A VBScript macro is a procedure that contains VBScript commands and takes no parameters. A VBScript macro begins with a Sub statement, continues with VBScript commands that represent tasks you want to accomplish, and ends with an End Sub statement.

To kayrak,
It is not an API, its a method of filesystemobject. This function I got it from the VC++ 6.0 help file. To compile this macro successfully you should have installed the internet SDK.
GetFolder Method  Language Reference
Version 3
 

See Also                  Applies To


--------------------------------------------------------------------------------

Description
Returns a Folder object corresponding to the folder in a specified path.
Syntax
object.GetFolder(folderspec)
The GetFolder method syntax has these parts:

Part Description
object Required. Always the name of a FileSystemObject.
folderspec Required. The folderspec is the path (absolute or relative) to a specific folder.


Remarks
An error occurs if the specified folder does not exist.
The following example illustrates the use of the GetFolder method to return a folder object:

Sub AddNewFolder(path, folderName)
  Dim fso, f, fc, nf
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.GetFolder(path)
  Set fc = f.SubFolders
  If folderName <> "" Then
    Set nf = fc.Add(folderName)
  Else
    Set nf = fc.Add("New Folder")
  End If
End Sub


Author

Commented:
Hi VBGuru,

thats it!
Thanks

Volkan

Commented:
welcome
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.