VB Riddle


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: VB Riddle

  1. #1
    Bruno Paris Guest

    VB Riddle

    Hi, all
    I have only one form in my project. When I click on my form, statement
    'a' will set caption to "1", but statement 'b' gives run-time error.
    Q: How is this possible?

    Option Explicit

    Private Sub Form_Click()
    Dim style As VbMsgBoxStyle

    style = vbExclamation Or vbOKCancel
    Caption = MsgBox("Hello", style) ' this line works OK

    style = vbExclamation Or vbOKOnly
    Caption = MsgBox("Hehe", style) ' <<<< ERROR
    End Sub

    Have fun!
    Bruno



  2. #2
    Bruno Paris Guest

    Re: VB Riddle

    Sorry, I forgot the labels:

    Option Explicit

    Private Sub Form_Click()
    Dim style As VbMsgBoxStyle

    style = vbExclamation Or vbOKCancel
    a: Caption = MsgBox("Hello", style) ' this line works OK

    style = vbExclamation Or vbOKOnly
    b: Caption = MsgBox("Hehe", style) ' <<<< ERROR
    End Sub


    Bruno Paris wrote:
    >Hi, all
    >I have only one form in my project. When I click on my form,

    statement
    >'a' will set caption to "1", but statement 'b' gives run-time error.
    >Q: How is this possible?

    ....



  3. #3
    bob butler Guest

    Re: VB Riddle


    Bruno Paris <nospam_ameba@zg.tel.hr> wrote in message
    news:38e5d0d4@news.devx.com...
    > Sorry, I forgot the labels:
    >
    > Option Explicit
    >
    > Private Sub Form_Click()
    > Dim style As VbMsgBoxStyle
    >
    > style = vbExclamation Or vbOKCancel
    > a: Caption = MsgBox("Hello", style) ' this line works OK
    >
    > style = vbExclamation Or vbOKOnly
    > b: Caption = MsgBox("Hehe", style) ' <<<< ERROR
    > End Sub
    >
    >
    > Bruno Paris wrote:
    > >Hi, all
    > >I have only one form in my project. When I click on my form,

    > statement
    > >'a' will set caption to "1", but statement 'b' gives run-time error.
    > >Q: How is this possible?

    > ...



    Using VB6 with SP3 this runs fine for me. I would make two suggestions to
    (IMHO) improve the readability and stability of the code:

    a: Me.Caption=CStr(Msgbox("Hello",style))
    b: Me.Caption=CStr(Msgbox("Hehe",style))




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center