DirectoryInfo()

  • Thread starter Thread starter Brad Granath
  • Start date Start date
B

Brad Granath

I'm trying to get a ListBox to display a directory list when the user chooses
a drive letter from a ComboBox. This is my code:

Private Sub Combo7_Change()
Dim di As DirectoryInfo
di = New DirectoryInfo("Combo7.Value")
List0.RowSource = di.GetDirectories()
End Sub

However, the compiler takes offense at the "di = New
DirectoryInfo("Combo7.Value")" line, caiming that it "expected end of
statement." I've included mscorlib in the references. It's been a long time
since I fooled around with constructors and the like, and never in VB, so I
have no clue if I'm breaking some simple syntax rule.

Any ideas?
 
In VB, you have to use Set to assign an object reference, so...

Set di = New DirectoryInfo("Combo7.Value")

....should work, assuming there are no other problems.


Rob
 
Nope, doesn't work. Same error.

I'm working with Visual Basic for Applications, within Access 2003. I think
it has certain limitations over regular VB.NET, like not being able to
utilize the comdlg32 ActiveX control, and other, random, quirky things like
that.

After further investigation and experimenting, the error I'm getting is
caused specifically by the"()".

Replacing:

Set di = New DirectoryInfo(Combo7.Value)

With:

Set di = New DirectoryInfo

....makes the error go away. But I then the code doesn't work (and well it
shouldn't). So, I think this is being caused by the way that my installation
of VB is handling the DirectoryInfo class. Trouble is, I have no clue what
I'm doing wrong, and can't find any examples of people having similar
problems. Is there another way to manipulate the DirectoryInfo class once
it's been initialized? Like, di.Path = Combo7.Value?

Thanks
 
D'oh! I was sleeping at the wheel. You're right, it HAS to be just "New
DirectoryInfo" without the parameter (another of those limitations you
mentioned, compared to .NET).

What exactly is the DirectoryInfo object and where are you getting it from?
It's not native to VBA/Access. I know there's something like that in
VB.NET, but I don't know what it does...I have only a very limited
experience with .NET.

Oh and despite what Microsoft tries to tell you, you're best off thinking of
VBA and VB.NET as two completely different languages that just happen to
share a lot of similarities. VB6 and VBA are virtually the same language,
give or take a few objects and functions; VB.NET is substantially different
in a number of ways.


Rob
 
I got it from the .NET MSDN. I recognize that VBA and VB.NET are different
entities. Is it possible to use VBA to get what I want? I couldn't find info
on it anywhere.
 
Well, I suppose maybe I'm using the wrong object, but I'd like to populate a
ComboBox with a list of directories in a given path. I *thought* that the
way this was done was:

Set di = New DirectoryInfo([GivenDrive:/GivenPath/])
ComboBox.RowSource = di.GetDirectories()

But that obviously doesn't work, so, is there another way to do it that
works in VBA?
 
You have to loop through all of the entries returned by GetDirectories, and
use the .AddItem method of the combo box to add them one at a time.
 
But there's no DirectoryInfo() object in Access in the first place. I
believe he'd have to use Dir() with the vbDirectory attribute specified.


Rob
 
Back
Top