Solved

Command 'Dir' / VisualStudioC++ 6

Posted on 2000-03-17
16
283 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    
0
Comment
Question by:kayrak
  • 8
  • 5
  • 3
16 Comments
 
LVL 22

Expert Comment

by:ture
ID: 2627914
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
 
LVL 22

Expert Comment

by:ture
ID: 2627915
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
 

Author Comment

by:kayrak
ID: 2627930
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
 

Author Comment

by:kayrak
ID: 2627936
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
 
LVL 22

Expert Comment

by:ture
ID: 2627963
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
 

Author Comment

by:kayrak
ID: 2628059
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
 
LVL 22

Expert Comment

by:ture
ID: 2628085
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
 

Author Comment

by:kayrak
ID: 2628098
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 6

Accepted Solution

by:
VBGuru earned 55 total points
ID: 2628136
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
 

Author Comment

by:kayrak
ID: 2628154
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
 
LVL 22

Expert Comment

by:ture
ID: 2628218
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
 

Author Comment

by:kayrak
ID: 2628233
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
 

Author Comment

by:kayrak
ID: 2628275
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
 
LVL 6

Expert Comment

by:VBGuru
ID: 2631016
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
 

Author Comment

by:kayrak
ID: 2635481
Hi VBGuru,

thats it!
Thanks

Volkan
0
 
LVL 6

Expert Comment

by:VBGuru
ID: 2635603
welcome
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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

708 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

15 Experts available now in Live!

Get 1:1 Help Now