Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

best way to check user input in journal 1

Status
Not open for further replies.

multicaduser

Industrial
Jan 29, 2013
261
The only options I know of for input in a vb journal are the winforms that can be found at we do not have any other licenses. Now, for user options I would like the user to type and integer (1,2,3, or 4), and based on that input perform one of four functions.

The following function can be used to check if it was an integer, however, is there a simple way to check the value besides brute force.

Loop Until Integer.TryParse(answer, myInt)

There may be a completely different way to do multiple choice that I'm not aware of.

Still trying to move programs from grip to vb.

Thanks in advance.

NX 12.0.1.7 Windows 10
 
Replies continue below

Recommended for you

If you want to build a dialog that has the modern NX look and feel, you will need an author license and a block styler license. If you do not have access to those licenses, you have a few options:
[ul]
[li]Use an input box. Both the NXOpen API and the .net framework provide input boxes; an example can be found here.[/li]
[li]Winforms, which you can use without any additional license. You can use a free IDE from MS to design your form and help write your code. I recommend picking up an IDE (MS offers a great one) to help write the code, even if you never create a user form.[/li]
[li]There is an NXOpen API function to create a very GRIP-like options dialog (example code below).[/li]
[/ul]

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic

Imports NXOpen
Imports NXOpen.UF


Module Module107

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()

    Dim theUI As UI = UI.GetUI

    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main(ByVal args() As String)

        lw.Open()
        Dim workPart As Part = theSession.Parts.Work

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Select Option")

        Dim optionList As New List(Of String)
        optionList.Add("option 1")
        optionList.Add("option 2")
        optionList.Add("option C")
        optionList.Add("fourth option")

        Dim retVal As Integer = 0
        Dim title As String = "Here are your options"
        theUfSession.Ui.LockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
        retVal = theUfSession.Ui.DisplayMenu(title, 1, optionList.ToArray, optionList.Count)
        theUfSession.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
        '1 = Back
        '2 = Cancel
        '5-18 = menu item selected
        '19 = disallowed state, unable to bring up dialog

        Select Case retVal
            Case Is = 1
                lw.WriteLine("user pressed Back")
            Case Is = 2
                lw.WriteLine("user pressed Cancel")
            Case Is = 19
                lw.WriteLine("something went wrong...")
            Case Else
                lw.WriteLine("user chose option: " & (retVal - 4).ToString)
        End Select


    End Sub


End Module

Edit: forgot to mention that using the block styler or a winform would be preferred because that way you can limit the user to only certain, rational choices. An input box allows the user to enter practically anything which can be difficult to parse into something useful; or may be difficult for the user to remember what to enter.

www.nxjournaling.com
 
Hey cowski, this is awesome, guess you don't know what you don't know, and yea, it does remind me of grip option programming. Thanks for the help. I'll post the code when I get that far, but it may take a little while. Thanks again.

NX 12.0.1.7 Windows 10
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor