none
"Hello World".ShowDialog() not possible in VB.NET RRS feed

  • Question

  • Say I have a extension method on String ShowDialog, that displays a mesagebox with the specified string.

    Why I cant do now

    "Hello World".ShowDialog()

    and need to play with 

    Call "Hello World".ShowDialog()

    or 

    CStr("Hello World").ShowDialog()

    or even

    Dim myString = "Hello World"
    myString.ShowDialog()

    or even

    If "Hello World".ShowDialog() = Windows.Forms.DialogResult.OK Then
        CStr("Thank You!").ShowDialog()
    End If



    Best regards, Sergiu


    Tuesday, December 18, 2012 3:33 PM

Answers

  • It has nothing to do with your extension method.

    In VB.Net any statement that starts with " is illegal. For example you can't do something like

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            "Hello".ToUpper()
        End Sub


    A.m.a.L Hashim
    Microsoft Most Valuable Professional
    My Blog - Dot Net Goodies

    • Proposed as answer by Blackwood Wednesday, December 19, 2012 4:14 AM
    • Marked as answer by Youen ZenModerator Friday, December 28, 2012 8:57 AM
    Tuesday, December 18, 2012 3:51 PM

All replies

  • It has nothing to do with your extension method.

    In VB.Net any statement that starts with " is illegal. For example you can't do something like

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            "Hello".ToUpper()
        End Sub


    A.m.a.L Hashim
    Microsoft Most Valuable Professional
    My Blog - Dot Net Goodies

    • Proposed as answer by Blackwood Wednesday, December 19, 2012 4:14 AM
    • Marked as answer by Youen ZenModerator Friday, December 28, 2012 8:57 AM
    Tuesday, December 18, 2012 3:51 PM
  • What other can I say that "VB.NET" sucks, knowing that this is not a limitation in C#?

    see also http://stackoverflow.com/q/13936382/185593


    Best regards, Sergiu

    Tuesday, December 18, 2012 4:01 PM
  • You should use C# from now on and stay away from VB.NET
    Wednesday, December 19, 2012 3:59 AM
  • Hi Sergiu,

    Welcome to the MSDN forum.

    As explained by Amal and other members in stackoverflow, currently VB.NET compiler doesn't support this syntax. You could submit this issue as feature request to http://connect.microsoft.com/.

    Thanks,


    Shanks Zen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 19, 2012 5:12 AM
    Moderator
  • What other can I say that "VB.NET" sucks, knowing that this is not a limitation in C#?

    see also http://stackoverflow.com/q/13936382/185593


    Best regards, Sergiu

    This is funny, that it is now possible what some C# has written in past as wrong in VB and they did not know they were not talking about VB for Net.

    Is now showed as a feature from C#.

    There is absolute no good reason to create in the String Class a extension member like you do, it can only lead to unintended behavior if somebody has in future to maintain a program from somebody who did this.

    Be aware I've seen more things like you do now in past. The result was always that it did cost much money because some lousy programmers used what they called "features" but in fact where mistakes (bugs) from the tool makers.

    I hope that Shanks correct his statement, it is no omission from VB, it should not be possible in C# because it makes from that a kind of scripting language. However, that cannot be changed anymore because of breaking changes.

    Those programmers who use and want this show in fact the beginners status they have.


    Success
    Cor



    • Edited by Cor Ligthert Wednesday, December 19, 2012 11:43 AM
    • Proposed as answer by Chantellie Tuesday, August 19, 2014 6:01 AM
    Wednesday, December 19, 2012 11:40 AM