Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

Command 'Dir' / VisualStudioC++ 6

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    
0
kayrak
Asked:
kayrak
  • 8
  • 5
  • 3
1 Solution
 
tureCommented:
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
0
 
tureCommented:
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
0
 
kayrakAuthor 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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kayrakAuthor 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
0
 
tureCommented:
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
0
 
kayrakAuthor 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
0
 
tureCommented:
Volkan,

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

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

/Ture
0
 
kayrakAuthor 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
0
 
VBGuruCommented:
VBA doesn't support the "Dir" function  provided by VB. Instead you have to use th FileSyatemObject as follows.

Collection of all Folder objects contained within a Folder object.
Remarks
The following code illustrates how to get a Folders collection and how to iterate the collection using the For Each...Next statement:
Function ShowFolderList(folderspec)
  Dim fso, f, f1, fc, s
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.GetFolder(folderspec)
  Set fc = f.SubFolders
  For Each f1 in fc
    s = s & f1.name
    s = s &  "<BR>"
  Next
  ShowFolderList = s
End Function




Following are the functions supported by the VBA
Microsoft® Visual Basic® Scripting Edition
Functions
 | Language Reference |
 

--------------------------------------------------------------------------------
Abs Function
Array Function
Asc Function
Atn Function
CBool Function
CByte Function
CCur Function
CDate Function
CDbl Function
Chr Function
CInt Function
CLng Function
Cos Function
CreateObject Function
CSng Function
CStr Function
Date Function
DateAddFunction
DateDiff Function
DatePart Function
DateSerial Function
DateValue Function
Day Function
Exp Function
Filter Function
Fix Function
FormatCurrency Function
FormatDateTime Function
FormatNumber Function
FormatPercent Function
GetObject Function
Hex Function
Hour Function
InputBox Function
InStr Function
InStrRev Function
Int Function
IsArray Function
IsDate Function
IsEmpty Function
IsNull Function
IsNumeric Function
IsObject Function
Join Function
LBound Function
LCase Function
Left Function
Len Function
LoadPicture Function
Log Function
LTrim Function
Mid Function
Minute Function
Month Function
MonthName Function
MsgBox Function
Now Function
Oct Function
Replace Function
Right Function
Rnd Function
Round Function
RTrim Function
ScriptEngine Function
ScriptEngineBuildVersion Function
ScriptEngineMajorVersion Function
ScriptEngineMinorVersion Function
Second Function
Sgn Function
Sin Function
Space Function
Split Function
Sqr Function
StrComp Function
StrReverse Function
String Function
Tan Function
Time Function
TimeSerial Function
TimeValue Function
Trim Function
TypeName Function
UBound Function
UCase Function
VarType Function
Weekday Function
WeekdayName Function
Year Function

--------------------------------------------------------------------------------
© 1996 by Microsoft Corporation.
0
 
kayrakAuthor 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
0
 
tureCommented:
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
0
 
kayrakAuthor 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
0
 
kayrakAuthor 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
0
 
VBGuruCommented:
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


0
 
kayrakAuthor Commented:
Hi VBGuru,

thats it!
Thanks

Volkan
0
 
VBGuruCommented:
welcome
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.

  • 8
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now