 |
 |

01-23-2004, 06:48 AM
|
|
Newcomer
|
|
Join Date: Aug 2003
Location: Singapore
Posts: 21
|
|
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. 
|
|

01-23-2004, 07:48 AM
|
 |
Contributor
|
|
Join Date: Dec 2003
Location: Mi
Posts: 654
|
|
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
|

01-23-2004, 11:22 AM
|
 |
Senior Contributor
* Expert *
|
|
Join Date: Jul 2003
Location: Ashby, Leicestershire.
Posts: 967
|
|
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 ~~
|

01-23-2004, 12:38 PM
|
|
Newcomer
|
|
Join Date: Aug 2003
Location: Singapore
Posts: 21
|
|
|
Thanks!
can i know why it doesn't work?
i had a friend who prefers using UBound(Arry) over Arry.Length - 1
but why?
|
|

01-23-2004, 12:42 PM
|
|
Newcomer
|
|
Join Date: Aug 2003
Location: Singapore
Posts: 21
|
|
|
THis one is really nifty...
woo!
thanks!
|
|

01-23-2004, 01:42 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
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.
|
|

01-23-2004, 08:25 PM
|
 |
Contributor
|
|
Join Date: Dec 2003
Location: Mi
Posts: 654
|
|
|
Cool. Ill remember that addrange one.
|
|

01-24-2004, 03:51 AM
|
|
Newcomer
|
|
Join Date: Aug 2003
Location: Singapore
Posts: 21
|
|
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
|
|

01-24-2004, 05:01 AM
|
 |
Senior Contributor
* Expert *
|
|
Join Date: Jul 2003
Location: Ashby, Leicestershire.
Posts: 967
|
|
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 ~~
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|