Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Journal - Show Attribute Value on TextBox (User Form) 5

Status
Not open for further replies.

DavidQ

Industrial
Oct 11, 2012
53
Hello Eng-Tips, I have a question regarding Attributes and Journal (vb). I need a user form to request and add attributes to a component part and use those attributes on a title block. So far i have identified and know how to build a user form, request the attribute and store as a variable; my question is how to show the value from a existing attribute value on a textbox (user form) to let the designer change the value or not. Form "fill_in_title_block_templ.vb" example I could extract the UF code lines and add some other code lines (form others examples) to show the value as follow:

Dim strCompany As String = "Co.SA"
Me.Attr1.Text = thepart.GetStringAttribute(strCompany)

**These lines are "<System.Diagnostics.DebuggerStepThrough()>" block form fill_in_title_block_templ example

From the error message and the original code I could guess that there is an issue regarding local and global variables on the changes I just made.

NX 7.5.0.32, trying to learn Visual Basic 2010. Only 10 months of experience with NX and a couple of weeks with VB2010...newbie
 
Replies continue below

Recommended for you

Here's a very quick example:

Code:
[COLOR=blue]Option[/color] [COLOR=blue]Strict[/color] [COLOR=blue]Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] NXOpen  
[COLOR=blue]Imports[/color] System.Windows.Forms  

[COLOR=blue]Module[/color] Module1  

    [COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()  
    [COLOR=blue]Public[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work  

    [COLOR=blue]Sub[/color] Main()  

        [COLOR=blue]Dim[/color] myDialog [COLOR=blue]As[/color] [COLOR=blue]New[/color] Dialog1  
        myDialog.ShowDialog()  

    End [COLOR=blue]Sub[/color]  


    [COLOR=blue]Public[/color] [COLOR=blue]Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As[/color] [COLOR=blue]String[/color]) [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]  

 [COLOR=green]'Unloads the image when the NX session terminates[/color]
        GetUnloadOption [COLOR=blue]=[/color] NXOpen.Session.LibraryUnloadOption.AtTermination  

    End [COLOR=blue]Function[/color]  

End [COLOR=blue]Module[/color]  



[COLOR=blue]Public[/color] Class Dialog1  
    [COLOR=blue]Private[/color] myAttributeTitle [COLOR=blue]As[/color] [COLOR=blue]String[/color] [COLOR=blue]=[/color] "Co.SA"  
    [COLOR=blue]Private[/color] [COLOR=blue]Sub[/color] OK_Button_Click(ByVal sender [COLOR=blue]As[/color] System.Object, [COLOR=blue]ByVal[/color] e [COLOR=blue]As[/color] System.EventArgs) [COLOR=blue]Handles[/color] OK_Button.Click  
        Me.DialogResult [COLOR=blue]=[/color] System.Windows.Forms.DialogResult.OK  

        workPart.SetAttribute(myAttributeTitle, TextBox1.Text)  

        Me.Close()  
    End [COLOR=blue]Sub[/color]  

    [COLOR=blue]Private[/color] [COLOR=blue]Sub[/color] Cancel_Button_Click(ByVal sender [COLOR=blue]As[/color] System.Object, [COLOR=blue]ByVal[/color] e [COLOR=blue]As[/color] System.EventArgs) [COLOR=blue]Handles[/color] Cancel_Button.Click  
        Me.DialogResult [COLOR=blue]=[/color] System.Windows.Forms.DialogResult.Cancel  
        Me.Close()  
    End [COLOR=blue]Sub[/color]  

    [COLOR=blue]Private[/color] [COLOR=blue]Sub[/color] Dialog1_Load(ByVal sender [COLOR=blue]As[/color] Object, [COLOR=blue]ByVal[/color] e [COLOR=blue]As[/color] System.EventArgs) [COLOR=blue]Handles[/color] Me.Load  

        [COLOR=blue]Try[/color]  
            TextBox1.Text [COLOR=blue]=[/color] workPart.GetStringAttribute(myAttributeTitle)  
        [COLOR=blue]Catch[/color] ex [COLOR=blue]As[/color] ApplicationException  
 [COLOR=green]'attribute does not exist[/color]
            TextBox1.Text [COLOR=blue]=[/color] ""  
        End [COLOR=blue]Try[/color]  

		Label1.Text [COLOR=blue]=[/color] myAttributeTitle  

    End [COLOR=blue]Sub[/color]  
End Class  



<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _  
[COLOR=blue]Partial[/color] Class Dialog1  
    [COLOR=blue]Inherits[/color] System.Windows.Forms.Form  

 [COLOR=green]'Form overrides dispose to clean up the component list.[/color]
    <System.Diagnostics.DebuggerNonUserCode()> _  
    [COLOR=blue]Protected[/color] [COLOR=blue]Overrides[/color] [COLOR=blue]Sub[/color] Dispose(ByVal disposing [COLOR=blue]As[/color] [COLOR=blue]Boolean[/color])  
        [COLOR=blue]Try[/color]  
            [COLOR=blue]If[/color] disposing [COLOR=blue]AndAlso[/color] components [COLOR=blue]IsNot[/color] [COLOR=blue]Nothing[/color] [COLOR=blue]Then[/color]  
                components.Dispose()  
            End [COLOR=blue]If[/color]  
        [COLOR=blue]Finally[/color]  
            MyBase.Dispose(disposing)  
        End [COLOR=blue]Try[/color]  
    End [COLOR=blue]Sub[/color]  

 [COLOR=green]'Required by the Windows Form Designer[/color]
    [COLOR=blue]Private[/color] components [COLOR=blue]As[/color] System.ComponentModel.IContainer  

 [COLOR=green]'NOTE: The following procedure is required by the Windows Form Designer[/color]
 [COLOR=green]'It can be modified using the Windows Form Designer.  [/color]
 [COLOR=green]'Do not modify it using the code editor.[/color]
    <System.Diagnostics.DebuggerStepThrough()> _  
    [COLOR=blue]Private[/color] [COLOR=blue]Sub[/color] InitializeComponent()  
        Me.TableLayoutPanel1 [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Windows.Forms.TableLayoutPanel()  
        Me.OK_Button [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Windows.Forms.Button()  
        Me.Cancel_Button [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Windows.Forms.Button()  
        Me.Label1 [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Windows.Forms.Label()  
        Me.TextBox1 [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Windows.Forms.TextBox()  
        Me.TableLayoutPanel1.SuspendLayout()  
        Me.SuspendLayout()  
 [COLOR=green]'[/color]
 [COLOR=green]'TableLayoutPanel1[/color]
 [COLOR=green]'[/color]
        Me.TableLayoutPanel1.Anchor [COLOR=blue]=[/color] CType((System.Windows.Forms.AnchorStyles.Bottom [COLOR=blue]Or[/color] System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)  
        Me.TableLayoutPanel1.ColumnCount [COLOR=blue]=[/color] 2  
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))  
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))  
        Me.TableLayoutPanel1.Controls.Add(Me.OK_Button, 0, 0)  
        Me.TableLayoutPanel1.Controls.Add(Me.Cancel_Button, 1, 0)  
        Me.TableLayoutPanel1.Location [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Drawing.Point(277, 122)  
        Me.TableLayoutPanel1.Name [COLOR=blue]=[/color] "TableLayoutPanel1"  
        Me.TableLayoutPanel1.RowCount [COLOR=blue]=[/color] 1  
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.0!))  
        Me.TableLayoutPanel1.Size [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Drawing.Size(146, 29)  
        Me.TableLayoutPanel1.TabIndex [COLOR=blue]=[/color] 0  
 [COLOR=green]'[/color]
 [COLOR=green]'OK_Button[/color]
 [COLOR=green]'[/color]
        Me.OK_Button.Anchor [COLOR=blue]=[/color] System.Windows.Forms.AnchorStyles.None  
        Me.OK_Button.Location [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Drawing.Point(3, 3)  
        Me.OK_Button.Name [COLOR=blue]=[/color] "OK_Button"  
        Me.OK_Button.Size [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Drawing.Size(67, 23)  
        Me.OK_Button.TabIndex [COLOR=blue]=[/color] 0  
        Me.OK_Button.Text [COLOR=blue]=[/color] "OK"  
 [COLOR=green]'[/color]
 [COLOR=green]'Cancel_Button[/color]
 [COLOR=green]'[/color]
        Me.Cancel_Button.Anchor [COLOR=blue]=[/color] System.Windows.Forms.AnchorStyles.None  
        Me.Cancel_Button.DialogResult [COLOR=blue]=[/color] System.Windows.Forms.DialogResult.Cancel  
        Me.Cancel_Button.Location [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Drawing.Point(76, 3)  
        Me.Cancel_Button.Name [COLOR=blue]=[/color] "Cancel_Button"  
        Me.Cancel_Button.Size [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Drawing.Size(67, 23)  
        Me.Cancel_Button.TabIndex [COLOR=blue]=[/color] 1  
        Me.Cancel_Button.Text [COLOR=blue]=[/color] "Cancel"  
 [COLOR=green]'[/color]
 [COLOR=green]'Label1[/color]
 [COLOR=green]'[/color]
        Me.Label1.Location [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Drawing.Point(12, 52)  
        Me.Label1.Name [COLOR=blue]=[/color] "Label1"  
        Me.Label1.Size [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Drawing.Size(134, 26)  
        Me.Label1.TabIndex [COLOR=blue]=[/color] 1  
        Me.Label1.Text [COLOR=blue]=[/color] "Attribute:"  
        Me.Label1.TextAlign [COLOR=blue]=[/color] System.Drawing.ContentAlignment.MiddleRight  
 [COLOR=green]'[/color]
 [COLOR=green]'TextBox1[/color]
 [COLOR=green]'[/color]
        Me.TextBox1.Location [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Drawing.Point(152, 56)  
        Me.TextBox1.Name [COLOR=blue]=[/color] "TextBox1"  
        Me.TextBox1.Size [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Drawing.Size(234, 20)  
        Me.TextBox1.TabIndex [COLOR=blue]=[/color] 2  
 [COLOR=green]'[/color]
 [COLOR=green]'Dialog1[/color]
 [COLOR=green]'[/color]
        Me.AcceptButton [COLOR=blue]=[/color] Me.OK_Button  
        Me.AutoScaleDimensions [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Drawing.SizeF(6.0!, 13.0!)  
        Me.AutoScaleMode [COLOR=blue]=[/color] System.Windows.Forms.AutoScaleMode.Font  
        Me.CancelButton [COLOR=blue]=[/color] Me.Cancel_Button  
        Me.ClientSize [COLOR=blue]=[/color] [COLOR=blue]New[/color] System.Drawing.Size(435, 163)  
        Me.Controls.Add(Me.TextBox1)  
        Me.Controls.Add(Me.Label1)  
        Me.Controls.Add(Me.TableLayoutPanel1)  
        Me.FormBorderStyle [COLOR=blue]=[/color] System.Windows.Forms.FormBorderStyle.FixedDialog  
        Me.MaximizeBox [COLOR=blue]=[/color] [COLOR=blue]False[/color]  
        Me.MinimizeBox [COLOR=blue]=[/color] [COLOR=blue]False[/color]  
        Me.Name [COLOR=blue]=[/color] "Dialog1"  
        Me.ShowInTaskbar [COLOR=blue]=[/color] [COLOR=blue]False[/color]  
        Me.StartPosition [COLOR=blue]=[/color] System.Windows.Forms.FormStartPosition.CenterParent  
        Me.Text [COLOR=blue]=[/color] "Dialog1"  
        Me.TableLayoutPanel1.ResumeLayout(False)  
        Me.ResumeLayout(False)  
        Me.PerformLayout()  

    End [COLOR=blue]Sub[/color]  
    [COLOR=blue]Friend[/color] [COLOR=blue]WithEvents[/color] TableLayoutPanel1 [COLOR=blue]As[/color] System.Windows.Forms.TableLayoutPanel  
    [COLOR=blue]Friend[/color] [COLOR=blue]WithEvents[/color] OK_Button [COLOR=blue]As[/color] System.Windows.Forms.Button  
    [COLOR=blue]Friend[/color] [COLOR=blue]WithEvents[/color] Cancel_Button [COLOR=blue]As[/color] System.Windows.Forms.Button  
    [COLOR=blue]Friend[/color] [COLOR=blue]WithEvents[/color] Label1 [COLOR=blue]As[/color] System.Windows.Forms.Label  
    [COLOR=blue]Friend[/color] [COLOR=blue]WithEvents[/color] TextBox1 [COLOR=blue]As[/color] System.Windows.Forms.TextBox  

End Class


www.nxjournaling.com
 
Thanks cowski for the your quick response. That's exactly what I looking for.[thumbsup]

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor