Class in VB.NET

Can I do the folowing:

make class like this

Public Class vizura
Public vizurabroj As String
Public horugao As Single
Public verugao As Single
Public kduzina As Single
Public lvisina As Single
End Class

and then make another class which element SVIZURA iz array

Public Class stanica
Public imestajaliste As String
Public ivisina As Single
Public svizura(100) As New vizura
End Class

I know something like this can be done in C++ but when I tryed in VB
ERROR.

Comments

  • [b][red]This message was edited by DrMarten at 2006-6-11 2:35:2[/red][/b][hr]
    : Can I do the following:
    :
    : make class like this
    :
    : Public Class vizura
    : Public vizurabroj As String
    : Public horugao As Single
    : Public verugao As Single
    : Public kduzina As Single
    : Public lvisina As Single
    : End Class
    :
    : and then make another class which element SVIZURA iz array
    [code]
    '[blue] This is your original code.[/blue]
    Public Class stanica
    Public imestajaliste As String
    Public ivisina As Single
    Public svizura(100) As New vizura
    End Class
    [/code]


    [b]Change it to read as follows:>>
    [code]
    Public Class stanica
    Public imestajaliste As String
    Public ivisina As Single
    Public svizura(100) As vizura
    End Class
    [/code][/b]

    Otherwise put a [b]NEW[/b] sub in your vizura CLASS.
    The NEW sub is called to get a NEW instance of an object.

    Eg. If you had a CAR class with a NEW sub in it, then anywhere in your program or within another CLASS say:>>

    Public iWantANewCar As New Car
    'so as to create a new "instance" of that object.

    See another example here:>>
    http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=14&MsgID=338814&Setting=A9999F0001

    in which the variable [b]theCards[/b] is of TYPE [b]deckOfCards
    [/b] within the CARD class.
    The main program has the line>>

    Private theDeck As New DeckOfCards
    as DeckOfCards CLASS has a NEW sub inside it.
    The NEW can be omitted, it just uses the original arraylist instead.



    Regards,

    Dr M.

  • [code]Public Class vizura
    :Public vizurabroj As String
    :Public horugao As Single
    :Public verugao As Single
    :Public kduzina As Single
    :Public lvisina As Single
    :End Class
    :
    :and then make another class which element SVIZURA iz array
    :
    :Public Class stanica
    :Public imestajaliste As String
    :Public ivisina As Single
    :Public svizura(100) As New vizura
    :End Class [/code]


    This is the sample of data i need to store in memory
    Here we are two instances of class stanica (there can be much more and
    I thought it will be easyest way to store it in array)
    [code]
    101Z 1.6300 'this line is something like header of stanica
    'and it is unique in one instance of class stanica.
    'Folowing lines are instances of class vizura
    'and I could have thousands of lines like this
    'so I tryed to make array of vizura to store
    'all of data
    P22 000.0001 90.0420 138.462 1.520
    102Z 183.2601 89.5507 110.113 1.530
    2001 096.1445 89.4634 26.221 1.870
    2002 096.5649 90.2243 19.268 1.620
    2003 109.4837 90.3711 19.948 1.320
    2004 112.0059 93.2535 17.500 0.600
    2005 120.5302 92.2122 18.568 0.900
    2006 130.2753 89.2027 20.805 1.900
    2007 130.0242 88.5518 14.582 2.000
    2008 180.4456 89.5613 9.434 1.620


    102Z 1.5900
    101Z 359.5959 90.0843 110.113 1.560
    103Z 184.3947 89.3937 36.464 1.660
    2024 277.0647 87.4120 33.807 2.880
    2025 280.3235 89.2536 23.163 1.730
    2026 296.1548 87.4043 22.645 2.500
    2027 282.2715 89.3618 20.627 1.750
    2028 283.2031 90.0922 19.005 1.620
    2029 248.0132 89.3614 21.719 1.620
    2030 229.3628 92.4038 26.622 0.200
    2031 118.5609 89.2503 15.158 1.620
    2032 145.3618 89.1859 23.281 1.620
    2033 151.2426 88.0558 22.618 2.250
    [/code]

    I didn't understand all instructions you gave to me but I think
    that is not solution to solve my problem.
    Should I use a Structure instead of class in case of vizura and forgot
    to make some functions and subs which I wanted in Class vizura

    Thanks on any help
  • [b][red]This message was edited by DrMarten at 2006-6-12 2:5:59[/red][/b][hr]

    Hi, will this do for you?

    If you want to write the values to a file i suggest a structure instead.
    Use a vbFixedString statement for random file access with fileget and fileput.

    [code]
    '#Region " Windows Form Designer generated code "
    [green]I've shown this statement to show it should be
    after the [b]" Windows Form Designer generated code "[/b]
    line.>>
    [/green]
    [b]Public vizuraArray() As vizura[/b]
    '_____________________________________________________________________
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim myString As String
    Dim myNumber As Single

    vizuraArray(0).vizurabro = "Whatever String"
    vizuraArray(0).horuga = 1
    vizuraArray(0).kduzin = 2
    vizuraArray(0).lvisin = 3
    vizuraArray(0).veruga = 4

    vizuraArray(1).vizurabro = "New String"
    vizuraArray(1).horuga = 1.2
    vizuraArray(1).kduzin = 2.3
    vizuraArray(1).lvisin = 3.4
    vizuraArray(1).veruga = 4.5
    [green]
    'Etcetera for as far as
    'you want as this is an unbounded array.

    'Further examples>>[/green]
    myString = vizuraArray(0).vizurabro
    myNumber = vizuraArray(0).horuga

    End Sub
    [/code]

    Here is the vizura CLASS>>
    [code]
    Public Class vizura
    Private vizurabroj As String
    Private horugao As Single
    Private verugao As Single
    Private kduzina As Single
    Private lvisina As Single
    Public Property vizurabro() As String
    Get
    Return vizurabroj
    End Get
    Set(ByVal Value As String)
    vizurabroj = Value
    End Set
    End Property
    Public Property horuga() As Single
    Get
    Return horugao
    End Get
    Set(ByVal Value As Single)
    horugao = Value
    End Set
    End Property
    Public Property veruga() As Single
    Get
    Return verugao
    End Get
    Set(ByVal Value As Single)
    verugao = Value
    End Set
    End Property
    Public Property kduzin() As Single
    Get
    Return kduzina
    End Get
    Set(ByVal Value As Single)
    kduzina = Value
    End Set
    End Property
    Public Property lvisin() As Single
    Get
    Return lvisina
    End Get
    Set(ByVal Value As Single)
    lvisina = Value
    End Set
    End Property
    End Class
    [/code]


    Regards,

    Dr M



  • [b][red]This message was edited by DrMarten at 2006-6-12 2:26:24[/red][/b][hr]

    [code]
    Structure myList

    Public imestajaliste As String
    Public ivisina As Single
    Public svizura() As vizura

    End Structure


    Private Sub example()
    [green]
    'Declaring an array of a structure (this STRUCTURE contains another array).
    'The STRUCTURE array SVIZURA contains the ELEMENTS
    ' of the VIZURA CLASS i.e.

    'Private horugao As Single 'passed as horuga
    'Private kduzina As Single 'passsed as kduzin
    'Private lvisina As Single 'passed as lvisin
    'Private verugao As Single 'passed as veruga
    ' Private vizurabroj 'passed as vizurabro
    [/green]

    Dim myArray() As myList

    myArray(0).imestajaliste = "This is a string."
    myArray(0).ivisina = 1.2 'This is a SINGLE
    myArray(0).svizura(0).horuga = 2.3 'This is a SINGLE
    myArray(0).svizura(0).kduzin = 4.5 'This is a SINGLE
    myArray(0).svizura(0).lvisin = 5.6 'This is a SINGLE
    myArray(0).svizura(0).veruga = 6.7 'This is a SINGLE
    myArray(0).svizura(0).vizurabro = "This is another string."
    [green]
    'or without creating an array called myArray use
    'the following method for each set of data>>

    'Create a variable of the STRUCTURE type or name of "myList"[/green]
    Dim list1 As myList
    list1.imestajaliste = "My string"
    list1.ivisina = 1.2 'This is a SINGLE
    list1.svizura(0).horuga = 2.3 'This is a SINGLE
    list1.svizura(0).kduzin = 3.4 'This is a SINGLE
    list1.svizura(0).lvisin = 4.5 'This is a SINGLE
    list1.svizura(0).veruga = 5.6 'This is a SINGLE
    list1.svizura(0).vizurabro = "Yet another string."

    End Sub
    [/code]

    The CLASS vizura is still the same. :-)
    [code]
    Public Class vizura

    Private vizurabroj As String
    Private horugao As Single
    Private verugao As Single
    Private kduzina As Single
    Private lvisina As Single
    Public Property vizurabro() As String
    Get
    Return vizurabroj
    End Get
    Set(ByVal Value As String)
    vizurabroj = Value
    End Set
    End Property
    Public Property horuga() As Single
    Get
    Return horugao
    End Get
    Set(ByVal Value As Single)
    horugao = Value
    End Set
    End Property
    Public Property veruga() As Single
    Get
    Return verugao
    End Get
    Set(ByVal Value As Single)
    verugao = Value
    End Set
    End Property
    Public Property kduzin() As Single
    Get
    Return kduzina
    End Get
    Set(ByVal Value As Single)
    kduzina = Value
    End Set
    End Property
    Public Property lvisin() As Single
    Get
    Return lvisina
    End Get
    Set(ByVal Value As Single)
    lvisina = Value
    End Set
    End Property

    End Class
    [/code]

    Don't forget to make all strings in the CLASS and the STRUCTURE
    a vbFixedString if you are writing STRUCTURE records to a random
    access file.

    list1 could refer to file number 1 or file1 if you like? :-)



    Regards,

    Dr M.



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories