.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Windows Forms

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Jedimaster
1734 Views, 10 Replies

Windows Forms

I am using MSVS 2012 Pro on a Windows 7 64 bit system for AutoCAD MAP 2015. I am trying to reconstruct a VBA routine into a VB .NET. When I initalize the form I enumerate a sepecific folders subfolders into a combobox. Actually the routine seems works okay in AutoCAD. MSVS 2012 Pro is the one throwing the error.If you go into the design view of the form it throws an error. Which is not a big probelm If you create the whole form then program it I guess. If in the design view I press continue to ignore the error it erases all my added code. I am learning as I go so it is a bit fustrating.

 

Imports System.IO
Private Sub InitializeComponent()

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim RootFolder As String
Dim i As Integer
Dim CFolder As String

RootFolder = "c:\Apps\Blocks\"
If Directory.Exists(RootFolder) Then
Dim Tier1 As System.Collections.Generic.IEnumerable(Of String)
Tier1 = System.IO.Directory.EnumerateDirectories(RootFolder)
Me.ComboBox1.Items.Clear()
For i = 0 To Tier1.Count

******* If I unremark this it throws the error 

              CFolder = Tier1(i)

********
'CFolder = Replace(CFolder, RootFolder, "", 1, -1, 1)
'CFolder = Replace(CFolder, "\", "", 1, -1, 1)
'If CFolder <> "" Then
' Me.ComboBox1.Items.Add(CFolder)
'End If
Next i
'If Me.ComboBox1.Items.Count > 0 Then
'Me.ComboBox1.SelectedIndex = 0
'End If
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

End Sub

 

 

 

Message 1 Could not find type 'System.Linq.Enumerable+ElementAtOrDefault'.
Please make sure that the assembly that contains this type is referenced.
If this type is a part of your development project, make sure that the
project has been successfully built using settings for your current platform or Any CPU.


Instances of this error (1)

Call Stack
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializer.DeserializeStatementToInstance(IDesignerSerializationManager manager, CodeStatement statement)
at System.ComponentModel.Design.Serialization.CodeDomSerializer.Deserialize(IDesignerSerializationManager manager, Object codeObject)
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.DeserializeName(IDesignerSerializationManager manager, String name, CodeStatementCollection statements)

10 REPLIES 10
Message 2 of 11
SENL1362
in reply to: Jedimaster

I'am not familiar with VB but it seems to me that you need to add
Import System.Linq;

Message 3 of 11
Jedimaster
in reply to: SENL1362

I have tried

 

Imports System.Linq
Imports System.Linq.Enumerable
Imports System.Linq.EnumerableExecutor
Imports System.Linq.EnumerableQuery

 

Still same error.

Message 4 of 11
_gile
in reply to: Jedimaster

Hi,

 

System.IO.Directory.EnumerateDirectories() method return an IEnumerable<string> which is a lazy sequence that does not implement the Index property, so you cannot use a for loop with this kind of collection.

You can convert the the IEnumerable<string> sequence into an indexed array using the ToArray() Linq method or simply use foreach to enumarate it.

 

If you do not use the lazyness behavior of the IEnumrable<string>, you'd rather use the Directory.GetDirectories() method which returns a classical indexed array of strings.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 11
Jedimaster
in reply to: _gile

Not sure if fully understand what you are recommending. I uses System.IO.Directory.EnumerateDirectories only because that was what I found using the object browser.  I changed to Directory.GetDirectories. It is thowing new error.

 

Dim RootFolder As String
RootFolder = "C:\Apps\Blocks\"
If Directory.Exists(RootFolder) Then
Dim CFolder As String
Dim Tier1 As Array = Directory.GetDirectories(RootFolder)

 

****************Error here

For Each CFolder In Tier1
' Me.ComboBox1.Items.Add(CFolder)
Next

***********************

 

End If

Message 1 The variable 'VB$t_ref$L0' is either undeclared or was never assigned.
There is no stack trace or error line information available for this error.

Message 2 The variable 'CFolder' is either undeclared or was never assigned.
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)

Message 3 The variable 'Tier1' is either undeclared or was never assigned.
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)

 

Message 6 of 11
_gile
in reply to: Jedimaster

Hi,

 

I'm not very comfortable with VB and didn't make tests, but this should work:

 

Dim rootFolder As String = "C:\UApps\Blocks"
If Directory.Exists(rootFolder) Then
    Dim tier() As String = Directory.GetDirectories(rootFolder)
    For Each cFolder As String In tier
        Me.ComboBox1.Items.Add(cFolder)
    Next
End If

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 11
Jedimaster
in reply to: _gile

Thanks for all the  input.I works great in AutoCAD. MSVS 2012 Pro is still throwing error. I have a feeling this is a bug that cannot be resolved. I will just have to program after Form is completed and  not use Design mode with programed form.

 

Dim RootFolder As String
RootFolder = "C:\Apps\Blocks\"
If Directory.Exists(RootFolder) Then
Dim Tier1() As String = Directory.GetDirectories(RootFolder)
For Each cFolder As String In Tier1
Me.ComboBox1.Items.Add(cFolder)
Next
End If

 

Message 1 The variable 'cFolder' is either undeclared or was never assigned.

1. ClassLibrary9 Form1.Designer.vb Line:43 Column:1

at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)

2. There is no stack trace or error line information available for this error.

Message 2 The variable 'Tier1' is either undeclared or was never assigned.

 

Message 8 of 11

Hi,

 

Try populating ComboBox1 in a separate function. Call the function after InitializeComponent() is completed.   



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 9 of 11

This may sound stupid, but I am new to VB .NET, how do I do this? Do I add the Function to the Form Class or to the main Public Class? How do I call from the IntializeComponet.  If create a function and call from IntializeComponet I get 'Method not found'.

Message 10 of 11
Jedimaster
in reply to: Jedimaster

I could be wrong but it does not allow  a call from the Private Sub InitializeComponent.

Message 11 of 11
Jedimaster
in reply to: Jedimaster

I moved everything out of Private Sub InitializeComponent and now process with the Form.Show from the main public class that loads the form.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta