Jump to content

Recommended Posts

Posted

What a long title. I am hopeing this is a simple problem and I have just overlooked the obvious. However, continuing from my other posts you know I am trudging my way through VB.Net with the help of Jerry Winters' book. All is good as far as it goes....

 

I am trying to rewrite a VBA routine of ours but while I have most of the component parts in place I can't find out how to stick it all together.

 

The routine....

I have a form with a combo box, a list, a label and a command button.

The combo box displays a list of the layers.

The list lists all the text entities on the selected layer.

The label displays the number of text entities on the selected layer.

The button exports the list to a text file.

(The text file is supplied to our panel builders to create heat shrink wire end markers.)

 

The combo box population is easy.

I haven't got the list population sorted but shouldn't be a problem using the selection set currently used for the label count (yesterday's problem - now sorted).

 

What I want to happen is that when the combo box is changed my list and label get updated. However the selection set is in my class definition and the combo box change is in the form class. I can't see a way of passing from the combo box changed event to a sub within the class. If I put the selection set sub in the form class it doesn't like the call to the Editor.

 

What have I missed out?

Posted

What I want to happen is that when the combo box is changed my list and label get updated.

 

I believe this is what you're after, Dave:

 

Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

       ComboBox1.SelectedIndex = 0

   End Sub

   Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

       Dim comboBox As ComboBox = CType(sender, ComboBox)

       Label1.Text = CType(comboBox.SelectedItem, String)

   End Sub

End Class

Posted

However the selection set is in my class definition and the combo box change is in the form class. I can't see a way of passing from the combo box changed event to a sub within the class. If I put the selection set sub in the form class it doesn't like the call to the Editor.

 

Hard to tell, especially without code... Could you post a snippet? It sounds like you're experiencing a permission issue, but again, not sure what you're attempting to do within the non-Form Class. More information is needed.

Posted

Thanks BB. Yet again I will have to leave this for a while as real work and a half day off are going to prevent me looking at it. I will try and post the code after it has been tidied up. It has taken a bit of cut & paste today and needs recovering. :D

Posted
Thanks BB. Yet again I will have to leave this for a while as real work and a half day off are going to prevent me looking at it. I will try and post the code after it has been tidied up. It has taken a bit of cut & paste today and needs recovering. :D

 

As always, you're welcome; I'm happy to help... As for the Cut+Pasting, 'surgery' is always painful, better now than later. :P

 

Enjoy your half-day. :)

Posted

That didn't take as long as expected. (Still not looked at yours thoguh).

 

My code...

This bit loads the combo box with the layer names and displays Form1

[size=2][color=#0000ff][size=2][color=#0000ff]Public[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Sub[/color][/size][/color][/size][size=2] ExportFerrules()[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] i [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Integer[/color][/size][/color][/size][size=2] = 1[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myForm [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] Form1[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myDB [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] Database = HostApplicationServices.WorkingDatabase[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Using[/color][/size][/color][/size][size=2] myTrans [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] Transaction = myDB.TransactionManager.StartTransaction[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myLT [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] LayerTable = myDB.LayerTableId.GetObject(OpenMode.ForRead)[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]For[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Each[/color][/size][/color][/size][size=2] myOID [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] ObjectId [/size][size=2][color=#0000ff][size=2][color=#0000ff]In[/color][/size][/color][/size][size=2] myLT[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myLTR [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] LayerTableRecord = myOID.GetObject(OpenMode.ForRead)[/size]
[size=2]myForm.ComboBox1.Items.Add(myLTR.Name)[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size][/color][/size][size=2] UCase(myLTR.Name) = [/size][size=2][color=#a31515][size=2][color=#a31515]"FERRULES"[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Then[/color][/size][/color][/size][size=2] i = myForm.ComboBox1.Items.Count[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Next[/color][/size]
[/color][/size][size=2]myForm.ComboBox1.SelectedIndex = i - 1[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Using[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] j [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Integer[/color][/size][/color][/size][size=2] = 0[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] LayNm [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]String[/color][/size][/color][/size][size=2] = myForm.ComboBox1.Items(i - 1)[/size]
[size=2][color=#008000][size=2][color=#008000]Call TextOnLayer(j, LayNm)[/color][/size]
[/color][/size][size=2]myForm.Label2.Text = j[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Select[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Case[/color][/size][/color][/size][size=2] Application.ShowModalDialog(myForm)[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Case[/color][/size][/color][/size][size=2] System.Windows.Forms.DialogResult.OK[/size]
[size=2]MsgBox([/size][size=2][color=#a31515][size=2][color=#a31515]"Hello"[/color][/size][/color][/size][size=2])[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Case[/color][/size][/color][/size][size=2] System.Windows.Forms.DialogResult.Cancel[/size]
[size=2]MsgBox([/size][size=2][color=#a31515][size=2][color=#a31515]"Do Nothing."[/color][/size][/color][/size][size=2])[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Select[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Sub[/color][/size]
[/color][/size]

 

This bit counts the number of text objects on the layer specified by the combo box.

[size=2][color=#0000ff][size=2][color=#0000ff]Public[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Sub[/color][/size][/color][/size][size=2] TextOnLayer([/size][size=2][color=#0000ff][size=2][color=#0000ff]ByRef[/color][/size][/color][/size][size=2] j, [/size][size=2][color=#0000ff][size=2][color=#0000ff]ByRef[/color][/size][/color][/size][size=2] LayNm)[/size]
[size=2][color=#008000][size=2][color=#008000]'Add bit about counting text on layer[/color][/size]
[/color][/size][size=2][color=#008000][size=2][color=#008000]'This has gone back in to the load stage for now.[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myEd [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] Editor = DocumentManager.MdiActiveDocument.Editor[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myTVs(3) [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] TypedValue[/size]
[size=2]myTVs.SetValue([/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] TypedValue(DxfCode.Operator, [/size][size=2][color=#a31515][size=2][color=#a31515]"<AND"[/color][/size][/color][/size][size=2]), 0)[/size]
[size=2]myTVs.SetValue([/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] TypedValue(DxfCode.Start, [/size][size=2][color=#a31515][size=2][color=#a31515]"TEXT"[/color][/size][/color][/size][size=2]), 1)[/size]
[size=2]myTVs.SetValue([/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] TypedValue(DxfCode.LayerName, LayNm), 2)[/size]
[size=2]myTVs.SetValue([/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] TypedValue(DxfCode.Operator, [/size][size=2][color=#a31515][size=2][color=#a31515]"AND>"[/color][/size][/color][/size][size=2]), 3)[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myFilter [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] SelectionFilter(myTVs)[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myPSR [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] PromptSelectionResult = myEd.SelectAll(myFilter)[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size][/color][/size][size=2] myPSR.Status = PromptStatus.OK [/size][size=2][color=#0000ff][size=2][color=#0000ff]Then[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] mySS [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] SelectionSet = myPSR.Value[/size]
[size=2]j = mySS.Count[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Sub[/color][/size]

[size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Class[/color][/size]
[/color][/size]

 

and this bit tells you that the combo box has a new selected layer

 

[size=2]
[/size][size=2][color=#0000ff][size=2][color=#0000ff]Private[/color][/size][/color][/size][size=2] [/size][size=2][color=#0000ff][size=2][color=#0000ff]Sub[/color][/size][/color][/size][size=2] ComboBox1_SelectedIndexChanged([/size][size=2][color=#0000ff][size=2][color=#0000ff]ByVal[/color][/size][/color][/size][size=2] sender [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff][size=2][color=#0000ff]ByVal[/color][/size][/color][/size][size=2] e [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff][size=2][color=#0000ff]Handles[/color][/size][/color][/size][size=2] ComboBox1.SelectedIndexChanged
MsgBox(ComboBox1.SelectedItem)
[/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2] [/size][size=2][color=#0000ff][size=2][color=#0000ff]Sub
[/color][/size][/color][/size]

 

what I was expecting to be able to do is call the "TextOnLayer" sub from the combo box "IndexChanged" code but they appear to be mutually exclusive.

Posted

I can get it to do what I want

 

but only by copying all the Imports from the Class.vb module to the Form1.vb module. Surely this isn't the right way to do it?

Posted

As I understand it, each Class file in your project/solution (i.e., .vb, .cs, etc.) requires the dependent Imports (using in C#) statement(s), in order to enable Type names to be reference without Namespace qualification.

Posted

thanks, I thought it might be simple. It just looks wrong.

Posted
thanks, I thought it might be simple. It just looks wrong.

 

Perhaps... But it (using Imports statement(s)) sure saves one an awful lot of typing when you're coding more than a 'hello world' equivalent. :thumbsup:

 

Compare this (with):

 

Namespace CADTutor.AutoCAD.PseudoCode.SampleWithImports

   Public Class Commands

       <[color="blue"]CommandMethod[/color]("WITH")> _
       Public Sub SampleWithImports()

           Dim doc As [color="blue"]Document[/color] =
               [color="blue"]Application.DocumentManager.MdiActiveDocument[/color]

           Dim ed As [color="blue"]Editor [/color]= doc.Editor

           ed.WriteMessage(vbLf & "** Bowties are cool ** " & vbLf)

       End Sub

       [color="green"]''<-- other CommandMethod methods[/color]

   End Class

End Namespace

 

 

... To this (without):

 

Namespace CADTutor.AutoCAD.PseudoCode.SampleWithoutImports

   Public Class Commands

       <[color="red"]Autodesk.AutoCAD.Runtime.[/color][color="blue"]CommandMethod[/color]("WITHOUT")> _
       Public Sub SampleWithoutImports()

           Dim doc As [color="red"]Autodesk.AutoCAD.ApplicationServices.[/color][color="blue"]Document [/color]=
               [color="red"]Autodesk.AutoCAD.ApplicationServices.[/color][color="blue"]Application _
               .DocumentManager.MdiActiveDocument[/color]

           Dim ed As [color="red"]Autodesk.AutoCAD.EditorInput.[/color][color="blue"]Editor [/color]= doc.Editor

           ed.WriteMessage(vbLf & "** Bowties are cool ** " & vbLf)

       End Sub

       [color="green"]''<-- other CommandMethod methods[/color]

   End Class

End Namespace

Posted

yes but the later one is more colourful

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...