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.
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. :p
AFterlife
01-23-2004, 07:48 AM
TRY THIS:
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
Csharp
01-23-2004, 11:22 AM
you dont need to loop through the drive letters though :) in one easy line ...
ListBox1.Items.AddRange(IO.Directory.GetLogicalDrives)
'/// add the array of drive letters in one go.
Thanks!
can i know why it doesn't work?
i had a friend who prefers using UBound(Arry) over Arry.Length - 1
but why?
THis one is really nifty...
woo!
thanks!
Iceplug
01-23-2004, 01:42 PM
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.
AFterlife
01-23-2004, 08:25 PM
Cool. Ill remember that addrange one.
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?
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
ListBox1.Items.Add(i.ToString(str))
but it does not work
Csharp
01-24-2004, 05:01 AM
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 ...
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 ..
Dim drives As String() = IO.Directory.GetLogicalDrives
Dim drive As String
For Each drive In drives
ListBox1.Items.Add(drive)
Next