Select to view content in your preferred language

Syntax for using InputBox input in a whereclause?

460
1
08-13-2011 11:01 AM
AshleyHayes
Emerging Contributor
I have some code where I want to use an InputBox to allow the user to specify the value used in a whereclause, but after 4 hours of searching I cannot figure out the proper syntax.  Obviously I am a beginner.  Any assistance would be greatly appreciated!

My Inputbox code would be similar to the following:

Dim strArea As String
strArea = InputBox("Area greater than", "Area", "5000")

Dim strDistance As String
strDistance = InputBox("Distance greater than", "Distance", "50")

And this would be my whereclause:

Dim pQueryFilter As IQueryFilter
        pQueryFilter = New QueryFilter
        pQueryFilter.WhereClause = "AREA> AND DISTANCE>" 

How do I add the strArea and strDistance to this whereclause? 

Do I need to convert them first to type "double", using something like:  

Dim dubArea As Double
dubArea = Convert.ToDouble(strArea)

Dim dubDistance As Double
dubDistance = Convert.ToDouble(strDistance)

If so, how would I then add the dubArea and dubDistance to my whereclause? 

What if I also wanted to have the user specify the >,<, =, etc. using separate Inputbox's?  How would I also add that to the whereclause. 

Thanks again!
0 Kudos
1 Reply
GregRieck
Frequent Contributor
Steve,

Yes, you would have to convert them to double prior to using them in the where clause. I can't image a data source that has Area or Distance as a string value. Then the where clause would have to include the values and the field names.

Something like this I think in VB:
pQueryFilter.WhereClause = "AREA > " & dubArea & " AND DISTANCE > " & dubDistance
or this in C#:
pQueryFilter.WhereClause = "AREA > " + dubArea + " AND DISTANCE > " + dubDistance;
As for dealing with the user input of the >,<, =, etc. it seems that you could introduce those as separate input boxes.  You could insert them much the same way as you do the variables for area and distance. However, personally when you have to use that many input boxes to accomplish a goal it's time to consider using a GUI.

G
0 Kudos