Coded some stuff in VB today. While programming I had to convert some values from the model into a string representation for the UI. A little bit similar to a #displayString method in Smalltalk. So I wrote this little helper procedure:
Public Function DisplayStringForValue(ByVal vSomeValue As String) As String
If vSomeValue = "" Then
DisplayStringForValue = "..."
Else
DisplayStringForValue = vSomeValue
End If
End Function
Unfortunately I had a little typo and the code looked like this:
Public Function DisplayStringForValue(ByVal vSomeValue As String) As String
If vSomeValue = "" Then
DisplayStringForValue = "..."
End
DisplayStringForValue = vSomeValue
End If
End Function
Do you notice the difference? I was first a little bit confused that my program always stopped when I used the Run button without displaying a form. But after a closer look ...
Unfortunately one has to close an "if" construct with an "end if" in VisualBasic. I havent noticed that I had an "end" instead of an "else", maybe it came exactly from a previously typed "end if".
For the VB compiler this is valid code since there is an "end" statement in Basic. It was sucessfully compiled but the "end" directly stopped my program when running.
So remember: always test and never trust your compiler, especially if you have to work with such a painfull syntax like VB has ...
No comments:
Post a Comment