I have some VB code I modified to add functionality to an older CAD routine (originally written by a consultant). The new code works fine and appears to do what I want. My question is, not being a programmer, I’m sure I did this quite primitively. I was wondering if anyone could peruse my code to see if there are any suggestions as to cleaning it up a bit (particularly with the numerous IF statements.
CODE:
If txtOrig_Mtrl = "" Then
If Not txtSize_2.Text = "" And Not IsNull(txtSize_2.Text) And Not txtSize_2.Text = 0 Then
If txtConst_Date = "9999" Then
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + "x" + Trim(txtSize_2.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + " (*)"
Else
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + "x" + Trim(txtSize_2.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + " (" + Trim(txtConst_Date.Text) + ")"
End If
If Not sLength = txtLength_1.Text Or Not sSize = txtSize_1.Text Or Not sSize2 = txtSize_2.Text Or Not sDate = txtConst_Date.Text Or Not sMaterial = cboMaterial.Text Then
ScanDrawingRemoveSTOText
StoPipeTextLine
End If
Else
If txtConst_Date = "9999" Then
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + " (*)"
Else
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + " (" + Trim(txtConst_Date.Text) + ")"
End If
If Not sLength = txtLength_1.Text Or Not sSize = txtSize_1.Text Or Not sSize2 = txtSize_2.Text Or Not sDate = txtConst_Date.Text Or Not sMaterial = cboMaterial.Text Then
ActiveModelReference.UnselectAllElements
ActiveModelReference.SelectElement ele
ScanDrawingRemoveSTOText
StoPipeTextLine
End If
End If
Else
If Not txtSize_2.Text = "" And Not IsNull(txtSize_2.Text) And Not txtSize_2.Text = 0 Then
If txtConst_Date = "9999" Then
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + "x" + Trim(txtSize_2.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + "-" + Trim(txtOrig_Mtrl.Text) + " (*)"
Else
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + "x" + Trim(txtSize_2.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + "-" + Trim(txtOrig_Mtrl.Text) + " (" + Trim(txtConst_Date.Text) + ")"
End If
If Not sLength = txtLength_1.Text Or Not sSize = txtSize_1.Text Or Not sSize2 = txtSize_2.Text Or Not sDate = txtConst_Date.Text Or Not sMaterial = cboMaterial.Text Then
ScanDrawingRemoveSTOText
StoPipeTextLine
End If
Else
If txtConst_Date = "9999" Then
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + "-" + Trim(txtOrig_Mtrl.Text) + " (*)"
Else
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + "-" + Trim(txtOrig_Mtrl.Text) + " (" + Trim(txtConst_Date.Text) + ")"
End If
If Not sLength = txtLength_1.Text Or Not sSize = txtSize_1.Text Or Not sSize2 = txtSize_2.Text Or Not sDate = txtConst_Date.Text Or Not sMaterial = cboMaterial.Text Then
ActiveModelReference.UnselectAllElements
ActiveModelReference.SelectElement ele
ScanDrawingRemoveSTOText
StoPipeTextLine
End If
End If
End If
If this appears too daunting, I understand.
Thanks,
SKK
CODE:
If txtOrig_Mtrl = "" Then
If Not txtSize_2.Text = "" And Not IsNull(txtSize_2.Text) And Not txtSize_2.Text = 0 Then
If txtConst_Date = "9999" Then
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + "x" + Trim(txtSize_2.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + " (*)"
Else
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + "x" + Trim(txtSize_2.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + " (" + Trim(txtConst_Date.Text) + ")"
End If
If Not sLength = txtLength_1.Text Or Not sSize = txtSize_1.Text Or Not sSize2 = txtSize_2.Text Or Not sDate = txtConst_Date.Text Or Not sMaterial = cboMaterial.Text Then
ScanDrawingRemoveSTOText
StoPipeTextLine
End If
Else
If txtConst_Date = "9999" Then
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + " (*)"
Else
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + " (" + Trim(txtConst_Date.Text) + ")"
End If
If Not sLength = txtLength_1.Text Or Not sSize = txtSize_1.Text Or Not sSize2 = txtSize_2.Text Or Not sDate = txtConst_Date.Text Or Not sMaterial = cboMaterial.Text Then
ActiveModelReference.UnselectAllElements
ActiveModelReference.SelectElement ele
ScanDrawingRemoveSTOText
StoPipeTextLine
End If
End If
Else
If Not txtSize_2.Text = "" And Not IsNull(txtSize_2.Text) And Not txtSize_2.Text = 0 Then
If txtConst_Date = "9999" Then
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + "x" + Trim(txtSize_2.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + "-" + Trim(txtOrig_Mtrl.Text) + " (*)"
Else
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + "x" + Trim(txtSize_2.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + "-" + Trim(txtOrig_Mtrl.Text) + " (" + Trim(txtConst_Date.Text) + ")"
End If
If Not sLength = txtLength_1.Text Or Not sSize = txtSize_1.Text Or Not sSize2 = txtSize_2.Text Or Not sDate = txtConst_Date.Text Or Not sMaterial = cboMaterial.Text Then
ScanDrawingRemoveSTOText
StoPipeTextLine
End If
Else
If txtConst_Date = "9999" Then
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + "-" + Trim(txtOrig_Mtrl.Text) + " (*)"
Else
sStoPipeText = Trim(txtLength_1.Text) + "'-" + Trim(txtSize_1.Text) + Chr(34) + " " + Trim(cboMaterial.Text) + "-" + Trim(txtOrig_Mtrl.Text) + " (" + Trim(txtConst_Date.Text) + ")"
End If
If Not sLength = txtLength_1.Text Or Not sSize = txtSize_1.Text Or Not sSize2 = txtSize_2.Text Or Not sDate = txtConst_Date.Text Or Not sMaterial = cboMaterial.Text Then
ActiveModelReference.UnselectAllElements
ActiveModelReference.SelectElement ele
ScanDrawingRemoveSTOText
StoPipeTextLine
End If
End If
End If
If this appears too daunting, I understand.
Thanks,
SKK