testorp

would like to generate a class with some variables and property to assign/read values

I don't understand how to then use this class as an array to store more values and how am I supposed to retrieve them

Below is the code, but I don't know how to use it properly, the counter of course works, but the information I store where is it going, what index am I suppsed to use to retrieve it.

Thanks for the answers

Public Class Cseq_log

Private v_date As DateTime

Private v_description As String

Public Property p_date() As DateTime

Get

Return v_date

End Get

Set(ByVal value As DateTime)

v_date = value

End Set

End Property

Public Property p_description() As String

Get

Return v_description

End Get

Set(ByVal value As String)

v_description = value

End Set

End Property

End Class

Public Class Form1

Dim seq_log As New Cseq_log

Dim count As Integer = 0

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

count += 1

Label1.Text = CStr(count)

seq_log.p_date = Date.Today

seq_log.p_description = CStr(Date.Now)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

MsgBox(CStr(seq_log.p_date))

End Sub

End Class



Re: Visual Basic Express Edition ??? class assign/retrive data - can someone explain to me please

nobugz

Try something like this:

Public Class Form1
Dim mLog() As Cseq_log
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ReDim mLog(100)
For ix As Integer = 0 To 99
mLog(ix).p_date = Now
Next
End Sub
End Class

Public Class Cseq_log
Private v_date As DateTime
Private v_description As String
Public Property p_date() As DateTime
Get
Return v_date
End Get
Set(ByVal value As DateTime)
v_date = value
End Set
End Property
End Class

The parentheses in the mLog declaration makes it an array. The ReDim statement creates the array, 100 elements in this sample.





Re: Visual Basic Express Edition ??? class assign/retrive data - can someone explain to me please

testorp

mmmm what if I don't know the size of my array, because I'm loading a log_file which is in txt format

also how can I filter da date range and do sorting

Is it best to sort my output on screen or previously in the array.

I was considering outputing data to screen in a listview format

THX





Re: Visual Basic Express Edition ??? class assign/retrive data - can someone explain to me please

nobugz

Use a List, it can dynamically expand itself. For example:

Public Class Form1
Dim mLog As New List(Of Cseq_log)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For ix As Integer = 0 To 99
Dim item As New Cseq_log
item.p_date = Now
mLog.Add(item)
Next
mLog.Sort(AddressOf CompareLogsByDate)
End Sub

Private Shared Function CompareLogsByDate(ByVal log1 As Cseq_log, ByVal log2 As Cseq_log) As Integer
Return log1.p_date.CompareTo(log2.p_date)
End Function

End Class







Re: Visual Basic Express Edition ??? class assign/retrive data - can someone explain to me please

testorp

Would this also be possible

Public Class Form1
Dim mLog As New List(Of Cseq_log) 'this creates a list that I can add to (of Cseq_log) correct
Dim item As New Cseq_log 'changed postion to Class Form what would it do in general

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For ix As Integer = 0 To 99 'the For ... next routine is to populate the variable correct
item.p_date = Now 'here you're setting the p_date property for the item class Cseq_log
mLog.Add(item) ' het the above mentioned property is loaded to the list, how can I identify the quote "line number where it's added"
Next
mLog.Sort(AddressOf CompareLogsByDate) 'this I don't get what does AddressOf do to CompareLogsByDate I can guess you are giving me a hint towards sorting and filtering :-)
End Sub

Private Shared Function CompareLogsByDate(ByVal log1 As Cseq_log, ByVal log2 As Cseq_log) As Integer
Return log1.p_date.CompareTo(log2.p_date)
End Function

End Class

thanks for all you guys helping out are just great

PAOLO






Re: Visual Basic Express Edition ??? class assign/retrive data - can someone explain to me please

nobugz

No, that's incorrect. You would create a list whose elements all reference the same item.

The AddressOf operator creates a delegate as required by the List.Sort() method. The Sort() method calls that delegate to decide how the elements need to be sorted.





Re: Visual Basic Express Edition ??? class assign/retrive data - can someone explain to me please

testorp

sorry dosen't help much, I more than NB to it.

can you point me to some resoucres on the net where I could get some culture, please. MSDN ! !