Can some one please tell me what I'm doing wrong. I'm trying to create
a class called Dog, but Visual Basic tells me that I can't enter
Wolf.age....why is this?
Public Class Form1
Public Class DOG
Dim COLOUR As String
Dim AGE As Integer
Dim NAME As String
End Class
Public Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim WOLF As New DOG
WOLF.AGE = 10
End Sub
End Class
Regards Brian 25 1489
Public Class Form1
Public Class DOG
Dim COLOUR As String
Dim AGE As Integer
Dim NAME As String
End Class
Public Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim WOLF As New DOG
WOLF.AGE = 10
End Sub
End Class
Regards Brian
Your "Dim" isn't public by default, try this instead:
Public COLOUR As String
Public AGE As Integer
Public NAME As String
Because the property variables aren't visible. Declare them with the
public keyword instead of dim (which is private by default). i.e. The
following should work just fine.
Public Class Form1
Public Class DOG
Public COLOUR As String
Public AGE As Integer
Public NAME As String
End Class
Public Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim WOLF As New DOG
WOLF.AGE = 10
End Sub
End Class
Brian wrote:
Can some one please tell me what I'm doing wrong. I'm trying to create
a class called Dog, but Visual Basic tells me that I can't enter
Wolf.age....why is this?
Public Class Form1
Public Class DOG
Dim COLOUR As String
Dim AGE As Integer
Dim NAME As String
End Class
Public Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim WOLF As New DOG
WOLF.AGE = 10
End Sub
End Class
Regards Brian
Brian,
While it may work, it's ugly as sin. You should separate your DOG class
out into a different file. Also, instead of using fields publicly you should
make them private and provide public properties instead.
-Boo
Because the property variables aren't visible. Declare them with the
public keyword instead of dim (which is private by default). i.e. The
following should work just fine.
Public Class Form1
Public Class DOG
Public COLOUR As String
Public AGE As Integer
Public NAME As String
End Class
Public Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim WOLF As New DOG
WOLF.AGE = 10
End Sub
End Class
Brian wrote:
>Can some one please tell me what I'm doing wrong. I'm trying to create a class called Dog, but Visual Basic tells me that I can't enter Wolf.age....why is this?
Public Class Form1 Public Class DOG Dim COLOUR As String Dim AGE As Integer Dim NAME As String End Class
Public Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventAr gs) Handles Button1.Click Dim WOLF As New DOG WOLF.AGE = 10 End Sub End Class Regards Brian
"Robinson" <it************ *****@nowmyinbo xisfull.comwrot e in news:eeoj9j
$j************* @news.demon.co. uk:
Your "Dim" isn't public by default, try this instead:
Public COLOUR As String
Public AGE As Integer
Public NAME As String
Even better declare the variables as properties : )
Why separate the dog class to a different file...moving it to after the end
of the form class should work also.
Why use a private variable then a property to read/write it if no special
actions are needed for the read and write?
--
Dennis in Houston
"GhostInAK" wrote:
Brian,
While it may work, it's ugly as sin. You should separate your DOG class
out into a different file. Also, instead of using fields publicly you should
make them private and provide public properties instead.
-Boo
Because the property variables aren't visible. Declare them with the
public keyword instead of dim (which is private by default). i.e. The
following should work just fine.
Public Class Form1
Public Class DOG
Public COLOUR As String
Public AGE As Integer
Public NAME As String
End Class
Public Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim WOLF As New DOG
WOLF.AGE = 10
End Sub
End Class
Brian wrote:
Can some one please tell me what I'm doing wrong. I'm trying to
create a class called Dog, but Visual Basic tells me that I can't
enter Wolf.age....why is this?
Public Class Form1
Public Class DOG
Dim COLOUR As String
Dim AGE As Integer
Dim NAME As String
End Class
Public Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim WOLF As New DOG
WOLF.AGE = 10
End Sub
End Class
Regards Brian
Why use a private variable then a property to read/write it if no special
actions are needed for the read and write?
The dog class isn't a real good example, but normally you want more
control over the property (validation for example). Just like Option
Strict On isn't always needed (and requires more code) using properties
instead of variables is just good programming practice. IMHO it
improves the readablity of the code and makes it much much easier to
update and/or modify.
Why separate the dog class to a different file...moving it to after the end
of the form class should work also.
Again, this is not a good example but moving it to a different file is
mainly for code reuse (OOP). If this was a more "advanced" class that
would be used in multiple solutions, being in the form's class file
wouldn't be a good idea. You would have to add an unneeded and unwanted
class (the form class) just to get to the advanced class. In my opinion
you shouldn't group unrelated classes in the same file.
Pretty much the suggestions were mainly to teach someone new to vb
classes good programming practices, not to say that what he had was
wrong.
Hope that clarifies some things,
Seth Rowe
Dennis wrote:
Why separate the dog class to a different file...moving it to after the end
of the form class should work also.
Why use a private variable then a property to read/write it if no special
actions are needed for the read and write?
--
Dennis in Houston
"GhostInAK" wrote:
Brian,
While it may work, it's ugly as sin. You should separate your DOG class
out into a different file. Also, instead of using fields publicly you should
make them private and provide public properties instead.
-Boo
Because the property variables aren't visible. Declare them with the
public keyword instead of dim (which is private by default). i.e. The
following should work just fine.
>
Public Class Form1
Public Class DOG
Public COLOUR As String
Public AGE As Integer
Public NAME As String
End Class
>
Public Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim WOLF As New DOG
WOLF.AGE = 10
End Sub
End Class
Brian wrote:
>
>Can some one please tell me what I'm doing wrong. I'm trying to
>create a class called Dog, but Visual Basic tells me that I can't
>enter Wolf.age....why is this?
>>
>Public Class Form1
>Public Class DOG
>Dim COLOUR As String
>Dim AGE As Integer
>Dim NAME As String
>End Class
>>
>Public Sub Button1_Click(B yVal sender As System.Object, ByVal e As
>System.EventAr gs) Handles Button1.Click
>Dim WOLF As New DOG
>WOLF.AGE = 10
>End Sub
>End Class
>Regards Brian
>>
Yeah...
Public members are baaaaaaaaaaaaaa aaaaaaaaaaaaaaa d.
Think encapsulation.
If I ever found one of my coders doing Public x As Integer in a class I
would force them to clean the bathrooms for a week.
"Spam Catcher" <sp**********@r ogers.comwrote in message
news:Xn******** *************** ***********@127 .0.0.1...
"Robinson" <it************ *****@nowmyinbo xisfull.comwrot e in news:eeoj9j
$j************* @news.demon.co. uk:
>Your "Dim" isn't public by default, try this instead:
Public COLOUR As String Public AGE As Integer Public NAME As String
Even better declare the variables as properties : )
Spam Catcher <sp**********@r ogers.comwrote:
>"Robinson" <it************ *****@nowmyinbo xisfull.comwrot e in news:eeoj9j $j************ *@news.demon.co .uk:
>Your "Dim" isn't public by default, try this instead:
Public COLOUR As String Public AGE As Integer Public NAME As String
Even better declare the variables as properties : )
Can you give me an example using my DOG Class please.
I'm new to this side of programming so I'm not certain what you mean
by declaring the variables as properties.
Regards Brian
Thanks for all your repies.
If someone could give me easy to follow examples of using Classes in
Visual Basic then that would be helpful.
Perhaps a web address the has code for a VB program that I could
download or if you have code that could be ziped up and sent to me by
e-mail for me to study then this would be helpful to learn more abolut
how to use classes in VB program code thanks.
Regards Brian
Brian <bc****@es.co.n zwrote:
>Can some one please tell me what I'm doing wrong. I'm trying to create a class called Dog, but Visual Basic tells me that I can't enter Wolf.age....wh y is this?
Public Class Form1
Public Class DOG
Dim COLOUR As String
Dim AGE As Integer
Dim NAME As String
End Class
Public Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventAr gs) Handles Button1.Click
Dim WOLF As New DOG
WOLF.AGE = 10
End Sub End Class
Regards Brian
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bob Rock |
last post by:
Hello,
in the last few days I've made my first few attempts at creating mixed C++
managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is
visible in those assemblies from a managed point-of-view I've noticed that:
1) for each managed and unmanaged C function (not C++ classes) I get a
public managed static method (defined on a 'Global Functions' class) in the
generated assembly with an export name of the form...
|
by: Jack |
last post by:
Hello
I have a library of calculationally intensive classes that is used both by a
GUI based authoring application and by a simpler non-interactive rendering
application. Both of these applications need to serialise the classes
to/from the same files but only the GUI app needs the full range of class
methods.
Now, the rendering app needs to be ported to multiple OS's but the GUI
doesn't. In order to reduce the time/cost of porting I'd...
|
by: Aguilar, James |
last post by:
I know that one can define an essentially unlimited number of classes in a
file. And one can declare just as many in a header file. However, the
question I have is, should I?
Suppose that, to use the common example, I have a situation where I am
implementing many types of Shapes. My current way of thinking is, well,
since they are all the same type, let's just put them all in the same file.
The include file would be "shapes.h" and it...
|
by: Langy |
last post by:
Hello
I'm fairly new to C++ but have programmed several other languages and
found most of c++ fairly easy (so far!).
I've come to a tutorial on classes, could someone please tell me why
you would need to use a class?
Perhaps you could also give an example on when it might be used rather
than an alternative method.
|
by: john townsley |
last post by:
do people prefer to design classes for the particular job or for a rangle of
tasks they might encounter now and in the future.
i am doing some simple win32 apps and picking classes is simple, but
understanding others peoples logic isnt (that doesnt mean they are wrong).
i prefer designing classes for the currect job and making tangible 'things'
classes , not overdoing it with loads of classes or inheritance..
it seems easier to make...
| |
by: joye |
last post by:
Hello,
My question is how to use C# to call the existing libraries containing
unmanaged C++ classes directly, but not use C# or managed C++ wrappers
unmanaged C++ classes?
Does anyone know how to do that?
Thanks.
Tsung-Yu
|
by: Edward Diener |
last post by:
Is the packing alignment of __nogc classes stored as part of the assembly ?
I think it must as the compiler, when referencing the assembly, could not
know how the original data is packed otherwise. Yet, in my understanding,
attributes are only __gc and __value class specific and do not apply to
__nogc classes. Is this correct ? If so, how is the packing alignment of
__nogc classes stored ?
|
by: ivan.leben |
last post by:
I want to write a Mesh class using half-edges. This class uses three
other classes: Vertex, HalfEdge and Face. These classes should be
linked properly in the process of building up the mesh by calling Mesh
class functions. Let's say they point to each other like this:
class Vertex {
HalfEdge *edge;
};
class HalfEdge {
Vertex* vert;
|
by: ivan.leben |
last post by:
I am writing this in a new thread to alert that I found a solution to
the problem mentioned here:
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8
and to avoid this topic getting lost before people interested in the
problem notice it.
The important tricks to the solution are two:
1) make the custom classes take a TEMPLATE argument which defines their
BASE class
2) EMBED the custom classes in a "Traits"...
|
by: Amu |
last post by:
i have a dll ( template class) ready which is written in
VC++6. But presently i need to inherit its classes into my new C#.net
project.so if there is some better solution with u then please give me
the solution.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |