Last post Aug 20, 2012 11:05 AM by David Anton
Aug 16, 2012 04:55 AM|damoUK|LINK
I'm converting some C# code to vb, and (having had some help from the community here already) have encountered another problem...
I'm trying to convert the following:
if (controlb.GetType().BaseType == typeof(SurveyQ))
// do stuff
SurveyQ is a class I'm referring to. Converting the type doesn't seem to work. I've figured that I can't use "=" when converting types and have got this as far as:
If TypeOf controlb.GetType().BaseType Is GetType(SurveyQ) Then
' do stuff
but I now get errors on the GetType(SurveyQ) part, with the error "Keyword does not name a type".
Anyone able to offer some insight as to how to resolve this.
Aug 16, 2012 05:21 AM|Menno van den Heuvel|LINK
How about you use
TryCast instead of the current clunky solution? TryCast controlb to
SurveyQ. Then check in your If/Then if your new variable is Nothing. Especially if inside your If, you're going to be using SurveyQ methods or properties.
Aug 16, 2012 06:49 AM|damoUK|LINK
I can't get this to work using trycast, what am I doing wrong?
Aug 20, 2012 11:05 AM|David Anton|LINK
You're adding too much to the conversion - it should just be:
If controlb.GetType().BaseType Is GetType(SurveyQ) Then
' do stuff