Solved

Filtering with figures

Posted on 2004-10-11
8
164 Views
Last Modified: 2011-09-20
Hi,

Here's my problem:

My App Users have to enter a minimum age and a maximum age in 2 TextBoxes (respectively : txtAge1 and txtAge2)

Dim Age1 As String = txtAge1.Text
 
Dim Age2 As String = txtAge2.Text

I have a data field in my DataTable that is named "Age".  Therefore "Age" >= Age1 And  "Age" <= Age2 which reads (My code) :

If txtAge1.Text.Trim <> "" And txtAge2.Text.Trim <> "" Then
strFilter += "Age >= '" & txtAge1.Text & "' AND "
strFilter += "Age <= '" & txtAge2.Text & "'    '"
End If

The filter works fine except for certain values e.g. min 5 and max 25. It seems that this is due to the fact that these are STRING comparisons, which means 5 in higher than 25 because 5 > 2.

Does anyboduy know how to resolve this issue?

Thanks
0
Comment
Question by:Ghanisen
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 34

Expert Comment

by:flavo
ID: 12282915
Dim Age1 As integer = cType(txtAge1.Text, integer)

Dave
0
 
LVL 34

Expert Comment

by:flavo
ID: 12282919
Its gonig to throw a casting error if the user entered for exmple a though...  you'll need to handle that.

Maybe on the leave entent on the textbox have something like


If not IsNumberic(Me.txtAge1.text) then
  msgbox "Enter a number mate!"
   me.txtAge1.text = 0
end if

Idea??

Dave
0
 
LVL 7

Expert Comment

by:J_Mak
ID: 12283693
Try converting the String into an integer first before doing the comparisons, like:

Dim int_Age1 as Integer
Dim int_Age2 as Integer

int_Age1 = CInt(Val(txtAge1.Text))
int_Age2 = CInt(Val(txtAge2.Text))

Hope that helps!
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:Ghanisen
ID: 12284926
Hi flavo, and J Mak,

Thanks for the suggestions. I had already tried that (converting to integer) but it did not work for one simple reason:

RowFilter is a string and at the end of the day the values converted to integer have to be converted back to string values ans are processed as such in the filtering.

This is a tough issue and I'll try this morning to use an SQL query to filter directely from the database.

Keep on searching please and thanks for your efforts.


0
 
LVL 13

Accepted Solution

by:
Corey2 earned 500 total points
ID: 12286418
Since it is a string filter then you have to have the same number of characters to have a proper numeric comparison.

to handle this try this

Dim Age1len as long
Dim Age2len as long

age1len = len(txtage1.text)

age2len = len(txtage2.text)

while age1len < age2len
     txtage1.text = "0" txtage1.text
     age1len = len(txtage1.text)
wend

'then your comparison

regards,
Corey
0
 
LVL 13

Expert Comment

by:Corey2
ID: 12286433
seems i missed an "&" in this line.

txtage1.text = "0" & txtage1.text
0
 

Author Comment

by:Ghanisen
ID: 12286750
Hi Corey,

You gave me a fantastic solution far better than the one I have found:

If txtAge1.Text <> "" Then
            If txtAge1.Text.Length <> 2 Then
                MsgBox("The minimum and maximum age must both be included between 10 et 99 years!")
                txtAge1.Focus()
            Else
                Exit Sub
            End If
End If

Since my users are adults, my solution works but your's is so elegant that I'm in deep admiration.

Corry you really deserved your 500 points. Many thanks
0
 
LVL 13

Expert Comment

by:Corey2
ID: 12286792
My pleasure.
Thank you for your kind words.

Corey
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Close form "before" open 3 40
VB.Net Report Printing Issue 3 33
Calculate number of nights between two dates 5 24
vb.net and creating a class 5 17
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question