Visual Studio - Autocomplete words for custom Objects / Libraries - vb.net

When typing code in Visual Studio 2015 it automatically gives me alternatives on what I can do with my code:
I was wondering if there is a way to enable autocomplete on imported Objects / Libraries (.dll) files?
I am using IBM 3270 and have imported all of the libraries and added them as references to my project, but I still don't get any alternatives.
Here is an example of the code and what I believe it should do:
' The Imports are already referenced to the project.
' I have added them here to visually display that I am using the libraries.
Imports AutConnListTypeLibrary
Imports AutConnMgrTypeLibrary
Imports AutOIATypeLibrary
Imports AutPSTypeLibrary
Imports AutSystemTypeLibrary
Public Class IBM3270
Public Shared autECLConnList As Object
autECLConnList = CreateObject("PCOMM.autECLConnList")
autECLConnList. ' <- I believe that I should get autocomplete words here, but I don't.
' Some of the alternatives that should pop up are:
' autECLConnList.Count
' autECLConnList.Refresh
End Class
Link to IBM Knowledge Center
EDIT: I have rewritten the code and the Autocomplete words appears, but I can't figure out how I can execute it now. Previously I used CreateObject("PCOMM.autECLConnList") to access the object.
Here is what I have:
Imports AutConnListTypeLibrary
Public Class IBM3270
Implements AutConnList
Default Public ReadOnly Property ConnInfo(Index As Object) As Object Implements IAutConnList.ConnInfo
Get
Throw New NotImplementedException()
End Get
End Property
Public ReadOnly Property Count As Integer Implements IAutConnList.Count
Get
Throw New NotImplementedException()
End Get
End Property
Public Sub Refresh() Implements IAutConnList.Refresh
Throw New NotImplementedException()
End Sub
Public Shared Sub Test() ' Here is where I am stuck.
Dim autECLConnList As AutConnList ' I believe I can't reference AutConnList. ("PCOMM.autECLConnList") should probably be added someplace.
autECLConnList.Refresh
End Sub
End Class

Related

How do I reference a Module in VB from a NuGet package

I've created my own private NuGet server and hosted two packages written in VB, one with a single public class and one with a Module containing some extension methods. When I reference the packages in my application, I am able to create a new instance of the class from the package, but I am unable to use any methods declared in the module. I know that modules need to be contained withing the namespace, so I have a feeling I may need to reference it somewhere to make use of it. Does anyone know what I need to do? Thanks.
I've currently got the following:
Namespace TestHelperNamespace
Public Class TestHelper
Public Sub DoSomething()
End Sub
End Class
Public Module TestModule
Public Sub StringSub(s As String)
End Sub
End Module
End Namespace
Import the Module's namespace in your code
Imports NugetModuleNamespace
Here's a MCVE
Imports Namespace2
Namespace Namespace1
Module Module1
Private Sub foo()
Dim a = 1.23#
Dim b = a.Square() ' doesn't work without Imports
End Sub
End Module
End Namespace
Namespace Namespace2
Module Module2
<System.Runtime.CompilerServices.Extension>
Public Function Square(value As Double) As Double
Return value ^ 2
End Function
End Module
End Namespace
This applies to Modules in separate files as well.

VB.NET Class with COM Interop, missing most properties when used from VBA (Access)

I have written a VB.NET class that has COM Interop enabled so it can be utilized in VBA - specifically, MS Access.
The class works fine in VB.NET.
With Accees, I can add the reference to it, instantiate the main object and set and return some properties.
But Access does not recognize anything relating to the sub-classes underneath the main class. VB.NET has no problem exposing these classes, but not VBA.
Is this simply a limitation of COM Interop and/or VBA?
Is there a work-around?
No you can’t get interop to generate the sub classes for you (to appear in VBA)
However, keep in mind that nested classes are really the same as non-nested. That sub class instance HAS to be initialized anyway. And there is nothing you can't do if the classes were to be separated. And you can well place many classes in one code module.
So this is purely a syntax preference you are looking for.
However, what you can do declare a pubic instance of any sub class in the main class (variables area as public).
Take this simple example.
Imports System.Runtime.InteropServices
<ClassInterface(ClassInterfaceType.AutoDual)>
Public Class Class1
Private m_Company As String = ""
Public Function MyHello()
MsgBox("Hello world")
End Function
Public Property Company As String
Get
Return m_Company
End Get
Set(value As String)
m_Company = value
End Set
End Property
<ClassInterface(ClassInterfaceType.AutoDual)>
Public Class Class2
Private m_FirstValue As Integer = 2
Public Property V1 As Integer
Get
Return m_FirstValue
End Get
Set(value As Integer)
m_FirstValue = value
End Set
End Property
Public Function MyTimes2() As Integer
Return m_FirstValue * 2
End Function
End Class
End Class
NOTE above the nested class “class2” in above.
Ok, so check the make com assembly visible = True, and for testing check the “register for com interop”
Compile the above, set the reference in Access. (Note how you don’t have to build a custom interface either!!!).
Now, in VBA you get this in intel-sense.
NOTE carefully how the sub class Class2 does not appear.
If you really want the intel-sense and sub class to appear, then to the above vb.net class, simple add this;
Public Class Class1
Private m_Company As String = ""
Public SClass2 As New Class2 <--- add this line to expose as public
Private m_Company As String = ""
.etc. etc. etc.
Now I put a “S” in from of the name – you unfortunately can’t use the same name as the nested class. (so either put something in front of the nested class, or something in front of the public instance of that class (that is what I did in above).
Now if we compile, then in VBA you get this:
Note the class2 DOES appear as a sub class
And if I hit a “dot” in VBA editor, then the sub class methods show like this:
So quite sure the above is the only way to get the sub-classes working with COM interop

ActiveX component can't create object when using .net class in vba

I am trying to use a custom class exported as a .tlb in vba. I have done the regasm stuff but I keep getting this error when I try to call a subroutine within the class:
Run-time error '429': ActiveX component can't create object
I've referenced the class in vba, I've built the class for 32bit and 64bit CPUs and nothing worked. Anyways, vba code:
Sub test()
Dim test As New Mail.Class1
test.test
End Sub
And the vb.net code:
Imports System.Runtime.InteropServices
Public Class Class1
Public Sub test()
MsgBox("hello")
End Sub
End Class
That class won't be exposed to COM. Simplest way to do this is to Add New Item and select COM Class. This generates a Class skeleton that looks like this:
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "e19c541f-8eda-4fdd-b030-abed31518344"
Public Const InterfaceId As String = "e2122f92-5752-4135-a416-4d499d022295"
Public Const EventsId As String = "6b03de7e-90d7-4227-90ec-9121c4ce1288"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
End Class
Also remember to check the "Make assembly COM Visible" in the Assembly Information dialog (Project properties>Application tab>Assembly Information)
Now when you compile this and call RegAsm, it should have an entry point for this class

VB.NET getting error: Class 'Application' must implement 'Sub InitializeComponent()'

I'm doing a VB.NET WPF application using VS2013, and I am just trying to find and use the right entry point.
I have read tons of answers on this, one saying something and the other saying the opposite. Mainly they say: the entry point of your project is the autogenerated main() you can find in your Application.g.vb. Yes, ok, very nice but...it is a generated file, not a good idea to modify it. So I searched the net on how to implement my own main() method, and the common answer I've found is:
Select Application.xaml and change its build action to "Page"
Create your own main method in Application.xaml.vb with this signature:
_
Public Shared Sub Main()
Dim app As Application = New Application()
app.InitializeComponent()
app.Run()
End Sub
Go to your project properties, untick "Enable applpication framework" and select Sub Main as startup for your application.
And so I have done but I continuously get this error:
Error 3 Class 'Application' must implement 'Sub InitializeComponent()' for interface 'System.Windows.Markup.IComponentConnector'.
this is the Application.g.i.vb file it generates:
#ExternalChecksum("..\..\Application.xaml","{406ea660-64cf-4c82-b6f0-42d48172a799}","DB788882721B2B27C90579D5FE2A0418")
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.42000
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict Off
Option Explicit On
Imports System
Imports System.Diagnostics
Imports System.Windows
Imports System.Windows.Automation
Imports System.Windows.Controls
Imports System.Windows.Controls.Primitives
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Ink
Imports System.Windows.Input
Imports System.Windows.Markup
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Media.Effects
Imports System.Windows.Media.Imaging
Imports System.Windows.Media.Media3D
Imports System.Windows.Media.TextFormatting
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Imports System.Windows.Shell
'''<summary>
'''Application
'''</summary>
<Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Public Class Application
Inherits System.Windows.Application
Implements System.Windows.Markup.IComponentConnector
Private _contentLoaded As Boolean
'''<summary>
'''InitializeComponent
'''</summary>
<System.Diagnostics.DebuggerNonUserCodeAttribute(), _
System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")> _
Public Sub InitializeComponent()
#ExternalSource("..\..\Application.xaml",4)
Me.StartupUri = New System.Uri("MainWindow.xaml", System.UriKind.Relative)
#End ExternalSource
If _contentLoaded Then
Return
End If
_contentLoaded = True
Dim resourceLocater As System.Uri = New System.Uri("/FatLink;component/application.xaml", System.UriKind.Relative)
#ExternalSource("..\..\Application.xaml",1)
System.Windows.Application.LoadComponent(Me, resourceLocater)
#End ExternalSource
End Sub
<System.Diagnostics.DebuggerNonUserCodeAttribute(), _
System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0"), _
System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never), _
System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes"), _
System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity"), _
System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")> _
Sub System_Windows_Markup_IComponentConnector_Connect(ByVal connectionId As Integer, ByVal target As Object) Implements System.Windows.Markup.IComponentConnector.Connect
Me._contentLoaded = True
End Sub
End Class
so...as Sub InitializeComponent() is there, why the hell do I keep getting this error?
**EDIT:**My Application.xaml.vb is just that:
Partial Public Class Application
<System.STAThreadAttribute(), _
System.Diagnostics.DebuggerNonUserCodeAttribute(), _
System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")> _
Public Shared Sub Main()
Dim app As Application = New Application()
app.InitializeComponent()
app.Run()
End Sub
End Class
I have managed to reproduce you problem:
Create a new WPF VB.NET application
Create the custom Main in the Application.xaml.vb file as from your post
In the project properties uncheck the Enable Application Framework (automatically the startup object becomes our Main sub)
Set for the Application.xaml file the Build Action property to Page
At this point, the line that call app.InitializeComponent() is underlined with a red squiggle to signify that the project cannot find the InitializeComponent method. If you try to compile at this point you get the mentioned error.
Final step:
In Application.xaml file remove the
StartupUri="MainWindow.xaml"
Now the squiggle disappears and the compilation ends correctly.
If you want to start you own main window you could change the Run line with
app.Run(New MainWindow())
If you get that error, you probably haven't stated that your app is to start with your Main() method. So:
"Go to your project settings and untick the Enable application framework checkbox (if it's ticked) and select Sub Main as the Startup object , then add your main-method to Application.xaml.vb (plus the logger and other stuff)."
When you have done that, VS won't create "its own" Main-method and will rather call the one you defined in Application.xaml.
Taken from: https://social.msdn.microsoft.com/Forums/vstudio/en-US/d7ef493f-27be-4f32-8ff4-a014078f572c/custom-systemwindowsapplication-in-vb-net?forum=wpf
Check also this: http://ugts.azurewebsites.net/data/UGTS/document/2/3/32.aspx

Bootstrapper class not found in Nito.AsyncEx

Please see the answer to the following question: Can't specify the 'async' modifier on the 'Main' method of a console app
I am trying to do this with a VB.NET program. I have added the package using NUGET and I have ensured that the Reference is added. Please see the code below:
Imports Nito.AsyncEx
Public Class ScheduledTasks
Private Shared Async Sub MainAsync(args As String())
Dim bs As New Bootstrapper()
Dim list As VariantType = Await bs.GetList()
End Sub
End Class
The error is: Type BootStrapper is not found. I have used Intellisense to look at the types contained in Nito.AsyncEx and Bootstapper is not there? How do I create an asynchronous main method using VB.NET?
Bootstrapper is not a part of AsyncEx. AsyncContext is:
Imports Nito.AsyncEx
Public Class Program
Private Shared Sub Main(args As String())
AsyncContext.Run(Function() MainAsync(args))
End Sub
Private Shared Function MainAsync(args As String()) As Task
...
End Function
End Class