Using message boxes

Send a message to your users

 

Is it doing anything? I think I clicked the button... It may have crashed. Is it done, did it work?

 

Users like to know what is going on. With some journals it is pretty obvious; run it and geometry is created, the view changes, other files open, etc etc. Other journals do their work in the background and there is no way to know what is going on, unless it tells you. Sometimes all it takes is a message such as "The journal completed with no errors" to put the user at ease. The message box is a great way to convey information to the user; and it can also be used to get simple input from the user.

 

Both the NXOpen API and the .NET framework supply methods to display message boxes; both are easy to use, the main differences being the visual appearance of the message boxes. The NXOpen message box will have the same visual theme as the NX application, whereas the .NET message box appearance will be controlled by Windows settings. The .NET version is more flexible, but in most instances either version will do the job.

 

Let's look at some code:

'NXJournaling
'November 9, 2012
'demo of NX and .NET message boxes
 
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports System.Windows.Forms
 
Module Module1
 
    Sub Main()
 
        Dim theSession As Session = Session.GetSession()
        Dim theUISession As UI = UI.GetUI
        Dim response As Integer
        Dim messages(4) As String
        messages(0) = "message line 1"
        messages(1) = "message line 2"
        messages(2) = "message line 3"
        messages(3) = "message line 4"
        messages(4) = "message line 5"
        Dim answer As String = ""
 
        '+----------------------------------+
        '¦                                  ¦
        '¦   first, the NX messagebox       ¦
        '¦                                  ¦
        '¦                                  ¦
        '¦           +--------+             ¦
        '¦           ¦   OK   ¦             ¦
        '¦           +--------+             ¦
        '+----------------------------------+
 
 
        response = theUISession.NXMessageBox.Show("Question", NXMessageBox.DialogType.Question, "This is a question?")
        '1 = Yes
        '2 = No
 
        If response = 1 Then
            answer = "Yes"
        Else
            answer = "No"
        End If
        response = theUISession.NXMessageBox.Show("Information", NXMessageBox.DialogType.Information, "You answered: " & answer)
        '-2 = OK was pressed
        response = theUISession.NXMessageBox.Show("Warning", NXMessageBox.DialogType.Warning, "This is your last warning, mister!")
        '-2 = OK was pressed
        response = theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "This is not a drill!")
        '-2 = OK was pressed
 
        'show multi line messages
        theUISession.NXMessageBox.Show("Multiple line message", NXMessageBox.DialogType.Information, messages)
 
 
        '+----------------------------------+
        '¦                                  ¦
        '¦   now for the .NET messagebox    ¦
        '¦                                  ¦
        '¦                                  ¦
        '¦           +--------+             ¦
        '¦           ¦   OK   ¦             ¦
        '¦           +--------+             ¦
        '+----------------------------------+
 
        'plain, untitled message box with OK button
        MessageBox.Show("simplest message box")
 
        'message box with title, icon, and OK button
        MessageBox.Show("Message box with message, title, and icon", "Here is the title", _
                        MessageBoxButtons.OK, MessageBoxIcon.Information)
 
        'message box to ask a question
        Dim result1 As DialogResult
        result1 = MessageBox.Show("Did you eat breakfast today?", "Just a question", _
                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question)
 
        MessageBox.Show("You answered: " & result1.ToString, "Your answer", _
                        MessageBoxButtons.OK, MessageBoxIcon.Information)
 
        MessageBox.Show("For this message box, the default button is 'Yes'" & _
                        ControlChars.NewLine & "pressing the enter button will trigger the 'Yes' button", _
                        "Default button Yes", MessageBoxButtons.YesNoCancel, _
                        MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
 
        MessageBox.Show("For this message box, the default button is 'No'" & _
                ControlChars.NewLine & "pressing the enter button will trigger the 'No' button", _
                "Default button No", MessageBoxButtons.YesNoCancel, _
                MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)
 
        'see http://msdn.microsoft.com/en-us/library/system.windows.forms.messagebox.aspx for more information on the messagebox class
 
 
    End Sub
 
 
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
 
        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
 
    End Function
 
End Module

 

If you would like more information on the NXMessagebox; open the NX help, navigate to the .NET API reference, switch to the Index tab, and type "NXMessagebox" in the search field.

More information on the .NET messagebox can be found here at MSDN.

 

Keep those users informed, they will thank you for it.

Well, ok, they won't thank you, but they may complain at you if you don't!

Comments

Hey,

Im trying to make a multiline response box I am currently using the following, but it isnt coming out, only the first line is, then the input line. Any advice?

Options = NXInputBox.GetInputNumber("What would you like to replace(enter the number)?" & vbCrLf & "Option 1:Full Cell Replacement (Multiline)" & vbCrLf & " Option 2: Full Cell Replacement (Single Line)" & vbCrLf & " Options 3: Part Cell Replacement" & vbCrLf & " Option 0: Exit", "Table Text Replacement Options")

I think the text is being added to the input box; however, the elements of the input box are not moving to allow the long text to be seen. Try using the Windows.Forms input box; I think it will do a better job of displaying multiple lines of text. An example of the windows input box can be found in the last code sample in the article:
http://nxjournaling.com/content/user-input-input-boxes

Hello,

The windows form input box does work and in case anyone else reads this, I think it works better than the NX one so I recommend using it.

In what situations would you use the NX input box?

The NX input box is handy if you cannot use or do not want to use the MS library. There is a linux version of NX which would not have access to the MS code. I have heard that MS is making a version of .net that will run on linux, so this may change in the near future...