Example MsgBox with a Prompt, yesNoCancel [Title]

I have tried over and over to put together a working Message box

Dim Prompt As String, Tilte As String, Status As String, Status2 As String
Dim Buttons As Integer

Prompt = "Welcome to Learning 5"
Title = "Unload File Check"
Status = "Was Unloaded"
Status2 = "File NOT Unloaded"
Buttons = vbOKOnly + vbCancel
MsgBox (Prompt)

I got this far, the Prompt shows the "Welcome to Learning 5"

Every time I tried adding second line of text with the & vbCrLf & Status got an error, I tried the "Status", I tried [Status]

If I just did (prompt + Status it worked but a mess, wanted two lines, plus I wanted the vbYesNoCancel buttons to pop-Up and I wanted a Title for the box

Anyway I called myself searching various ways

MsgBox Examples, Examples of MsgBox Function. Found a lot on Excel on-line but could not seem to make a working one for a starting point.

Jan gave me an example of Macro using variable and I was able to follow the working format on that. I keep looking for a working example

to learn from. Someone please help? No Will someone help me

This also was a failure MsgBox "Test Message Wanted" & CStr(This), vbOKOnly, + CrLf "Check"

Parents
  • Hi Richard,

    I Guess your Problem is the Word "Prompt", because it is a VBA Keyword, and so it is not allowed as variable name. That's why I use Pretext Notation.

    Sub DialogTest()
    
        Dim sPrompt As String, sTilte As String, sStatus As String, sStatus2 As String
        Dim nButtons As Integer
    
        sPrompt = "Welcome to Learning 5"
        sTitle = "Unload File Check"
        sStatus = "Was Unloaded"
        sStatus2 = "File NOT Unloaded"
        nButtons = vbOKOnly + vbCancel
        
        myPromt = sPrompt & vbNewLine & sStatus
        
       Dim myResult As VbMsgBoxResult
       
       myResult = MsgBox(myPromt, vbOKCancel, sTitle)
       
        
    End Sub
    

    Mit freundlichen Grüßen / Best regards
    Volker Hüfner

    |  AB_DATE Engineering  Software   |  ab-date.de  |

Reply
  • Hi Richard,

    I Guess your Problem is the Word "Prompt", because it is a VBA Keyword, and so it is not allowed as variable name. That's why I use Pretext Notation.

    Sub DialogTest()
    
        Dim sPrompt As String, sTilte As String, sStatus As String, sStatus2 As String
        Dim nButtons As Integer
    
        sPrompt = "Welcome to Learning 5"
        sTitle = "Unload File Check"
        sStatus = "Was Unloaded"
        sStatus2 = "File NOT Unloaded"
        nButtons = vbOKOnly + vbCancel
        
        myPromt = sPrompt & vbNewLine & sStatus
        
       Dim myResult As VbMsgBoxResult
       
       myResult = MsgBox(myPromt, vbOKCancel, sTitle)
       
        
    End Sub
    

    Mit freundlichen Grüßen / Best regards
    Volker Hüfner

    |  AB_DATE Engineering  Software   |  ab-date.de  |

Children
  • So Appreciate, I thought when it said Prompt that was what I was supposed to do, Like the pretext idea. Thank you

    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus

  • Volker Hufner, Thanks to you and all who responded

    Question from your example:

    Sub DialogTest() '080619 This worked
    ' via reply from MicroStation Reply

    Dim sPrompt As String, sTilte As String, sStatus As String, sStatus2 As String
    Dim nButtons As Integer

    sPrompt = "Welcome to Learning 5"
    sTitle = "Unload File Check"
    sStatus = "Was Unloaded"
    sStatus2 = "File NOT Unloaded"
    nButtons = vbOKOnly + vbCancel

    myPromt = sPrompt & vbNewLine & sStatus & vbNewLine & sStatus2

    Dim myResult As VbMsgBoxResult ' forms the

    'myResult = MsgBox(myPromt, vbOKCancel, sTitle)
    myResult = MsgBox(myPromt, nButtons, sTitle)

    End Sub

    I saw your nButtons so I commented out the working myResult and copied it back using

    the nbuttons, but when you run that it gives 

     all fine but I was expecting

    the vbOKonly + vbCancel, did not know what happened? I also plan to try to add +vbdefaultButton2 which should move it to Retry

    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus

  • I read this information:

    VbMsgBoxResult Value Button Selected
    vbOK 1 OK ------------------------------ give a 1 when pressed
    vbCancel 2 Cancel ------------------------------ give a 2 when pressed
    vbAbort 3 Abort ------------------------------ give a 3 when pressed
    vbRetry 4 Retry ------------------------------ give a 4 when pressed
    vbIgnore 5 Ignore ------------------------------ give a 5 when pressed
    vbYes 6 Yes ------------------------------ give a 6 when pressed
    vbNo 7 No ------------------------------ give a 7 when pressed

    can you get something back from MsgBox to show or use the values ? Only wondering

    I did no see any on Critical, ok gotta go, thank you again.

    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus

  • Hi Richard,

    you are mixing up results and definitions. I could only mark out Jon Summers. You need to learn some fundamental basics. You can't learn "how to drive a car" by watching and copying Michael Knight in knight-rider on TV :-) Some lessons by a qualified instructor will save you month of frustration!

    Mit freundlichen Grüßen / Best regards
    Volker Hüfner

    |  AB_DATE Engineering  Software   |  ab-date.de  |

  • Hi Richard,

    As Jon and Volker mention it is best to abstract, learn and differentiate between "common Microsoft VBA programming" vs. "MicroStation VBA programming" and leverage each company's respective documentation, communities, and forums; for best results.

    Here are a few places that may help get started with Microsoft Office VBA (same engine used in MicroStation VBA - just extended with our Object Model).

    Lastly, YouTube provides a number of very good (though not all so good) Microsoft VBA Getting Started videos.  In particular, I (just my opinion) found this series to provide a very nice and helpful pace and topics covered consider when getting starting: Leila Gharani's: Excel VBA and Macros Tutorials.

    Given the above locations, things like MsgBox constants and VBA Keywords (reserved for VBA names not to use as your own variables) will be more clear going forward.

    Good luck and HTH,
    Bob