try.. List.SelectedItem.Value instead, can't be sure, returned everything to lecturer.Originally posted by Xcert:Dim Counter As Integer
Dim Array() As String
For Counter = 0 To TotalItemsinList - 1
Array(Counter) = System.Convert.ToString(List.SelectedItem)
Next Counter
Basically I just want to put the items I have selected in the Listbox into the array.
For the above code...I get the error message "Object reference not set to an instance of an object."...Any experts here know what's the problem?
Nope...its not valid.Thanks anyway...Originally posted by Ito_^:try.. List.SelectedItem.Value instead, can't be sure, returned everything to lecturer.
Does the Listbox has a data source? Or just filled with string values?Originally posted by Xcert:Dim Counter As Integer
Dim Array() As String
For Counter = 0 To TotalItemsinList - 1
Array(Counter) = System.Convert.ToString(List.SelectedItem)
Next Counter
Basically I just want to put the items I have selected in the Listbox into the array.
For the above code...I get the error message "Object reference not set to an instance of an object."...Any experts here know what's the problem?
err...I am not too sure what U mean by data source...the listbox is filled with filenames from a OpenFileDialog.Originally posted by hjxfabio:Does the Listbox has a data source? Or just filled with string values?
tried the redim...doesnt work...I think the problem is with incompatible data types in the statement but I cannot find the error...also tried dim array as object...also cannot work.Originally posted by octega:If it is a VB6 problem, the problem is most likely, have to
reDIM the arrary to the number of items in the listbox/etc.
But not sure if thats the case for VB.NET
Originally posted by Xcert:i didn't use VB.NET, but from your code in bold, your declaring an variable called "Array" of String type. Therefore your variable "Array" is a immutable array of characters aka String datatype. so if u declare your variable Array as a string ur are impling that this string variable can only store ONE string value.
Dim Counter As Integer
Dim Array() As String
For Counter = 0 To TotalItemsinList - 1
Array(Counter) = System.Convert.ToString(List.SelectedItem)
Next Counter
Basically I just want to put the items I have selected in the Listbox into the array.
For the above code...I get the error message "Object reference not set to an instance of an object."...Any experts here know what's the problem?[/b]
Originally posted by Xcert:Are those items in bold still valid? Might have removed them or nulled them somewhere in yr program?
Dim Counter As Integer
Dim Array() As String
For Counter = 0 To TotalItemsinList - 1
Array(Counter) = System.Convert.ToString(List.SelectedItem)
Next Counter
Basically I just want to put the items I have selected in the Listbox into the array.
For the above code...I get the error message "Object reference not set to an instance of an object."...Any experts here know what's the problem?
Originally posted by Xcert:Where did it say the error was?
Dim Counter As Integer
Dim Array() As String
For Counter = 0 To TotalItemsinList - 1
Array(Counter) = System.Convert.ToString(List.SelectedItem)
Next Counter
Dim Counter As IntegerOriginally posted by Xcert:Dim Counter As Integer
Dim Array() As String
For Counter = 0 To TotalItemsinList - 1
Array(Counter) = System.Convert.ToString(List.SelectedItem)
Next Counter
Basically I just want to put the items I have selected in the Listbox into the array.
For the above code...I get the error message "Object reference not set to an instance of an object."...Any experts here know what's the problem?
Originally posted by hjxfabio:yup.It works.
Dim Counter As Integer
Dim Array([b]List.SelectedItems.Count - 1) As String
For Counter = 0 To List.SelectedItems.Count - 1
Array(Counter)=System.Convert.ToString(List.SelectedItems(Counter))
Next Counter
Try to see if this code works.[/b]
Welcome..Originally posted by Xcert:yup.It works.
Thanks.![]()
![]()