Hi Guys
How would I best resolve this, VS 2K5 is complaing about the values in the case statements and not able to test for object Identity, I don't want to test for object identity I'm looking for values, I know I could add the ToString option after optCurrency.Value.ToString and then put both the "2" and "3" in quotes but that does't seem right either, any thoughts
Select Case Me.optCurrency.Value
Case 2
Me.optCurrency.Value = CurrencyType.Euros
'load combo boxCall LoadFundId(CurrencyType.Euros)
Case 3
Me.optCurrency.Value = CurrencyType.Sterling
'load combo box
Call LoadFundId(CurrencyType.Sterling)
End Select
Thanks

Error 27 Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity.
hakan65
Hi
Thanks
danny y
Glad I coud help. . .
Yeah it looks like alot of code. . . thats because it is vb
. On the other hand alot of it is IDE generated, too.
What this is doing is making your form as "dumb" as possible. The Class file is the 'model'. The form's load method sets up the 'view'. the events specify the 'control.'
The important thing to note is that the goal was not to replace the select/case statement.
The select case statement produced a "smell" indicating that perhaps the model was not really representative of the problem domain.
By designing a more robust class hierarchy, the need for the select/case was removed. At the same time we gained a more flexible model.
The elimination of the select/case is just a side effect!
Easy_Care
Hi Blair
Thanks for the reply, I agree select case statements are bad practice a hang up from vb 5/6 I guess. I will look into these "type" class patterns and see if that makes for better coding.
do you know of any specific information in MSDN I can look up
Duncan
demercurio
before you say 'but you make it so complicated' I say guess again. . .
what happens when you decide to add a new currency type
total code rewrite using the select case. . . just add a couple of lines of code using 'TypeCode' class pattern.
Plus the code reads better. . . and is faster!
Daniel Holt
here is an extremely good investigation of the pattern:
Right Click and Save this PDF
Ken D.
Hi Blair
I am a little confused by this abstract classing, I can see how it works, just not in this case, perhaps I should have provided more information.
Select Case Me.optCurrency.ValueCase 2
Me.optCurrency.Value = CurrencyType.Euros
'load combo box
Call LoadFundId(CurrencyType.Euros)
Case 3
Me.optCurrency.Value = CurrencyType.Sterling
'load combo box
Call LoadFundId(CurrencyType.Sterling)
End Select
the me.optCurrency was a group of radio buttons, each having a value, depending on which one has been selected, this calls loadFundId(currencyType.XXXX) and populates a dropdown. Me is the current form (I guess it would "this" in c#)
So not sure whether this needs to be an abstract class, so to get over the issue being thrown by VS2K5 I've changed to an if statement rather than a select case.
I will certianly look into abstract class in more detail, as I can see how they would benefit an application, thanks for your help
Duncan
waterhunter
Hi Blair
Well I didn't expect that, wow thanks for that, my first reaction is that is a lot of code just to replace a select case statement, but the more I look at it the more cleaner and readable it becomes, and makes for a better application in the long run, so I will look at implmenting this into the app (got probably 4 or 5 areas to clean up).
I have also decided to step my learning of c#, been reading some interesting articles about where Microsoft is taking VB and C#, so might be better to start now.
Thanks once again
Duncan
Ed Reid
also. . . you could override the Derived CurrencyType.ToString such as:
and change the assignbutton function:
and the viewer:Andres Yepes
what is optCurrency an integer or a currency type
on another note. . . I can't stand select case statements. . . typically bad style.
I will assume that Me in your example is a class called CurrencyUser
the right way is to make Currency an abstract class with an abstract method
LoadFundId(ByVal aUser as CurrencyUser)inherit from Currency for all your different types.
Each CurrencyUser has a Currency field.
CurrencyUser user just calls Me.Currency.LoadFundID(Me)
done!
nhaas
google "Replace Conditional with Polymorphism" or "Replace Type Code with State/Strategy"
here's an example: Replace Conditional with Polymorphism
Get Fowler's Refactoring: Improving the Design of Existing Code and the orginal Gang Of Four:
Wes Williamson
create a new windows app.
add a class module call CurrencyType and add this code:
in your main form. . . drop three radio buttons a combobox and a button. . .
put this code in it:
compile and run. . .
code can be found here: http://www.obj-tec.com/MSDNForums/TestOptsForDuncan/testopts.zip
10wattmindtrip
Hi
point taken about the language, yes vb should have been changed long before vb.net, too much of a hand holding thing I feel. and to a lesser extent they are still but thats another topic.
anyway thanks for the advice I will look at the information you have provided and hopefully that will put me straight.
Once again thanks
Duncan
Archana Kamath
now you ready. . .lets say you want to add the foo currency type. . . In CurrencyTypes.vb, change this:
to
and add this class:
and simply add a new radiobutton and an assignment in the FormLoad:
AndyMc
Hi
I guess you're using c#, I am learning c# but have a better knowledge of VB so logical choice for me. I didn't think the type of language used mattered such much these days as everything is compiled into MSIL.