نمایش نتایج 1 تا 5 از 5

نام تاپیک: در خواست يه برنامه كامل كه در آن از كلاس و...استفاده شده باشد

  1. #1
    کاربر دائمی آواتار Afshin160
    تاریخ عضویت
    شهریور 1386
    محل زندگی
    تهران
    پست
    528

    Question در خواست يه برنامه كامل كه در آن از كلاس و...استفاده شده باشد

    سلام...
    من دنبال يه برنامه كامل (به نوعي آموزشي) ميگردم كه از كلاسها و متد ها و اينام ها و property ها و.... گزارش گيري و ... درآن استفاده شده باشد....

    ممنون ميشم اگه راهنماييم كنيد.....

  2. #2
    کاربر دائمی آواتار Afshin160
    تاریخ عضویت
    شهریور 1386
    محل زندگی
    تهران
    پست
    528

    نقل قول: در خواست يه برنامه كامل كه در آن از كلاس و...استفاده شده باشد

    سلام ...
    كسي نبود كمك كنه ...

    يعني كسي به از اين امكانات ستفاده نكرده ...؟!!!
    فكر كنم اگه كسي يه نمونه خوب داشته باشه ازش استقبال فراواني ميشه..
    باتشكر

  3. #3
    کاربر دائمی آواتار mostafaaa
    تاریخ عضویت
    دی 1386
    محل زندگی
    جزیره کیش
    پست
    723

    نقل قول: در خواست يه برنامه كامل كه در آن از كلاس و...استفاده شده باشد

    یه سری فایل هست در مورد مقدمات OOP که قبلا از همین سایت گرفتمشون. کدهاشون رو اینجا میزارم .

     Lesson1'You can use the classes in a namespace, by simply importing the namespace.
    'The 'imports' keyword is used to import a namespace to your project.
    '.NET framework provides a rich set of built in classes, grouped
    'to various namespaces.

    'In this lesson, we are using the system namespace.



    '-----------------------------------------------------------------
    'Import the System namespace (already available in .NET)
    Imports System
    '-----------------------------------------------------------------



    '// 2) A Class
    '====================================
    '
    'Probably, you are already familiar with classes and objects
    'Simply speaking, a class is a definition of a real life
    'object. For example, Human is a class for representing all
    'human beings. Dog is a class to represent all Dogs.

    'Classes can contain functions too.



    '-----------------------------------------------------------------
    'Animals is a namespace
    Namespace Animals

    'Dog is a class in the namespace Animals
    Class Dog

    'Bark is a function in this class
    Function Bark()
    Console.Writeline ("Dog is barking")
    End Function

    End Class

    End Namespace
    '-----------------------------------------------------------------



    '// 3) An Object
    '====================================
    '
    'An object is an instance of a class. For example,
    'Jimmy is an object of type Dog. We will create
    'an object in the next section. Read on.


    '// 4) Modules
    '====================================
    '
    'You can use modules to write common functions. A module is a
    'group of functions. Unlike functions in classes, public functions
    'in modules can be called directly from some where else.

    'VB provides Functions and Subroutines. Functions and Sub
    'routines are almost same, but subroutines can't return
    'a value.
    '

    '-----------------------------------------------------------------


    Public Module modMain

    'Execution will start from the Main() subroutine

    Sub Main()

    'Call our function. See below
    OurFunction()
    End sub


    'OurFunction: Our own little function to use the class Dog

    Function OurFunction()
    'Here is how we declare a variable Jimmy of type Dog.
    'We use Animals.Dog because, the class Dog is in the
    'namespace Animals (see above).

    Dim Jimmy as Animals.Dog

    'Create an object. Unlike in VB 6, it is not required to use
    'the 'set' keyword.

    Jimmy = new Animals.Dog()

    'Another way to create an object is
    'Dim Jimmy as new Dog

    'Call Jimmy's Main Function
    Jimmy.Bark()

    End Function

    End module


    '-----------------------------------------------------------------
    Lesson2
    '@desc: 2 : Access Types

    'LESSON 2: ACCESS TYPES
    '----------------------------------------------------

    'The major access types are Public, Private, Friend And Protected.

    'A class may contain functions, variables etc, either public
    'or private or protected or friend. If they are public,
    'they can be accessed by creating objects of the class.

    'Private and Protected members can be accessed only by functions
    'inside the class. Protected members are much like private members,
    'but they have some special use while inheriting the class. We
    'will see this later, in Inheritance (Lesson 5).

    'Friend members can be accessed only from elements in the
    'same project, and not by elements outer the current project.


    'Let us expand our dog class.

    '-----------------------------------------------------------------
    'Import the System namespace (already available in .NET)
    Imports System
    '-----------------------------------------------------------------

    '-----------------------------------------------------------------
    'Animals is a namespace
    Namespace Animals

    'Dog is a class in the namespace Animals
    Public Class Dog

    'A public variable
    Public AgeOfDog as Integer


    'Bark is a function in this class. It is public
    Public Function Bark()
    Console.Writeline ("Dog is barking")
    End Function

    'Walk is a function in this class. It is private
    Private Function Walk()
    Console.Writeline ("Dog is walking")
    End Function

    End Class


    End Namespace
    '-----------------------------------------------------------------


    '-----------------------------------------------------------------
    'Our Module

    Public Module modMain

    'Execution will start from the Main() subroutine

    Sub Main()

    'Call our function. See below
    OurFunction()
    End sub


    'OurFunction: Called from Main()

    Function OurFunction()

    Dim Jimmy as Animals.Dog
    Jimmy=new Animals.Dog()


    'This will work, because Bark & Ageofdog are public
    Jimmy.Bark
    Jimmy.AgeOfDog=10

    'Calling the Walk function will not work here, because
    'Walk() is outside the class Dog

    'So this is wrong. Uncomment this and try to compile, it will
    'cause an error.

    'Jimmy.Walk

    End Function

    End Module


    '-----------------------------------------------------------------
    'Additional Notes:

    '//Encapsulation:

    'Putting all the data and related functions, in the class is called
    'as Encapsulation.

    '//Data Hiding or Abstraction:

    'Normally, in a class, variables used to hold data (like the age of
    'a dog) is declared as private. Functions or property routines are used
    'to access these variables. Protecting the data of an object from
    'outer functions is called as Abstraction or Data Hiding. This prevents
    'accidental modification of data by functions outside the class.

    Lesson3
    '@desc: 3 : Shared Functions

    '================================================= ===============
    'Author: Anoop - anoop@logicmatrixonline.com
    ' http://www.logicmatrixonline.com/anoop
    '================================================= ===============

    '
    'You need Microsoft.NET framework SDK installed in your system to
    'compile and execute the excercises in this article.
    'You can download it from http://www.asp.net

    'You need a good editor to compile .NET applications. You can try
    'Smart Editor Professional, a free to try editor which supports
    'C#‎, VB.NET etc. See http://www.logicmatrixonline.com/sepro

    '================================================= ===============

    'Note: See Readme.htm in the same folder to learn how to
    'compile this file.
    '================================================= ===============

    'LESSON 3: SHARED FUNCTIONS
    '----------------------------------------------------

    'The shared members in a class (both functions and variables)
    'can be used with out creating objects of the class as shown.

    'The Shared modifier indicates the method does not operate on a
    'specific instance of a type and may be invoked directly from
    'a type rather than through a particular instance of a type.

    '-----------------------------------------------------------------
    'Import the System namespace (already available in .NET)
    Imports System
    '-----------------------------------------------------------------

    '-----------------------------------------------------------------
    'Animals is a namespace
    Namespace Animals

    'Dog is a class in the namespace Animals
    Class Dog

    'Bark is a now a public, shared function in this class

    Public Shared Function Bark()
    Console.Writeline ("Dog is barking")
    End Function


    'Walk is a public function in this class. It is not shared
    Public Function Walk()
    Console.Writeline ("Dog is walking")
    End Function

    End Class

    End Namespace
    '-----------------------------------------------------------------


    '-----------------------------------------------------------------
    'Our Module

    Public Module modMain

    'Execution will start from the Main() subroutine

    Sub Main()


    'We can call the Bark() function directly,
    'with out creating an object of type Dog -
    'because it is shared.

    Animals.Dog.Bark()


    'We can call the Walk() function only
    'after creating an object, because
    'it is not shared.

    Dim Jimmy as Animals.Dog
    Jimmy=new Animals.Dog()
    Jimmy.Walk()

    'Now Guess? The WriteLine() function we used so far
    'is a shared function in class Console :)

    'Also, we can write the Main() function itself as a shared
    'function in a class. i.e Shared Sub Main(). Try
    'moving Main() from this module to the above class


    End sub

    End Module
    '-----------------------------------------------------------------

    Lesson4
    '@desc: 4 : Over Loading Functions

    'LESSON 4: OVERLOADING
    '----------------------------------------------------

    '-----------------------------------------------------------------
    'Import the System namespace (already available in .NET)
    Imports System
    '-----------------------------------------------------------------


    'Overloading is a simple technique, to enable a single
    'function name to accept parameters of different type.


    'Our simple Adder class
    Class Adder

    'Here, we have two Add() functions.

    'This one adds two integers.
    'Convert.ToString is equivalent to good old Cstr

    Overloads Public Sub Add(A as Integer, B as Integer)
    Console.Writeline ("Adding Integers: " + Convert.ToString(a + b))
    End Sub


    'This one adds two strings
    Overloads Public Sub Add(A as String, B as String)
    Console.Writeline ("Adding Strings: " + a + b)
    End Sub

    'And both have the same name. This is possible because, we used the
    'Overloads keyword, to overload them.


    'Here, we have the Main Function with in this class. When you write.
    'your main function inside the class, it should be a shared function.

    Shared Sub Main()

    Dim AdderObj as Adder

    'Create the object
    AdderObj=new Adder

    'This will invoke first function
    AdderObj.Add(10,20)
    'This will invoke second function
    AdderObj.Add("hello"," how are you")


    End Sub


    End Class




    Lesson5
    '@desc: 5 : Inheritance

    '================================================= ===============
    'Author: Anoop - anoop@logicmatrixonline.com
    ' http://www.logicmatrixonline.com/anoop
    '================================================= ===============



    'Note: See Readme.htm in the same folder to learn how to
    'compile this file.
    '================================================= ===============

    'LESSON 5: INHERITANCE
    '----------------------------------------------------

    '-----------------------------------------------------------------
    'Import the System namespace (already available in .NET)
    Imports System
    '-----------------------------------------------------------------


    'Inheritance is the property in which, a derived class
    'aquires the attributes of its base class. In simple terms,
    'you can create or 'inherit' your own class (derived class),
    'using an existing class (base class). You can use the
    'Inherits keyword for this.

    'Let us see a simple example.

    '// Our simple base class
    Class Human

    'This is something that all humans do
    Public Sub Walk()
    Console.Writeline ("Walking")
    End Sub

    End Class


    '-----------------------------------------------------------------

    '// Now, let us derive a class from human

    'A programmer IS_A Human

    Class Programmer
    Inherits Human

    'We already have the above Walk() function

    'This is something that all programmers do ;)
    Public Sub StealCode()
    Console.Writeline ("Stealing code")
    End Sub

    'MS.NET has a rich set of built in classes, which can be derived
    'to create your own classes.

    End Class

    '-----------------------------------------------------------------
    'Just a main class

    Class MainClass


    'Our main function
    Shared Sub Main()
    Dim Tom as Programmer
    Tom=new Programmer

    'This call is okie because programmer got this function
    'from its base class
    Tom.Walk()

    'This is also correct because Tom is a programmer
    Tom.StealCode()

    End Sub

    End Class

    '-----------------------------------------------------------------

    'Additional Notes:




  4. #4
    کاربر دائمی آواتار mostafaaa
    تاریخ عضویت
    دی 1386
    محل زندگی
    جزیره کیش
    پست
    723

    نقل قول: در خواست يه برنامه كامل كه در آن از كلاس و...استفاده شده باشد

    Lesson6

    '@desc: 6 : Over Riding

    '================================================= ===============
    'Author: Anoop - anoop@logicmatrixonline.com
    ' http://www.logicmatrixonline.com/anoop
    '================================================= ===============



    'Note: See Readme.htm in the same folder to learn how to
    'compile this file.
    '================================================= ===============

    'LESSON 6: OVERRIDING
    '----------------------------------------------------

    '-----------------------------------------------------------------
    'Import the System namespace (already available in .NET)
    Imports System
    '-----------------------------------------------------------------


    'By default, a derived class inherits methods from its base class.
    'If an inherited property or method needs to behave differently in
    'the derived class it can be overridden; that is, you can define a
    'new implementation of the method in the derived class.

    'The 'Overridable' keyword is used to mark a function as
    'overridable. The keyword 'Overrides' is used to mark that a function
    'is overriding some base class function.

    'Let us see an example

    '// Our simple base class
    Class Human

    'Speak() is declared Overridable
    Overridable Public Sub Speak()
    Console.Writeline ("Speaking")
    End Sub

    End Class


    '-----------------------------------------------------------------

    '// Now, let us derive a class from human

    'An Indian IS_A Human

    Class Indian
    Inherits Human

    'Let us make Indian speak Hindi, the National Language
    'in India

    'Speak() is overriding Speak() in its base class (Human)

    Overrides Public Sub Speak()
    Console.Writeline ("Speaking Hindi")


    'Important: As you expect, any call to Speak() inside this class
    'will invoke the Speak() in this class. If you need to
    'call Speak() in base class, you can use MyBase keyword.

    'Like this
    'Mybase.Speak()

    End Sub




    End Class

    '-----------------------------------------------------------------

    '// Just a class to put our Main()

    Class MainClass


    'Our main function
    Shared Sub Main()

    'Tom is a generic Human
    Dim Tom as Human
    Tom=new Human

    'Tony is a human and an Indian
    Dim Tony as Indian
    Tony=new Indian


    'This call will invoke the Speak() function
    'in class Human
    Tom.Speak()

    'This call will invoke the Speak() function
    'in class Indian
    Tony.Speak()

    End Sub

    End Class

    '-----------------------------------------------------------------



    Lesson7

    '@desc: 7 : Polymorphism

    '================================================= ===============
    'Author: Anoop - anoop@logicmatrixonline.com
    ' http://www.logicmatrixonline.com/anoop
    '================================================= ===============



    'Note: See Readme.htm in the same folder to learn how to
    'compile this file.
    '================================================= ===============


    'LESSON 7: POLYMORPHISM
    '----------------------------------------------------

    '-----------------------------------------------------------------
    'Import the System namespace (already available in .NET)
    Imports System
    '-----------------------------------------------------------------


    'This example is exactly the same one we saw in previous lesson.
    'The only difference is in the Shared Sub Main() in class
    'ClassMain. So scroll down.

    'Let us see an example

    '// Our simple base class
    Class Human

    'Speak() is declared Overridable
    Overridable Public Sub Speak()
    Console.Writeline ("Speaking")
    End Sub

    End Class


    '-----------------------------------------------------------------

    '// Now, let us derive a class from human

    'An Indian IS_A Human

    Class Indian
    Inherits Human

    'Let us make Indian speak Hindi, the National Language
    'in India

    'Speak() is overriding Speak() in its base class (Human)

    Overrides Public Sub Speak()
    Console.Writeline ("Speaking Hindi")


    'Important: As you expect, any call to Speak() inside this class
    'will invoke the Speak() in this class. If you need to
    'call Speak() in base class, you can use MyBase keyword.

    'Like this
    'Mybase.Speak()

    End Sub




    End Class

    '-----------------------------------------------------------------

    '// Carefully examine the code in Main()

    Class MainClass


    'Our main function
    Shared Sub Main()

    'Let us define Tom as a human (base class)
    Dim Tom as Human

    'Now, I am assiging an Indian (derived class)
    Tom=new Indian

    'The above assignment is legal, because
    'Indian IS_A human.

    'Now, let me call Speak as
    Tom.Speak()

    'Which Speak() will work? The Speak() in Indian, or the
    'Speak() in human?

    'The question arises because, Tom is declared as a Human,
    'but an object of type Indian is assigned to Tom.

    'The Answer is, the Speak() in Indian will work. This is because,
    'most object oriented languages like Vb.net can automatically
    'detect the type of the object assigned to a base class variable.

    'This is called Polymorphism


    End Sub

    End Class

    '-----------------------------------------------------------------




  5. #5
    کاربر دائمی آواتار mostafaaa
    تاریخ عضویت
    دی 1386
    محل زندگی
    جزیره کیش
    پست
    723

    نقل قول: در خواست يه برنامه كامل كه در آن از كلاس و...استفاده شده باشد

    Lesson8

    '@desc: 8 : Constructors & Destructors

    '================================================= ===============
    'Author: Anoop - anoop@logicmatrixonline.com
    ' http://www.logicmatrixonline.com/anoop
    '================================================= ===============



    'Note: See Readme.htm in the same folder to learn how to
    'compile this file.
    '================================================= ===============

    'LESSON 8: CONSTRUCTORS & DESTRUCTORS
    '----------------------------------------------------

    '-----------------------------------------------------------------
    'Import the System namespace (already available in .NET)
    Imports System
    '-----------------------------------------------------------------

    'A Constructor is a special function, which is called
    'automatically when a class is created. In VB.NET, you should use
    'New() to create constructors as in the below examples.

    'Constructors can be overloaded (see Lesson 4), but unlike
    'in functions, the Overloads keyword is not required.

    'A Destructor is a special function, which is called
    'automatically when a class is Destroyed. In VB.NET, you should use
    'Finalize() routine to create Destructors.

    'They are similiar to Class_Initialize and Class_Terminate
    'in VB 6.0


    '-----------------------------------------------------------------

    'Dog is a class
    Class Dog

    'The age variable
    Private Age as integer

    'The Default Constructor.
    Public Sub New()
    Console.Writeline ("Dog is Created With Age Zero")
    Age=0
    End Sub

    'The Parameterized Constructor
    Public Sub New(val as Integer)
    Console.Writeline ("Dog is Created With Age " + Convert.ToString(val))
    Age=val
    End Sub


    'This is the destructor.
    Overrides Protected Sub Finalize()
    Console.Writeline ("Dog is Destroyed")
    End Sub


    'The Main Function
    Shared Sub Main()
    Dim Jimmy, Jacky as Dog

    'Create the objects

    'This will call the default constructor
    Jimmy=new Dog

    'This will call the parameterized constructor
    Jacky=new Dog(10)

    End Sub

    'The Destruction will be done automatically, when
    'the program ends. This is done by the Garbage
    'Collector.

    End Class






    Lesson9

    '@desc: 9 : Property Routines

    '================================================= ===============
    'Author: Anoop - anoop@logicmatrixonline.com
    ' http://www.logicmatrixonline.com/anoop
    '================================================= ===============

    '


    'Note: See Readme.htm in the same folder to learn how to
    'compile this file.
    '================================================= ===============

    'LESSON 9: PROPERTY ROUTINES
    '----------------------------------------------------

    'You can use both properties and fields to store information in an object.
    'Whereas fields are simply public variables, properties use property procedures
    'to control how values are set or returned.

    'You can use the Get/Set keywords for getting/setting properties.

    'See the following example.

    '-----------------------------------------------------------------
    'Import the System namespace (already available in .NET)
    Imports System
    '-----------------------------------------------------------------


    'Dog is a class
    Public Class Dog

    'A private variable to hold the value
    Private mAgeOfDog as Integer

    'This is our property routine

    Public Property Age() As Integer

    'Called when someone tries to retreive the value
    Get
    Console.Writeline ("Getting Property")
    Return mAgeOfdog
    End Get

    'Called when someone tries to assign a value
    Set(ByVal Value As Integer)
    Console.Writeline ("Setting Property")
    mAgeOfDog=Value
    End Set

    End Property


    End Class

    '-----------------------------------------------------------------

    '// Another Class

    Class MainClass


    'Our main function. Execution starts here.
    Shared Sub Main()

    'Let us create an object.
    Dim Jimmy as Dog
    Jimmy=new Dog

    'We can't access mAgeofDog directly, so we should
    'use Age() property routine.

    'Set it. The Age Set routine will work
    Jimmy.Age=30

    'Get it back. The Age GEt routine will work
    Dim curAge=Jimmy.Age()

    End Sub

    End Class

    '-----------------------------------------------------------------



    Lesson10

    '@desc: 10 : Putting It Altogether

    '================================================= ===============
    'Author: Anoop - anoop@logicmatrixonline.com
    ' http://www.logicmatrixonline.com/anoop
    '================================================= ===============


    'Note: To compile this file, use the command
    'vbc Lesson10.vb /r:"System.Windows.Forms.dll","System.dll"
    '================================================= ===============

    'LESSON 10: PUTTING IT ALTOGETHER
    '----------------------------------------------------

    'Let us analyze a simple program.


    'Importing required namespaces
    Imports System
    Imports System.ComponentModel
    Imports System.Windows.Forms
    Imports System.Drawing

    '----------------------------------------------------

    'We are inheriting a class named SimpleForm, from the
    'class System.Windows.Forms.Form
    '
    'i.e, Windows is a namespace in system, Forms is a
    'namespace in Windows, and Form is a class in Forms.

    Public Class SimpleForm
    Inherits System.Windows.Forms.Form

    'Our constructor
    Public Sub New()
    'This will invoke the constructor of the base
    'class
    MyBase.New()

    'Set the text property of this class. We inherited
    'this property from the base class.

    Me.Text = "Hello, How Are You?"

    End Sub
    End Class

    '----------------------------------------------------


    Public Class MainClass

    Shared Sub Main()
    'Create an object from our SimpleForm class
    Dim sf as SimpleForm
    sf=new SimpleForm

    'Pass this object to the Run() function to start
    System.Windows.Forms.Application.Run(sf)
    End Sub

    End Class





    امیدوارم به دردتون بخوره

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •