Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

thread561-332871 how could I add

Status
Not open for further replies.

Fabio Sena

Automotive
Mar 25, 2019
1
0
0
BR
thread561-332871

how could I add more TEXTBOX in this case, I would like to have at least 6 TEXTBOX, this example is wonderful, but I can not open via VISUAL BASIC correctly. If someone can show me how to add one more would be incredible.
 
Replies continue below

Recommended for you

Below is code for 6 textboxes:

Code:
Option Strict Off  
Imports System  
Imports NXOpen  
Imports System.Windows.Forms  

Module Module1  

	Dim theSession As Session = Session.GetSession()  
	Public workPart As Part = theSession.Parts.Work  

Sub Main()  

	Dim myDialog As New Dialog1  
	myDialog.ShowDialog()  

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  


Public Class Dialog1  

	Private myAttributeTitle1 As String = "Attrib 1" 
	Private myAttributeTitle2 As String = "Attrib 2" 
	Private myAttributeTitle3 As String = "Attrib 3" 
	Private myAttributeTitle4 As String = "Attrib 4" 
	Private myAttributeTitle5 As String = "Attrib 5" 
	Private myAttributeTitle6 As String = "Attrib 6" 
				
	Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click 
	
		Me.DialogResult = System.Windows.Forms.DialogResult.OK  

		workPart.SetAttribute(myAttributeTitle1, TextBox1.Text) 
		workPart.SetAttribute(myAttributeTitle2, TextBox2.Text) 
		workPart.SetAttribute(myAttributeTitle3, TextBox3.Text) 
		workPart.SetAttribute(myAttributeTitle4, TextBox4.Text) 
		workPart.SetAttribute(myAttributeTitle5, TextBox5.Text) 
		workPart.SetAttribute(myAttributeTitle6, TextBox6.Text) 
						
		Me.Close() 
		
	End Sub  

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

	Private Sub Dialog1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  

		Try  
		
			TextBox1.Text = workPart.GetStringAttribute(myAttributeTitle1)  
			Catch ex1 As ApplicationException  
		
			'attribute does not exist
			TextBox1.Text = ""  
			
		End Try  
		
		Try  
		
			TextBox2.Text = workPart.GetStringAttribute(myAttributeTitle2) 
			
			Catch ex2 As ApplicationException  
		
			'attribute does not exist
			TextBox2.Text = ""  
			
		End Try  
		
		Try  
		
			TextBox3.Text = workPart.GetStringAttribute(myAttributeTitle3) 
			
			Catch ex3 As ApplicationException  
		
			'attribute does not exist
			TextBox3.Text = ""  
			
		End Try 
		
		Try  
		
			TextBox4.Text = workPart.GetStringAttribute(myAttributeTitle4) 
			
			Catch ex4 As ApplicationException  
		
			'attribute does not exist
			TextBox4.Text = ""  
			
		End Try  
		
		Try  
		
			TextBox5.Text = workPart.GetStringAttribute(myAttributeTitle5) 
			
			Catch ex5 As ApplicationException  
		
			'attribute does not exist
			TextBox5.Text = ""  
			
		End Try 
		
		Try  
		
			TextBox6.Text = workPart.GetStringAttribute(myAttributeTitle6) 
			
			Catch ex6 As ApplicationException  
		
			'attribute does not exist
			TextBox6.Text = ""  
			
		End Try  
		
		Label1.Text = myAttributeTitle1
		Label2.Text = myAttributeTitle2
		Label3.Text = myAttributeTitle3
		Label4.Text = myAttributeTitle4
		Label5.Text = myAttributeTitle5
		Label6.Text = myAttributeTitle6								

	End Sub  
	
End Class  



<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _  
Partial Class Dialog1  
	Inherits System.Windows.Forms.Form  

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

 'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer  

 'NOTE: The following procedure is required by the Windows Form Designer
 'It can be modified using the Windows Form Designer.  
 'Do not modify it using the code editor.
	<System.Diagnostics.DebuggerStepThrough()> _  
	Private Sub InitializeComponent()
		Me.OK_Button = New System.Windows.Forms.Button()
		Me.Cancel_Button = New System.Windows.Forms.Button()
		Me.Label1 = New System.Windows.Forms.Label()
		Me.Label2 = New System.Windows.Forms.Label()
		Me.Label3 = New System.Windows.Forms.Label()
		Me.Label4 = New System.Windows.Forms.Label()
		Me.Label5 = New System.Windows.Forms.Label()
		Me.Label6 = New System.Windows.Forms.Label()
		Me.TextBox1 = New System.Windows.Forms.TextBox()
		Me.TextBox2 = New System.Windows.Forms.TextBox()
		Me.TextBox3 = New System.Windows.Forms.TextBox()
		Me.TextBox4 = New System.Windows.Forms.TextBox()
		Me.TextBox5 = New System.Windows.Forms.TextBox()
		Me.TextBox6 = New System.Windows.Forms.TextBox()
		Me.SuspendLayout()
		'
		'OK_Button
		'
		Me.OK_Button.Anchor = System.Windows.Forms.AnchorStyles.None
		Me.OK_Button.Location = New System.Drawing.Point(179, 373)
		Me.OK_Button.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
		Me.OK_Button.Name = "OK_Button"
		Me.OK_Button.Size = New System.Drawing.Size(122, 42)
		Me.OK_Button.TabIndex = 7
		Me.OK_Button.Text = "OK"
		'
		'Cancel_Button
		'
		Me.Cancel_Button.Anchor = System.Windows.Forms.AnchorStyles.None
		Me.Cancel_Button.DialogResult = System.Windows.Forms.DialogResult.Cancel
		Me.Cancel_Button.Location = New System.Drawing.Point(435, 373)
		Me.Cancel_Button.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
		Me.Cancel_Button.Name = "Cancel_Button"
		Me.Cancel_Button.Size = New System.Drawing.Size(122, 42)
		Me.Cancel_Button.TabIndex = 8
		Me.Cancel_Button.Text = "Cancel"
		'
		'Label1
		'
		Me.Label1.Location = New System.Drawing.Point(18, 22)
		Me.Label1.Margin = New System.Windows.Forms.Padding(6, 0, 6, 0)
		Me.Label1.Name = "Label1"
		Me.Label1.Size = New System.Drawing.Size(183, 48)
		Me.Label1.TabIndex = 0
		Me.Label1.Text = "Attribute1:"
		'
		'Label2
		'
		Me.Label2.Location = New System.Drawing.Point(18, 78)
		Me.Label2.Margin = New System.Windows.Forms.Padding(6, 0, 6, 0)
		Me.Label2.Name = "Label2"
		Me.Label2.Size = New System.Drawing.Size(183, 48)
		Me.Label2.TabIndex = 0
		Me.Label2.Text = "Attribute2:"
		'
		'Label3
		'
		Me.Label3.Location = New System.Drawing.Point(18, 133)
		Me.Label3.Margin = New System.Windows.Forms.Padding(6, 0, 6, 0)
		Me.Label3.Name = "Label3"
		Me.Label3.Size = New System.Drawing.Size(183, 48)
		Me.Label3.TabIndex = 0
		Me.Label3.Text = "Attribute3:"
		'
		'Label4
		'
		Me.Label4.Location = New System.Drawing.Point(18, 188)
		Me.Label4.Margin = New System.Windows.Forms.Padding(6, 0, 6, 0)
		Me.Label4.Name = "Label4"
		Me.Label4.Size = New System.Drawing.Size(183, 48)
		Me.Label4.TabIndex = 0
		Me.Label4.Text = "Attribute4:"
		'
		'Label5
		'
		Me.Label5.Location = New System.Drawing.Point(18, 245)
		Me.Label5.Margin = New System.Windows.Forms.Padding(6, 0, 6, 0)
		Me.Label5.Name = "Label5"
		Me.Label5.Size = New System.Drawing.Size(183, 48)
		Me.Label5.TabIndex = 0
		Me.Label5.Text = "Attribute5:"
		'
		'Label6
		'
		Me.Label6.Location = New System.Drawing.Point(18, 302)
		Me.Label6.Margin = New System.Windows.Forms.Padding(6, 0, 6, 0)
		Me.Label6.Name = "Label6"
		Me.Label6.Size = New System.Drawing.Size(183, 48)
		Me.Label6.TabIndex = 0
		Me.Label6.Text = "Attribute6:"
		'
		'TextBox1
		'
		Me.TextBox1.Location = New System.Drawing.Point(179, 22)
		Me.TextBox1.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
		Me.TextBox1.Name = "TextBox1"
		Me.TextBox1.Size = New System.Drawing.Size(526, 29)
		Me.TextBox1.TabIndex = 1
		'
		'TextBox2
		'
		Me.TextBox2.Location = New System.Drawing.Point(179, 78)
		Me.TextBox2.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
		Me.TextBox2.Name = "TextBox2"
		Me.TextBox2.Size = New System.Drawing.Size(526, 29)
		Me.TextBox2.TabIndex = 2
		'
		'TextBox3
		'
		Me.TextBox3.Location = New System.Drawing.Point(179, 133)
		Me.TextBox3.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
		Me.TextBox3.Name = "TextBox3"
		Me.TextBox3.Size = New System.Drawing.Size(526, 29)
		Me.TextBox3.TabIndex = 3
		'
		'TextBox4
		'
		Me.TextBox4.Location = New System.Drawing.Point(179, 188)
		Me.TextBox4.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
		Me.TextBox4.Name = "TextBox4"
		Me.TextBox4.Size = New System.Drawing.Size(526, 29)
		Me.TextBox4.TabIndex = 4
		'
		'TextBox5
		'
		Me.TextBox5.Location = New System.Drawing.Point(179, 244)
		Me.TextBox5.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
		Me.TextBox5.Name = "TextBox5"
		Me.TextBox5.Size = New System.Drawing.Size(526, 29)
		Me.TextBox5.TabIndex = 5
		'
		'TextBox6
		'
		Me.TextBox6.Location = New System.Drawing.Point(179, 299)
		Me.TextBox6.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
		Me.TextBox6.Name = "TextBox6"
		Me.TextBox6.Size = New System.Drawing.Size(526, 29)
		Me.TextBox6.TabIndex = 6
		'
		'Form1
		'
		Me.AcceptButton = Me.OK_Button
		Me.AutoScaleDimensions = New System.Drawing.SizeF(11.0!, 24.0!)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.CancelButton = Me.Cancel_Button
		Me.ClientSize = New System.Drawing.Size(741, 448)
		Me.Controls.Add(Me.Cancel_Button)
		Me.Controls.Add(Me.OK_Button)
		Me.Controls.Add(Me.TextBox1)
		Me.Controls.Add(Me.TextBox2)
		Me.Controls.Add(Me.TextBox3)
		Me.Controls.Add(Me.TextBox4)
		Me.Controls.Add(Me.TextBox5)
		Me.Controls.Add(Me.TextBox6)
		Me.Controls.Add(Me.Label1)
		Me.Controls.Add(Me.Label2)
		Me.Controls.Add(Me.Label3)
		Me.Controls.Add(Me.Label4)
		Me.Controls.Add(Me.Label5)
		Me.Controls.Add(Me.Label6)
		Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
		Me.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
		Me.MaximizeBox = False
		Me.MinimizeBox = False
		Me.Name = "Dialog1"
		Me.ShowInTaskbar = False
		Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
		Me.Text = "Dialog1"
		Me.ResumeLayout(False)
		Me.PerformLayout()

	End Sub
	
	Friend WithEvents OK_Button As System.Windows.Forms.Button
	Friend WithEvents Cancel_Button As System.Windows.Forms.Button  
	Friend WithEvents Label1 As System.Windows.Forms.Label 
	Friend WithEvents Label2 As System.Windows.Forms.Label 
	Friend WithEvents Label3 As System.Windows.Forms.Label 
	Friend WithEvents Label4 As System.Windows.Forms.Label 
	Friend WithEvents Label5 As System.Windows.Forms.Label 
	Friend WithEvents Label6 As System.Windows.Forms.Label 
	Friend WithEvents TextBox1 As System.Windows.Forms.TextBox 
	Friend WithEvents TextBox2 As System.Windows.Forms.TextBox 
	Friend WithEvents TextBox3 As System.Windows.Forms.TextBox 
	Friend WithEvents TextBox4 As System.Windows.Forms.TextBox 
	Friend WithEvents TextBox5 As System.Windows.Forms.TextBox 
	Friend WithEvents TextBox6 As System.Windows.Forms.TextBox 

End Class

With best regards
Michael
 
You will need Windows form designer to edit the table.

"It is impossible to make anything foolproof because fools are so ingenious."
 
Status
Not open for further replies.
Back
Top