Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Filtering with figures

Posted on 2004-10-11
8
Medium Priority
?
171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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:
Corey Scheich earned 2000 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:Corey Scheich
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:Corey Scheich
ID: 12286792
My pleasure.
Thank you for your kind words.

Corey
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

618 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