Make Own Classes In .net?
Jul 22, 2010I've often wondered why would you need to make your own classes in vb.net? What purpose can they serve a typical application that cannot be already down without creating them?
View 2 RepliesI've often wondered why would you need to make your own classes in vb.net? What purpose can they serve a typical application that cannot be already down without creating them?
View 2 RepliesSo i learned about classes today and i am totally confused about them. How exactly do they make programming life eaiser? I though Functions and Sub Procedures were making my programming life easier
View 4 RepliesI'm trying to create a base interface for a class of mine that uses generics. However, I cannot figure out how to declare a property of the interface when its type won't be defined until the class is initialized.
To clarify, consider List(of T), which according to msdn, implements IList (among other things). Note that IList is not the same as its generic counterpart IList(Of T). So that mean any List(of T) can be converted to IList, which simply returns an object for its items. That's what I want to do with MyClass(of T), be able to cast it as IMyClass regardless of what T is.
But when I try such as:
Interface IMyClass
Prop A as Object
Class MyClass(of T) Implements IMyClass
Prop A as T Implements IMyClass.A
I get a signature error for the last line, even though object is broader than T. What am I doing wrong, or how exactly did Microsoft manage to make List(of T) implement IList?
This probably sounds daft, but im struggling to get to grips with Classes/Modules/arrays and objects, as well as there uses and what they are, and yes im still coding some how i hear you cry.The reason i ask is because Ive got a load of Dim's in my program that are the same giving locations of files and folders and wondered can they be used as a module that i can alter after the program is built, incase of folder locations being wrong or moved, manually correct after install.
View 1 RepliesI am working on a bitmap class module in Visual Basic 2010 that has an option to create a graphic grid on the bitmap.
[code]...
We are using T4 to generate our .aspx and .vb files. Everything works well - but we often have to customize behavior on the pages. However, we also occasionally have to regenerate pages - which has the potential to wipe out work which would otherwise still be valid. I would like a setup like this:
Default.aspx 'which would contain the controls
Default.aspx.vb 'which would bind, load and save data
Default.behaviour.vb '(or something like that) - which would store the behavior
With both the pages being able to reference the controls. Is that at all possible? [Code]
I was just wondering how you can make classes import into your main Form.vb
Let's say I make a class with the following.
Public Class OtherStuff
Public Sub HideMe()
Form1.Hide()
[Code]....
How could I make the Form1.vb include the things that are in OtherStuff.vb.
All of the solutions that I have tried come up with the same error. Reference to a non-shared member requires an object reference.
I have written multiple programs in the past that deal with cad data. Points, lines, arcs, etc. For each program I ended up creating slightly different versions of some really base classes like a class that defines a point:
<Serializable()> Public Class Point
Public x As Double = 0
Public y As Double = 0
Public z As Double = 0
End Class
My question is how would I use that class in such a way that it could be in a namespace and imported into any future project that I write?
I have two classes, one nested in the other. [code]Neither "Name" or "ID" are unique between operations and records.I wish to construct a dictionary using LINQ = Dictionary(Of String, Of List(Of Integer), whereby the keys are uniqe examples of Names in my collection and the values are the collective set of distinct IDs that are associated with those names.
View 2 RepliesHow can I structure my classes so that the user interfaces though a single class while the supporting classes are hidden from their view? I think its best understood in an example:
Public Class MyInterface
Public Economic as EconomicClass
Public Sub New()
MyBase.New()
[code].....
So you might ask why am I even separating them? It's strictly for others who will be working with this interface. I need to funnel them though a logical structure:
interface.Economic.MyMethod
interface.Currency.MyMethod
etc
This way everything is already handled for them in the background and they only need to run the method they need. I don't know if I can have it both ways in VB.NET.
Here is some example code of what I mean:
vb
Public Class Form1
Private Sub Button1_Click(ByVal sender as Object, e as systemEventArgs) Handles Button1.Click
[Code]....
I m trying to raise Click event of Textbox explictly but I m getting "Derived classes cannot raise base classes" error.[code]....
View 1 Replieswith one form and 1 class it is simple.but i have now 4 forms and 4 classfiles with 8 classes.i only need 1 commandlist with 20 commands i made them classes form 4 makes a private instance of the commandlist with the dim statement so i cant use it througout the projekt if i chance it in public , i get the reaction of visual studio i must replace it with dim (private) i read it is better to make instances ( dynamically)then to publicly share your classes(static)but i want my instances to be used by all forms and classes.
View 3 Repliesso far i got
code
For Each item As Reflection.FieldInfo In GetType(NameSpace.ClassWithNestedClasses).GetFields
rtfAppend(item.Name & ":" & Tab & item.GetValue(Me))
Next
For Each item As Reflection.PropertyInfo In GetType(NameSpace.ClassWithNestedClasses).GetProperties()
[code]...
which gets me the simple string vars and properties of my top class, but how can i apply this to loop through all sub classes and get there vars and props?
Searching the internet finds no less than 700 different ways and opinions to accomplish what I'm trying to do, and I would just like to know the simplest, most bullet-proof way possible.
[Code]...
I simply want to extract the string "bar," which is inside <hostName></hostName>I can do this easily enough with simple string functions, but I'd like to do it with one of the .NET XML classes/methods.
I have three classes Employee, Manager and Salesman. Manager and Salesman classes inherits Employee class.
Employee :
Public MustInherit Class Employee
' Field data.
Protected empName As String
Protected empID As Integer
Protected currPay As Single
[CODE]...
Manager :
Public Class Manager
Inherits Employee
[CODE]...
Salesman :
Public Class Salesman
Inherits Employee
[CODE]...
Now I have created a object of salesman and manager using the following code:
Dim objSalesMan as Employee=new Salesman("xyz",1,2000,5000)
Dim objManager as Employee=new Manager("abx",2,5000,"production")
Is this a good programming pratice or should I use:
Dim objSalesMan as new Salesman("xyz",1,2000,5000)
Dim objManager as new Manager("abx",2,5000,"production")
I find that I write a lot of code within my classes to keep properties in sync with each other. I've read about Events in Classes, but have not been able to wrap my head around how to make them work for what I'm looking for.For example, in this one I always want to keep myColor up to date with any change whatsoever in any or all of the Red, Green or Blue properties.
Class myColors
Private Property Red As Byte
Private Property Green As Byte
[code]....
If one or more of those changes, I want myColor to be updated. Easy enough as above, but is there a way to work with events that would automatically do this so I don't have to put myColor = Color.FromArgb(Red, Green, Blue) in every sub routine?
How can I create a namespace and classes in it, then save it, and reuse the namespace in other projects? Do I have to click on Create Class Library in Visual Studio?
View 2 RepliesI am new to .net and was wondering if there are any projects which have sets of vb.net classes online which i can use. For example we have Flourish — PHP Unframework which has lots of php classes therefore a programmer doesn't not to replicate code on each project. Is there a asp.net (vb) resource website or any open source project which has built in vb.net functions.
View 3 Repliescreated class TestA. There is Sub mysub defined inside it. Now I want to use this Sub in other class. So far I did like this:
Dim oTestA As New TestA
Dim dblA As Double
dblA = oTestA.mysub
[code].....
I have a slew of sub routines that I need to use in my software because each website that I will be accessing don't all use the same methods.....go here...click that...go here...click that...etc etc
So I've divided them into sub routines and call them when I need them but the coding is getting so long that it's becoming confusing to keep up with each sub.
Is it possible to place the sub routines into an independent file like a class and then call them from the file when I need them so I can free up some space to code?
The 1st part of the code required me to write a class definition for a class(Worker). The class should include Private variables and Property procedures for a worker object's name and salary.
The salary may contain a decimal place. The class should also contain two constructors:a default and a parameterized.
The second part for the code indicates that I need add a method named GetNewSalary to the Worker class.The method should calculate a Worker objects new salary, which is based on a raise percentage provided by the application using the object.
Before calculating the new salary, the method should verify that the raise percentage is greater than or equal to zero. If the raise percentage is less than zero the method should assign the number zero as the new salary
There are three text boxes which allows the user to enter the employees name current salary and raise percentage....the calculate button will display the new salary in the new salary label box...so far here is what I have for the worker class.
The Class for the code had to be written from scratch. Can you please look over the class code and see if I need to chang anything....that will allow the program to run.[code...]
'A way to connect to SQL with VB.Net using Classes
'This must be a class on its own
Imports System
Imports System.IO
[code].....
How can I add c# classes to my vb project. I am using vb .net express 2008
View 1 RepliesI am trying to get to grips with Classes and how to use them "efficiently", So bearing this in mind I decided to create a small class driven application.I am struggling to understand how I can "use" this new instance of this user somewhere else.
Test Data was
Name : Joe
username : JoeBloggs
Password : JoesPassword
[code].....
Now this works and updates the listbox with the new instance of the user but how can I use that instance from the listBox control to retrieve that users details?
As easily as possible? How to parse and create XML easily?
View 3 Replieshow to write classes. I have been searching and I understand classes a little. What I am confused on is how to write a class that contains more than 1 bit of information. How would I write a class that contains someone First Name, Last Name, Age, Address, City and State they live in. For instance all the information in the class can be retreived if I enter the person last name. And the class has to have more than 1 person infomation in it.
View 8 RepliesIDE: VS2010 Framework.net: 4.0 I created a c# dll project under Visual Studio 2010, with several public classes, and I would like to use its classes inside another dll project, but written in vb.net.
In the vb.net dll project, I referenced the built c# dll, but impossible to import the c# classes. The namespace of the c# dll is even not recognized.
What must I do to see my c# classes? If this is possible.
[Code]...
How do I integrate C++ into Visual Basic applications made in Visual Studio?
View 4 RepliesI am trying to do is get interoperability between my "mainwindow" and a class. As far as I know the way to do this is to create an instance of the class (in "mainwindow") for example and then use that instance to call the functions etc... This works. However I want to allow the class to call functions in the "mainwindow" The moment I declare the instance on the class as well it goes into an endless loop.
View 4 Replies