Hi Richard, I didn't know for for what purpose you were trying to use the goto that's why I assumed it was for as try catch system (is the most common use). On your case it's not the try/catch that has to be used. How I would solve this problem, is by using validationfunction with a return value. This way you could even put your validation in a separate class or library. It's a standalone function. Best practice to seperate this because if your using winforms, you could easily use the same validation when you decide to use ASP.net or something else. Compile the lib as a dll, put the function public and you can use it in any language. The enum is practical in .net because the intellisense kicks in but you could easily test it on the values 1,2,3 In fact you could consider the return value as a kind of a label. I'll put it in VB because I know this best but you'll get the idea. Enum ValidateError firstcondition = 1 secondcondition = 2 thirdcondition = 3 End Enum Private Sub ValidateMessage(ByVal someComplexType) Select Case ValidateSomething(someComplexType) Case ValidateError.firstcondition MsgBox("first") Case ValidateError.secondcondition MsgBox("second") Case ValidateError.thirdcondition MsgBox("third") Case Else MsgBox("ok") End Select End Sub Private Function ValidateSomething(ByVal someComplexType) As ValidateError If someComplexType < 0 Then Return ValidateError.firstcondition End If If someComplexType > 100 Then Return ValidateError.secondcondition End If If someComplexType > 1000 Then If someComplexType > 2000 Then Return ValidateError.thirdcondition End If End If '... End Function What do you think of it ? Regards Serge
Sergelp
Posts
-
Where Is IntelliSense For "goto" statements? -
Where Is IntelliSense For "goto" statements?Ever heard of try/catch - if then else ... Goto usage is the ultimate spaghetti type programming, so you don't want to go that way. It's not a crusade, it's a fact. Believe me - a former spaghetti analyser that has programmed for years in language like Data General/UBB (Universal Business BASIC). For a long time in those languages (interpreter based) the "do while/for loop" instruction didn't exist and every line in your program had a linenumber. With the goto you could force a kind of do while or even if then else. Also a goto made the program go faster (interpreter) skipping the lines that it didn't needed. The goto was of course abused making the readability very poor. Here's an example of a do while in old BASIC 100 if i<10 then 110 ... (instruction) 120 ... 130 ... 140 goto 100 150 end if Gradually the linenumber became labels and vb3,vb4,... took on this way of programming. @start 100 if i<10 then 110 ... 120 goto @start 130 end if Those (nostalgic) days are gone now... :-) I think the only reason why MS didn't completely erase the command is backwards compatibility with VB6 where you had to use it with (on) error handling. Now you have an (even better) initiative for this, the try/catch/finaly block. The finaly part is certainly an improvement. Conclusion : "Spaghetti is nice as long as it's on your plate accompagnied with some tomatoesauce, cheese and some tabasco".
modified on Tuesday, July 13, 2010 5:20 AM