B
Benjamino5
I need to write a function which checks for certain strings in a field, then
reports back a "field type" (my term, not the actual fieldtype in Word) based
on the strings it finds. I don't know quite how to write this. Here's what I
have so far:
Function FieldType(oField As Field) As String
FieldType = Switch((InStr(oField.Code, "mNL1")), "mNL1", (InStr(oField.Code,
"mNLa")), "mNLa", _
(InStr(oField.Code, "MACROBUTTON")), "TypeHere")
End Function
The problem is that if none of the expressions in the Switch function are
true, there's an error. I'd like to add an "OTHER" string that the function
would produce if the field it checks isn't any of my "types" (mNL1, mNLa, and
TypeHere). How would I do that?
Should I be using something other than the Switch function? I thought of
using a Select Case statement, but I'm not sure how to phrase the InStr
checks as a single expression that could be evaluated for each case.
I feel like the answer is staring me in the face, but I'm not familiar
enough with programming to know what I should do. Thanks for any advice you
can give me!
reports back a "field type" (my term, not the actual fieldtype in Word) based
on the strings it finds. I don't know quite how to write this. Here's what I
have so far:
Function FieldType(oField As Field) As String
FieldType = Switch((InStr(oField.Code, "mNL1")), "mNL1", (InStr(oField.Code,
"mNLa")), "mNLa", _
(InStr(oField.Code, "MACROBUTTON")), "TypeHere")
End Function
The problem is that if none of the expressions in the Switch function are
true, there's an error. I'd like to add an "OTHER" string that the function
would produce if the field it checks isn't any of my "types" (mNL1, mNLa, and
TypeHere). How would I do that?
Should I be using something other than the Switch function? I thought of
using a Select Case statement, but I'm not sure how to phrase the InStr
checks as a single expression that could be evaluated for each case.
I feel like the answer is staring me in the face, but I'm not familiar
enough with programming to know what I should do. Thanks for any advice you
can give me!