cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a form from within a Block Styler application

Pioneer
Pioneer

I have a block styler application and would like to call a windows form that I have created within the block styler application. The new form is called Form1.vb and I have not been able to figure out how to call it from code. I have been able to display a form created programatically but not the one contained within the application.

 

I have tried the following code but get the error "Type 'Form1' is not defined.

 

Dim myForm as New Form1 

myForm.ShowDialog()

 

NX 9.0

VB.Net

11 REPLIES

Re: Calling a form from within a Block Styler application

Siemens Phenom Siemens Phenom
Siemens Phenom

 

Assuming you have created the Form within the project, this should work:

 

   Public Function update_cb(ByVal block As NXOpen.BlockStyler.UIBlock) As Integer
        Try

            If block Is button0 Then
                Dim myForm As Form1 = New Form1
                myForm.ShowDialog()

            End If

        Catch ex As Exception

            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
        End Try
        update_cb = 0
    End Function

 

Note that I used an Action Button to launch it.  If it would help I can zip up my project and dialog and post it - just let me know.

 

Re: Calling a form from within a Block Styler application

Pioneer
Pioneer

Steve,  Yes, Form1 was created within my project and I have inserted the code you suggested in the OK action button function. However when I run the code I still get the error that Type 'Form1 is not defined'. I have imported System.Windows.Forms thinking it was needed but still get the error. If you could post your zipped project for me to look at that may help or any other suggestions would be appreciated.

 

 

Public Function ok_cb() As Integer
        Dim errorCode As Integer = 0
        Try

            Dim myForm As Form1 = New Form1
            myForm.ShowDialog()
            
        Catch ex As Exception

            '---- Enter your exception handling code here -----
            errorCode = 1
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
        End Try
        ok_cb = errorCode
    End Function

Re: Calling a form from within a Block Styler application

Siemens Phenom Siemens Phenom
Siemens Phenom

Re: Calling a form from within a Block Styler application

Pioneer
Pioneer

Steve, I’m getting the same error message when running your code too. What am I doing wrong?

 

Re: Calling a form from within a Block Styler application

Siemens Phenom Siemens Phenom
Siemens Phenom

 

Hmmm, as you can imagine, it is hard for me to guess what might be going wrong if you are using my project, because it worked perfectly here.

 

So...did you use my entire project, or did you just paste my code into your old project?

 

I created the dialog in NX9 and saved it, then I created an NXOpen VB.Net project in the Visual Studio, and overwrote the template code with the code that Block Styler wrote.

 

Then I selected Project -> Add Windows Form and made the form, added a button and one line of code to close the form when the button was pressed.  Then I added the code I sent earlier to the update callback.

 

Oddly enough I did not have to add an Imports statement or a Reference to the Windows Forms library.

Re: Calling a form from within a Block Styler application

Pioneer
Pioneer

Steve, I used your entire project. I unzipped it and ran it as a journal application from within NX using Module1.vb as the source.

Re: Calling a form from within a Block Styler application

Siemens Phenom Siemens Phenom
Siemens Phenom

 

AHA!!!!!!!!!!!!!

 

When you run the .VB file using Tools -> Journal -> Play, one of the restrictions is that all of your source code has to be in one .VB file.

 

So in the project, the form code is created as a separate .VB file, and that file will not be triggered running in the Journal editor.  It is possible, but a little bit of trouble, to take your Form code and put it inside the same source file so you can run as a journal.  I'll see what I can do as time permits...but at least we have a logical explanation for the behavior that you are seeing.

 

 

 

Re: Calling a form from within a Block Styler application

Pioneer
Pioneer

Steve, could I just build a DLL and run it as an NXOpen application?

Re: Calling a form from within a Block Styler application

Siemens Phenom Siemens Phenom
Siemens Phenom

 

Yes, absolutely!  That is what I did.

 

Sometimes people need to run the .VB because they do not have the dotnet_author license, but as long as you have the license, that is the simplest solution.