Trying To Understand Classes And Objects ?
Jun 5, 2010
I've been trying to understand classes and objects. Yes, I'm thick headed and slow, but I made the decision to go to .Net and I am determined to improve my coding skills to be more efficient. I have spoken to Atma several times on the topic and read most of his posts concerning classes and objects, but still came away a little baffled (He's really advanced for me yet). I needed a simplistic analogy for a reference point to begin understanding. I was reading about OOP written by MikeJ in the following thread/post ...[URL] and it all started to become clear in this statement , but I would like some reassurance that I'm getting it ..."A car IS-A vehicle, while a dog HAS-A tail. The car would be an object declared as type Vehicle, while the dog would have a member that IS-A tail. However, Fido IS-A dog. The dog class is the base template for all dog objects, so when we declare Fido as a dog, Fido is an object. Since Fido IS-A dog, Fido HAS-A tail."
From this I have taken the following understanding...
Vehicle ... ' Class
Car ....... ' Object
Truck ... ' Object
Van ....... ' Object
And from that can I infer that this is true?
Dog ....... ' Class
Fido ... ' Object
Tail .. ' Member of Fido
So to apply this to a program I wrote recently that tracks Generator service...
Generator ' Would be the class
Brand X ' Would be an object
Spark Plug ' Would be a member
Gas Tank ' Would be a member
Brand Y ' Would be an object
Brand Z ' Would be an object
This statement also helped ...
""Class" and "object" are sometimes used interchangeably. However, classes describe the structure of objects, while objects are instances of classes. Each instance is an exact copy of its base class. Because an object is an "instance" of a class, the act of creating an object is called instantiation. To describe it better, a class is a blueprint, and an object is a building based on that blueprint". I can understand this (I think) and it refers to a basic template such as ..."Generator" (my class or blueprint or template) Generators have an engine, powerplant, fuel tank, etc. These are basic requirements to be a generator. (Template or Blueprint) They can differ by Brand of engine, Size of powerplant, and type of fuel used. (Based on template or blueprint) Do I have it down now? MikeJ also made this statement ..."you can't access certain types of class members from outside of the class itself." From this I assume you would need to assign a Global variable the value of the class member if you needed to use it outside of the class?
View 17 Replies
ADVERTISEMENT
Jan 3, 2012
I have a nested class, let's call it class1 and it has class2 inside it; VB.Net eg:[code]
1) How can I define X number of Class2 objects[let's call it: Node(x) array]** with NEW() subroutine called?' this raises error: dim cls2(n) as new class2 end sub.
2) How can I return actual number of Node() array? [code]Outside my class in main project I define cls1 object:[code]Now an array of class2 is created inside cls1.
3) Now,How can I access All of them[node(x) array which is created inside cls1] with all properties and methods available?
I remember I wrote a ProcessManager class with this functionality in .net 2003, nearly 4 years age, I don't have the code now.
View 1 Replies
Aug 29, 2010
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...]
View 1 Replies
Sep 7, 2010
In ASP.NET I have a form that has a Textbox named txtOutput and a button. In the main file.aspx.vb I can call a function from the button handler and in that function I can have [code]I have a bunch of functions in several other classes. For instance I have a class named AbleCommerce that does some database functions. These functions are called from my main class. In those functions, however, I have no visibility of txtOutput.All of my classes are, unfortunately, in the default namespace which I understand is not optimal but didn't seem to impact this issue.
View 2 Replies
Dec 28, 2011
suppose I have a collection of objects of different classes (like controls in a form), and all of their classes have a MyMethod extension method. How do I have the appropriatemethod be called for each object, depending on its type?or example,
For Each ctrl In Me.Controls
'call ctrl real type's MyMethod
Next
[code]....
View 6 Replies
Apr 10, 2011
1) Add a Private variable named _area2) Associate the _area variable with a Property procedure called Area3) Change the CalculateArea method to a Sub procedure. The method should calculate the area and then assign the result to the _area variable.4) Include a parameterized constructor in the class. The constructor should accept one argument: the side measurement. After using the Public property to initialize the Private variable, the constructor should automatically call the CalculateArea method.At this point I believe I've completed the first 2 steps for the Square method, but I'm not sure where to go from therHere is my code for the Square class and the Main Form, in tha order:
Public Class Square
Private _side As Integer
Private _area As Integer
[code].....
View 3 Replies
Mar 5, 2010
Pursuing the Microsoft Certified Professional Developer Certification and working through the training kit.I've programmed for a while and mainly used classes as my objects.The training certification book I'm working through has a section on structures. they look very similiar to classes so my question is: why use them? Do they offer something that creating a class doesn't? What's the difference between structures and classes?
View 8 Replies
Oct 14, 2009
relation between Classes and Objects with an example.Md. Marufuzzaman
View 7 Replies
Sep 25, 2011
I have a webservice that is wrapped up by a data access object and is accessed by many different UI controls.
The proxy objects look something like this:
Public Class WebProxyObject1
' Common properties, there are about 10 of these
Public Name As String
[Code]....
View 1 Replies
Aug 27, 2010
I'm wondering on how you would go abouts instantiating a class that contains other complex objects. for example an Payment Class which has Date,Time, etc.. and it also holds a reference to a paymethod object which has id,Type,Description etc.. How do you instantiate the payment class with all the other objects without one or the other failing, how do you create the payment class which doesn
View 4 Replies
May 9, 2009
I have one class with <Serialize> attribute called Tree. And Tree class has an arraylist of TreeNode classes. Is it possible to use Soap to convert the Tree class and arraylist of TreeNode classes to one xml file or binary file? If it is possible, do i need to use <Serialize> attribute on TreeNode classes too? If not, what should i do then?
View 3 Replies
Feb 26, 2010
I have a project where a email is sent when the user clicks send on the web page, however the content of the email will change depending on what is inputted by the user. I have added classes to my project so that depending what is selected by the user different classes are selected and as such different emails then sent from the project.
[Code]...
View 9 Replies
Dec 26, 2010
I have a Clients master object and then a number of child objects whose exact number is not known in advance such as Client-Contacts, Client-Payments etc, all of which have a one-to-many relationship with the Client master object.How do I define classes for such a scenario? Do I for instance create the master Clients class and can then I create an array of class somehow for child objects?
View 2 Replies
Jul 2, 2009
I have a VB.NET web app that is about 2000 lines of code, contains about 20 different subroutines, and about 50 different functions.Is there an easy way to "rewrite" this to take advantage of classes and objects?
View 5 Replies
May 18, 2010
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 Replies
Jun 26, 2010
I want to know what are classes , objects , a namespace , subroutines,functions,methods,properties and differemce betweem byval and byref in your words.
View 18 Replies
Jan 23, 2012
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 Replies
Oct 18, 2010
I have been given an old dll and the assignment of accessing it through C# .NET 3.5. I believe the dll was originally built with VB6, but am not positive. There is no documentation or source for the dll aside from an example for how to use the it in VB6. I have been able to succesfully access it through VB.NET 3.5. Example code for accessing looks like this:
myLib = CreateObject("MyLib.api")
myConnection = myLib.CreateObject("NameOfConnectionObject")
myConnection.do_something("abc")
There are several different objects that are created from the library and all of those objects have different methods. I tried using different dll reading tools, but all the export methods show up as garbage. I also tried importing the dll in visual studio, but I get an error stating the dll is not accessible and/or not a COM object or assembly. So, I only know about the methods from the old documentation which is sparse. how to access in C# and/or find out more about this mystery dll?
View 2 Replies
Apr 24, 2012
i cant understand what constants are.
View 3 Replies
Dec 4, 2011
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim d As Integer
Dim price(20) As Double ' Adjusted close price
[code]....
What is the for ... next loops in the second subroutine doing? What is the sim() array meaning?
View 3 Replies
Feb 1, 2009
I have a modem that I've been trying to communicate with only to discover this....went to the modem properties and queried the modem.....
AT+FCLASS = 0,1,8
AT#CLASS = ? COMMAND NOT SUPPORTED
(And I had been trying to use AT#CLASS = 8 all day).So, what does this mean?That the modem is automatically in voice mode (or will automatically choose it's own mode) and forcing it isn't necessary?Still no luck with the connection response messages either -- RING, etc.All I can do is make a call and the called number will appear in a textbox.
View 14 Replies
Jun 13, 2012
How 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.
View 23 Replies
Feb 18, 2011
I am getting a build error. If I try to build again after getting this error, it will build just fine.
View 9 Replies
Jan 4, 2011
[code] I cannot seem to understand why left & lan isn't working in the vb 2008 edition
View 2 Replies
Jun 6, 2011
how to understand a msakeditbox in null?
View 4 Replies
Nov 21, 2009
I'm just getting back into VB and was never a pro. The last environment I was in, briefly, was VB6 but spent a good amount of time coding in early VB's back to QB.I'm trying to read RSS feeds and found a nice demo reader but now I want to understand the code I'm seeing:[code]
1. Why does the demo create a new XML to read through an existing XML or is this all in memory as I can't find an actually file? Is this even needed as what I want to do is read the RSS feed, grab some info from it (Source, Title of each story, Date stamp, author and the story text) and then process that in various ways (not actually view it... I want to e-mail specific stories directly to me that fit my search criteria). Or is this just opening the XML out on the web? That would explain why sending it "test" gives me an error saying it can't find "test" in the bin folder as without an HTTP address it goes local.
2. doc.load... what check can I perform here to be certain that the data entered by the user is actually a valid feed? It should, for example, have a first line header that is reliable but is that the best method?
3. Where or how are the elements stored that I can then refer back to pull the data out I want?
4. I don't understand how this part works: navigator.Select("/rss/channel/item/title") Can someone shed some lite on the 4 pieces at the end?
5. I'm assuming the clean-up isn't really needed for e-mail but I didn't remove it as it doesn't seem to harm anything.
View 2 Replies
Feb 20, 2011
I have Visual Basic 2010 and also bought a book to study and practice problems. I know how to add controls and assign properties but get confused with the coding part.understand this somewhat?
Here is one problem I am working on-
Write a program to make change for an amount of money from 0-99 cents input by the user. the output of the program should show the number of coins from each denomination used to make change.
Now I know what controls i need on the windows form but I am sorta lost on the coding to make this program work.
View 3 Replies
May 25, 2010
At the following cmd.ExecuteNonQuery() line, I get the following error message: [code] I have followed the example at page [code] as closely as possible, but it does not work.Additionally, I am not sure of the syntax for the length (64) that I have for the BigInt or if it should even have a length.All of the examples that I have found in MSDN uses only parameters with character rather than numberic type. [code]
View 6 Replies
Oct 24, 2009
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]....
View 5 Replies
Aug 5, 2011
"write sub prototype for a procedure whcih is named my data and has first parameter as a string which can be changed and second parameter of an integer which cannot be change"
View 3 Replies