Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > System.IO Directory


Reply
 
Thread Tools Display Modes
  #1  
Old 01-23-2004, 06:48 AM
byon byon is offline
Newcomer
 
Join Date: Aug 2003
Location: Singapore
Posts: 21
Default System.IO Directory


Hi

I'm new to vb.net and i just read up on system.io namespace, directory. my mind just generated an idea on creating a application that 'Create', 'Delete', 'Refresh' Directories. but currently my listbox1 is giving me errors...
Argument not specified for parameter 'item' of 'public function....

i inserted the following code into a button/form both generated the same error message.

Code:
Dim str() As String, intx As Integer str = Directory.GetLogicalDrives For intx = 1 To UBound(str) ListBox1.Items.Add = str(intx) Next

thanks in advance.
Reply With Quote
  #2  
Old 01-23-2004, 07:48 AM
AFterlife's Avatar
AFterlife AFterlife is offline
Contributor
 
Join Date: Dec 2003
Location: Mi
Posts: 654
Default

TRY THIS:
Code:
Dim str As String(), intx As Integer, i As Integer str = Directory.GetLogicalDrives intx = Directory.GetLogicalDrives.Length - 1 For i = 0 To intx ListBox1.Items.Add(str(i)) Next

Last edited by Wamphyri; 01-23-2004 at 08:24 AM. Reason: erased quote of previous post
Reply With Quote
  #3  
Old 01-23-2004, 11:22 AM
Csharp's Avatar
Csharp Csharp is offline
Senior Contributor

* Expert *
 
Join Date: Jul 2003
Location: Ashby, Leicestershire.
Posts: 967
Default

you dont need to loop through the drive letters though in one easy line ...
Code:
ListBox1.Items.AddRange(IO.Directory.GetLogicalDrives) '/// add the array of drive letters in one go.
__________________
~~ please don't PM me regarding code, I only reply to personnal messages ~~
Reply With Quote
  #4  
Old 01-23-2004, 12:38 PM
byon byon is offline
Newcomer
 
Join Date: Aug 2003
Location: Singapore
Posts: 21
Default

Thanks!
can i know why it doesn't work?

i had a friend who prefers using UBound(Arry) over Arry.Length - 1

but why?
Reply With Quote
  #5  
Old 01-23-2004, 12:42 PM
byon byon is offline
Newcomer
 
Join Date: Aug 2003
Location: Singapore
Posts: 21
Default

THis one is really nifty...
woo!
thanks!
Reply With Quote
  #6  
Old 01-23-2004, 01:42 PM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

Since you are using .NET, use the array's .GetUpperBound() method to get the UBound instead.
And i.ToString() instead of the str() function, which is outdated even in Legacy VB.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #7  
Old 01-23-2004, 08:25 PM
AFterlife's Avatar
AFterlife AFterlife is offline
Contributor
 
Join Date: Dec 2003
Location: Mi
Posts: 654
Default

Cool. Ill remember that addrange one.
Reply With Quote
  #8  
Old 01-24-2004, 03:51 AM
byon byon is offline
Newcomer
 
Join Date: Aug 2003
Location: Singapore
Posts: 21
Default

Quote:
Originally Posted by Iceplug
Since you are using .NET, use the array's .GetUpperBound() method to get the UBound instead.
And i.ToString() instead of the str() function, which is outdated even in Legacy VB.



a reply to the above...
How do i use Str() Function in the following code?

Code:
Dim str As String(), intx As Integer, i As Integer str = Directory.GetLogicalDrives intx = Directory.GetLogicalDrives.Length - 1 For i = 0 To intx ListBox1.Items.Add(str(i)) Next

i tried changing to
Code:
ListBox1.Items.Add(i.ToString(str))

but it does not work
Reply With Quote
  #9  
Old 01-24-2004, 05:01 AM
Csharp's Avatar
Csharp Csharp is offline
Senior Contributor

* Expert *
 
Join Date: Jul 2003
Location: Ashby, Leicestershire.
Posts: 967
Default

firstly you shouldnt declare a string with the name Str , as Str is a function.
if you wish to add each item through a loop, do either of these ...
Code:
Dim drives As String() = IO.Directory.GetLogicalDrives Dim x As Integer For x = drives.GetLowerBound(0) To drives.GetUpperBound(0) ListBox1.Items.Add(drives(x)) Next
or ..
Code:
Dim drives As String() = IO.Directory.GetLogicalDrives Dim drive As String For Each drive In drives ListBox1.Items.Add(drive) Next
__________________
~~ please don't PM me regarding code, I only reply to personnal messages ~~
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell command from a directory... Kasdoffe General 3 01-21-2004 11:46 AM
FTP not setting current directory kkonkle API 2 09-29-2003 10:30 AM
CommonDialog starting in Specified Directory? And more.. CynicalSaint General 4 05-11-2003 06:09 PM
Searching for a directory vs searching a text file for the same thing! AznCutie General 1 11-23-2002 03:51 PM
directory list problem polarbear199 General 3 09-24-2002 01:53 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->