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.
I have encountered another instance where the same situation arises; ValidFacet is used in a different class and with a string parameter. I still cannot figure out exactly what the original vba code is trying to say or how to convert the vba to C#.
If Not ValidFacet(pTopFac) Then
pTopFac = "END OF DATA"
End If
So far I have this (which doesn't work):
if (FacetClass.ValidFacet() != pTopFac)
{
pTopFac = "END OF DATA";
}
Since the statement seems to be checking to see if the variable's value exists in the ValidFacet, I have also tried
if (!FacetClass.ValidFacet.Contains(pTopFac))
The statement does not work but perhaps it is closer to what is needed?
. . .
. . .
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.
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
}
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;
}
}