I am transferring a code from a VBA module to a C# arcmap add-in. I am using ArcMap 10.2 and Visual Studio 2010.
I cannot figure out how to translate what appears to be a method from a different class (module) within an ElseIf Not statement that places 2 variables from the current class within the method. The biggest problem for me in translating the code is that I can't really figure out with 100% certainty what the original code is saying with that ElseIf Not statement.
Any assistance will be appreciated.
This is the code snippet that I am referring to (ValidFacet is the method from a different module):
ElseIf Not ValidFacet(txtFacetNumber.Text & cboFacetLetter.Text) Then
MsgBox "The facet you entered does not exist." & vbCrLf & _
"Please check and try again.", vbSystemModal
Here it is again within the original VBA code.
Private Sub cmdCreateFacet_Click()
Dim strFacetNumber As String
If txtFacetNumber.Text = "" Then
MsgBox "You must inter a value for the facet.", vbCritical + vbSystemModal
txtFacetNumber.SetFocus
Exit Sub
ElseIf cboFacetLetter.Text = "" And Not optFullFacet.Value Then
MsgBox "You must inter a value for the facet letter.", vbCritical + vbSystemModal
cboFacetLetter.SetFocus
Exit Sub
ElseIf Not ValidFacet(txtFacetNumber.Text & cboFacetLetter.Text) Then
MsgBox "The facet you entered does not exist." & vbCrLf & _
"Please check and try again.", vbSystemModal
cboFacetLetter.Text = ""
With txtFacetNumber
.Text = ""
.SetFocus
End With
Exit Sub
End If
strFacetNumber = txtFacetNumber.Text & cboFacetLetter.Text
DrawMap strFacetNumber
'MsgBox "Drawing"
cmdExit_Click
End Sub
Here is my C# translation so far. I have created a different class (FacetClass) for the ValidFacet method. I reference the FacetClass namespace (SingleFacet1) within the 'using' section although both SingleFacetForm1 and FacetClass are from the same namespace.
public partial class SingleFacetForm1 : Form
{
private void searchBtn_Click(object sender, EventArgs e)
{
string facetNumberstr;
if (facetNumbertxt.Text == "")
{
MessageBox.Show(new Form {TopMost = true }, "You must enter a value for the facet.");
facetNumbertxt.Focus();
}
else if (qFacetCmb.Text == "" && !(wFacetrb.Checked))
{
MessageBox.Show(new Form {TopMost = true }, "You must enter a value for the facet letter.");
qFacetCmb.Focus();
}
else (! FacetClass.ValidFacet(facetNumbertxt.Text && qFacetCmb.Text))
{
MessageBox.Show(new Form {TopMost = true }, "The facet you entered does not exist." + newLine + " " + "Please check and try again.");
qFacetCmb.Text = "";
facetNumbertxt.Text = "";
facetNumbertxt.Focus();
}
facetNumberstr = facetNumbertxt.Text + qFacetCmb.Text;
facetNumberstr.DrawMap facetNumberstr;
//facetNumberstr = new Draw(Map);
//Draw(Map) (facetNumberstr);
MessageBox.Show("Drawing");
//cancelBtn_Click();
cancelBtn_Click
}<CODE><SPAN class="pln" style="color: #000000;"> </SPAN>And just in case it helps, here is my C# code for ValidFacet:
public static void ValidFacet()
{
string newLine = System.Environment.NewLine;
IMxDocument pMxDoc = ArcMap.Document;
IMap pMap = pMxDoc.FocusMap;
IFeatureLayer pFLayer;
bool ValidFacet = true;
string facetStr = "";
int y;
pFLayer = (IFeatureLayer)pMap.get_Layer(0);
for (y = 0; y <= pMap.LayerCount - 1; y++)
{
if (pMap.get_Layer(y).Name == "Facet")
{
pFLayer = pMap.get_Layer(y) as IFeatureLayer;
}
else if (pFLayer as IFeatureLayer == null)
{
MessageBox.Show("Failed to find the Facet Layer." + newLine + "Please check and try again");
ValidFacet = false;
}
}
//IFeatureLayer pFLayer;
IGeoFeatureLayer pSearchLayer;
IFeatureClass pSearchFC;
IFeatureCursor pFCursor;
IQueryFilter pQueryFilter;
//pFLayer = pSearchLayer;
pSearchLayer = (IGeoFeatureLayer)pFLayer;
pSearchFC = pSearchLayer.DisplayFeatureClass;
//Set queryfilter and search for pages to update
pQueryFilter = new QueryFilter();
String strSelField = "qfname";
pQueryFilter.WhereClause = strSelField + " like '" + facetStr + "%'";
pFCursor = pSearchFC.Search(pQueryFilter, false);
if (pSearchFC.FeatureCount(pQueryFilter) < 1)
{
ValidFacet = false;
}
}<CODE><SPAN class="pln" style="color: #000000;"> </SPAN>