|
-
Sep 4th, 2003, 05:52 AM
#1
Thread Starter
New Member
Add Item To ArrayList
Hi, I Have some problem to add ListBox Item to ArrayList.
can anyone help me what I do wrong?
Code:
Dim myStreamReader As StreamReader = File.OpenText(LastFile) 'Last Opened File
Dim intListBoxTabs() As Integer = {80, 180}
Dim intRes As Integer
Dim myInputString As String
Dim t As Task
Dim Prio As Integer
Dim Due As Date
Dim ToDo As String
List.Items.Clear()
intRes = SendMessage(List.Handle, _
LB_SETTABSTOPS, _
intListBoxTabs.Length, _
intListBoxTabs(0))
While myStreamReader.Peek() > -1
myInputString = myStreamReader.ReadLine()
If Not myInputString Is Nothing Then
t = New Task(Prio, Due, ToDo)
tasks.Add(t)
End If
End While
Dim i As Integer
Dim s As String = ""
If tasks.Count > 0 Then
For i = 0 To tasks.Count - 1
't = Split(myInputString, ",")
List.Items.Add(Prio & vbTab & Due & vbTab & ToDo)
Next
End If
tasks.Sort()
myStreamReader.Close()
End Sub
End Class
Thanks
-
Sep 4th, 2003, 08:08 AM
#2
I'm guessing that tasks is your ArrayList and that the red line is where you're having trouble?
Are you getting an error message? If so, what is it?
Can you let us see the definition of your Task class?
This world is not my home. I'm just passing through.
-
Sep 4th, 2003, 10:31 AM
#3
Thread Starter
New Member
Hi trisuglow, you're right.
I'm having trouble there ( or somewhere else)
Here is the class...
Code:
Public Class Task
Implements IComparable
Private mPrio As Integer
Private mDue As DateTime
Private mToDo As String
Public Sub New(ByVal Prio As Integer, _
ByVal Due As DateTime, _
ByVal ToDo As String)
mPrio = Prio
mDue = Due
mToDo = ToDo
End Sub
Public Function Prio() As Integer
Return mPrio
End Function
Public Function Due() As DateTime
Return mDue
End Function
Public Overloads Function CompareTo(ByVal t1 As Object) As Integer Implements IComparable.CompareTo
If t1.Prio() > mPrio Then
Return 1
ElseIf t1.Prio < mPrio Then
Return -1
Else
'the two tasks have equal priority
Return DateTime.Compare(mDue, t1.due())
End If
End Function
Public Overrides Function ToString() As String
Return mPrio.ToString & "_" & mDue.ToShortDateString() & "_" & mToDo
End Function
End Class
Thanks
-
Sep 5th, 2003, 03:00 AM
#4
Just a thought...
You are declaring t as a New ArrayList aren't you?
Tris.
This world is not my home. I'm just passing through.
-
Sep 5th, 2003, 11:43 PM
#5
Thread Starter
New Member
-
Sep 7th, 2003, 12:20 AM
#6
I wonder how many charact
Originally posted by trisuglow
You are declaring t as a New ArrayList aren't you?
And that's the problem Marcels... you are making a new Arraylist everytime you want to add something instead of adding it to the same one.
-
Sep 7th, 2003, 12:52 PM
#7
Thread Starter
New Member
Do you have another idea, if I want to add everything into the same one?
-
Sep 7th, 2003, 12:57 PM
#8
Frenzied Member
Remove t = New Task(Prio, Due, ToDo) from the if block.
-
Sep 7th, 2003, 01:11 PM
#9
I wonder how many charact
Originally posted by marcels
Do you have another idea, if I want to add everything into the same one?
1) You haven't included the code where you declare tasks. I see a line tasks.add(t), but I don't see the decleration. Where is it?
2) Also, you haven't said what the error is, or what you are trying to do... you should give more information, otherwise this will turn into a 20 post thread and people will view it and think ***.
3) You only need to declare one instance of your Task class. But you do need a method to ADD things. I don't see one in your class. All I see is a NEW function, which does little to help you list tasks all in one place, much less compare them.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|