Public Class frmPrecinctSearch Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MsgBox(txtPrecinctSearch.Text) 'for debugging, shows the textbox value is being captured successfully End Sub End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim pMap As IMapDocument Dim activeView As IActiveView Dim featureLayer As IFeatureLayer Dim whereClause As String pMap = New MapDocument activeView = pMap featureLayer = pMap.Layer(0, 0) whereClause = "PRECINCT = " + txtPrecinctSearch.Text SelectMapFeaturesByAttributeQuery(activeView, featureLayer, whereClause) End Sub
whereClause = "PRECINCT = '" & txtPrecinctSearch.Text & "'"
I'm still having difficulty with this. The links provided are a very high-level overview, but I can't seem to find a way to get started.
I have got my button click function this far:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim pMap As IMapDocument Dim activeView As IActiveView Dim featureLayer As IFeatureLayer Dim whereClause As String pMap = New MapDocument activeView = pMap featureLayer = pMap.Layer(0, 0) whereClause = "PRECINCT = " + txtPrecinctSearch.Text SelectMapFeaturesByAttributeQuery(activeView, featureLayer, whereClause) End Sub
The variable txtPrecinctSearch.Text is coming from a user input textbox on the form. There are no errors shown in the code, but I get a fatal exception when I try to run this. I just don't understand what is causing the problem. It really is ridiculous that there is no clear documentation on how to set up the variables for the current map, active map frame, and the selected layer.
Thanks, James. I am still getting the fatal exception when I try to run the program, but adding the single quotes to the where clause is still a good idea.
Try 'some code that does stuff here Catch ex As Exception MsgBox(ex.ToString) End Try
Unfortunately, when I attempt to "Step Into" the function, it just launches ArcMap and goes into debug mode. The "Step Into" and "Step Over" tools become greyed out so I can't even diagnose where the exception is occuring.
A first chance exception of type 'System.InvalidCastException' occurred in PrecinctSearch2.dll A first chance exception of type 'System.InvalidCastException' occurred in PrecinctSearch2.dll A first chance exception of type 'System.InvalidCastException' occurred in PrecinctSearch2.dll
I tried placing the stop at several different points in the function, but regardless I get this error in the Immediate Window:A first chance exception of type 'System.InvalidCastException' occurred in PrecinctSearch2.dll A first chance exception of type 'System.InvalidCastException' occurred in PrecinctSearch2.dll A first chance exception of type 'System.InvalidCastException' occurred in PrecinctSearch2.dll
It seems vague, but I am trying to research what may be causing this.