VB in Visual Studio Adding a class module will it have access for the form.vb I've built? - vb.net

Hello thanks for reading my question, I've build a user form with controls to control equipment via RS232 and USB. I've also added a separate class module "class.vb" to hold miscellaneous functions like writing to an ini file.
When I'm in the code section of the Form.vb and I type txb for text boxes that I have in the form visual studio pops up a nice list of all things in the form that start with txb.
However, when I do the same thing in my class.vb it does not do this and even if I type the whole thing such as txbModulation and then add the dot after it does not come up with the list of properties.
Does the class.vb have access to Form1.vb controls?

When I'm in the code section of the Form.vb and I type txb for text
boxes that I have in the form visual studio pops up a nice list of all
things in the form that start with txb.
This is because when you start typing a variable name, Visual Studio starts looking for a match. It looks in block scope first (a for or while loop maybe), then at local (function/sub) scope, and finally at class level (a form is a class). It will also look for any matches in Modules if you have them. See Scope in Visual Basic for more info.
Since the Form and your INI Class are different, they cannot see each other unless you pass references or somehow pass values via parameters to subs/functions.

Related

VSTO - visual studio code structuring

I'm new to .NET from an extensive VBA background. I'm building an Excel add-in and have been struggling to find any guidance on line about control of code structure and layout in visual studio.
Comparing to the VBA environment, what I want to do is have different modules for the different components (e.g. one module with all the calculation subs, one module with all the formatting subs, one module with all the custom charting subs, etc.) but cannot find any guidance on how to set this up.
I've put the skeleton of the ribbon tab in, with some icons etc. and VS has automatically created tabs as follows:
Ribbon1.Designer.vb, which appears to house setup code - adding groups and buttons etc.
Ribbon1.vb, which now contains a few subs I've written in 'Public Class Ribbon 1'. This is the bit I want to "modularise".
I have tried creating another public class which didn't work, and a few other things. I also saw mention of "sub classes" though could not find any instructions/examples and couldn't get this going myself (or if I need to specify inheritance from one to another?).
From a user friendliness perspective for me, one tab in VS per category of subs would be the ideal but I'm amateur so definitely open to learning how to structure it all properly. Yes, I wish I had software engineering training!
Screenshot

Finding the definition of an object in a VB web-user-control

I have an ascx.vb file with a function that starts off like this:
Sub buildlist()
repcaldatelist.Visible = True
...
End Sub
I'm just trying to figure out what repcaldatelist is. When I use VS's "Go To Definition", it gives me a popup saying "The definition of the object is hidden." Using "Go To Implementation" does nothing.
I see the corresponding .ascx file with this line:
<asp:repeater ID="repcaldatelist" runat="server">
and I see how repcaldatelist is databound to it, so that page can display its data.
But what I'm trying to understand is, where does repcaldatelist come from? I want to see where it's initialized and what its type is.
I know this is probably really basic but I'm new to VB / Web User Controls and haven't had any luck searching for this online thus far. Please enlighten me.
ID="repcaldatelist" means that's the ID of the Repeater control. So in your .vb file, repcaldatelist is an object of type Repeater - the ID in the ascx/html translates into a variable name in the VB. If you hover over the variable in the .vb file in Visual Studio it should tell you the type as well.
Go To Definition / Implementation don't work because the Repeater class is part of the .NET framework, and it's closed-source - just a DLL on your machine. Therefore there's no source code or definition you can view. You just have access to its public API as defined by the docs (and should be available in intellisense as well).

How to find a form from many forms in vb6 on a existing project

I am working on a old project of vb6 which has hundreds if forms. I am able to run the application and have to fix a runtime error in a form which pop up. I don't know the name of the form and only have visual reference. I tried using debug but It has continues SQL statements running in a loop. Any advice is appreciated.
Thanks.
Search the code for the form caption, or the labels of controls on the form, using visual studio's "find in files" or simlar function of your favourite editor.
If the caption is set in the form design, this will take you to the .frm file the form is stored in. You can open this in Notepad or another editor to get the name of the class (which is usually the same as the filename).
If the caption is set in code, you can place a breakpoint on that line. Again, this will lead you to the code which instantiates the form.

Upgrading VB6 to VB.NET - Usercontrol not available because I could not compile the project

I have upgrade a VB6 project with the upgrade wizard to VB.NET.
I think I am in a vicious circle now:
There is one user control in my main form that is accessed from many other forms.
The IDE tells me that it shows the maximum amount of errors (102), and those shown are all like:
ucPage is not a member of prjMyProject.frmMain
ucPage is not a member of prjMyProject.frmMain
ucPage is not a member of prjMyProject.frmMain
EB1 is not a member of prjMyProject.frmMain
EB1 is not a member of prjMyProject.frmMain
I need to replace EB1 with a standard control, but I can not load the frmMain in the designer because the IDE is still mocking about the missing ucPage control on the form.
And the user control "ucPage" is not available in the toolbox because I have not been able to compile the project yet, so I can not even put it on my form.
This is a vicious circle, I think.
Does anybody have any suggestions on how to resolve it?
If you are converting VB6 projects to VB.NET (especially with UI), be prepared to encounter a lot of errors, because many VB6 tricks are not compatible with VB.NET. There is a way to manually edit form designer code in VB.NET:
Solution Explorer - Show All Files. Notice your form file in Solution Explorer can now be expanded.
Expand the form in question, and double-click Designer.vb file.
If designer file is not there, chances are designer code is sitting in the vb file under #Region "Form Designer generated code", usually on the very top.

VB.NET UserControl

I am trying to create a UserControl in VB.net, under VS2010. I have the code for the UserControl and I would like to add it to a form. My problem is that, according to every book and forum I have seen, after I build the UserControl, it should show up in the Toolbox. It doesn't. I even downloaded code from a book, the code executes perfectly, but their TrafficLight control doesn't go in the Toolbox (even though the book says it should - and that the only way to set its properties and to add it to the form is through the Control properties). I have tried to add the control to the form manually, by declaring it
Dim myObj As New SomeClass.SomeControl
and in the Designer.vb, identical with the buttons on the form:
Friend WithEvents myObj As SomeClass.SomeControl
With both, I get an error saying
'myObj' is already declared as 'Friend WithEvents myObj As SomeControl' in this class.
And either way, I get an error when I try to look at the design:
Could not find type 'SomeClass.SomeControl'. Please make sure that the assembly that contains this type is referenced. If this type is part of your development project, make sure the project has been successfully built using settings for your current platform or AnyCPU.
The control by itself builds and shows up in design view (not in the Toolbox though, even though it Imports System.ComponentModel and Inherits System.Windows.Forms.UserControl and... what else ? I tried to build it in a separate project, to see if I creating a separate dll will make a difference, though I really want it in the same project.
Please help ! (BTW I have reinstalled VS2010 and it did no good)
Thank you.
Look in Tools / Options / Windows Forms Designer and set "AutoToolboxPopulate" to True (but note that this can take a noticeable amount of time if you haver many (i.e. dozens) of user controls.