I have a simple application, a form with two datepicker( Datepicker1 is for startsearchdate, while datepicker2 is endsearchdate) to filter out any record that not in the range. The source of the record is readed from a rtf file.The record is in format as showm below.
[dd/MM/yyyy] time result
So far i can make it run by using Startindex = RichTextBox1.find, then get the startdate charindex by using RichTextBox1.GetLineFromCharIndex(Startindex), use similiar method to get the endindex as well. Then use

RichTextBox1.Select(first, lastchar)
        RichTextBox1.Text = RichTextBox1.SelectedText

so text lefted behind is what I wanted. then i use readline to read every line, then use filter out the result

subStrings = Filter(arraylist2, "GOOD", True, CompareMethod.Text)

So far it works alrite, the only prolem is SPEED. With a rtf file with 60k result or lines (one result per line), It take nearly one minute to finish the task.....it is unacceptable:(

So, Is there any faster command, or ways to do this? I need this done in few second, maybe around 10s? I do search over the net before I post, but sadly that not much article regarding this(or i search the wrong keyword?)

PS: would it be faster if I put the source in textpad? or Acess database?

Any hint is welcome cos im really new in VB, not much experiece in it:)

Recommended Answers

All 9 Replies

You need to use a DB to increase speeds, Access will do if the program will be used by maximum of 5 people.

You need to use a DB to increase speeds, Access will do if the program will be used by maximum of 5 people.

Initially, i try to avoid using ADO bcos i wish the data source(notepad,rtf) can be open directly by client who didnt have MS Access. Now guess i need to filter using DB, then generate rtf file after that.( Aready try the speed, wonder y DB can filter in such speed?)

BTW, what you mean by "if the program will used by MAX of 5 people"?

Anyway, thank for replying my post:)

Access is not suitable for use of more then 5 people.

If you want a good free DB check out MySql and PostgreSql

One more question, is it the same in term of functionality and performance of MDB file created by MS acess compare to MDB file created by VB using ADOX.

I am not a 100% sure, but I don't see the feasibility of Microsoft maker another standard just for VS. It is a minimalist version on the full fledged MS Access.

Pls look at the following code.....The filter just seem work rite...

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

        Dim strExpr As String
        Dim myTable As DataTable
        Dim MyDate As Date = DateTimePicker1.Value
        myTable = ds.Tables("Contacts")
        ' Setup Filter and Sort Criteria
        strExpr = "ProcessDate > '" & Format(DateTimePicker1.Value, "dd/MM/yyyy") & "' AND ProcessDate < '" & Format(DateTimePicker2.Value, "dd/MM/yyyy") & "'"
        SetFilter(strExpr)
    End Sub

Private Sub SetFilter(ByVal strFilterExpression As String)
        Try
            ' Apply Filter Expression
            ds.Tables(0).DefaultView.RowFilter = strFilterExpression
            ' Gets the number of records in the DataView after
            ' RowFilter and RowStateFilter have been applied.
            If ds.Tables(0).DefaultView.Count > 0 Then
                DataGridView1.DataSource = ds.Tables(0).DefaultView
            Else
                MessageBox.Show("Filter criteria does not meet criteria")
            End If
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
            Console.WriteLine()
        End Try
    End Sub

I try to replace 'dd/MM/yyyy' to #dd/MM/yyy# but error massage when compile/Build. Seem it only support string type

What i need is juat to filter a range of date. Now VB only can regconize date and month but not year.

E.g when i search for < 1/7/2010....it 6/6/2010,6/6/2011,6/6/2012......

The Db is create using ADOX from VB since my MS access aready expire.....

You want to work with yyyyMMdd not dd/MM/yyy

you can also do

"ProcessDate BETWEEN '" & DateTimePicker1.Value.ToString("yyyyMMdd") & "' AND  '" & DateTimePicker2.Value.ToString("yyyyMMdd") & "'"

Shame on me:( I found the culprit:(
I acidentally deifne the "ProcessDate" to DataTypeEnum.adVarWChar, instead of

With .Columns
                .Append("ProcessDate", DataTypeEnum.adDate)
            End With

when creating the DB wit ADOX.Now work fine wit

strExpr = "ProcessDate >= #" & Format(DateTimePicker1.Value, "MM/dd/yyyy") & "# AND ProcessDate <= #" & Format(DateTimePicker2.Value, "MM/dd/yyyy") & "#"

Still.....need to think off a way to work on dd/MM/yyyy. bcoz i wish to store dd/MM/yyyy format in DB.......headache.....:)

thank for ur advice too:)

you can format it to look like you want in the DB.

I don't know the exact method but I know you can.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.