Results 1 to 3 of 3

Thread: Use Class for remembering the length of data

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2017
    Posts
    10

    Use Class for remembering the length of data

    Hello everyone

    I'm fairly new to Visual Basic, so this question might be very "dumb" .
    For an assignment I have to use a class that contains a number of properties, among other things, to remember the maximum length of the various data (maximum length of the name, maximum length of the country, etc.) for the purpose of aligning the data.


    I've tried a few things but I'm not sure how to do about this.


    Can you guide me in the right direction?


    Form 1:


    Code:
    Dim NameLength As New LayoutClass
    
    
    If Persons Is Nothing Then
    
       TextBox1.Text = "no person was found"
            Else
                Dim queryData = From Person In Persons.Descendants("Person")
                    Where (Person.Attribute("Name")).Value <> ""
                  Select Naam = Person.Attribute("Name").Value,
                  Country= Person.Attribute("Country").Value
                  Order By (Name)
    
    TextBox1.Text = " "
    TextBox1.Text = "The persons are: " & vbCrLf & NameLength.PersonNameLength


    LayoutClass


    Code:
    Public Class LayoutClass
    
    
        Public Property NameLength() As Short
        Public Property CountryLength() As Short
     
    
    
        Public Function PersonNameLength() As Short
            Dim PersonLength As Short
            If PersonLength > NameLength Then
                PersonNameLength = PersonLength 
            End If
    
            Return PersonNameLength 
    
        End Function
    End Class

    Thanks for the effort!

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Use Class for remembering the length of data

    Code:
    Public Class LayoutClass
    
        Public Property NameLength As Short = what???
        Public Property CountryLength As Short = what???
     
        Public Function PersonNameLength(PersonLength As Short) As Short
            Return Math.Max(PersonLength, NameLength)
        End Function
    
    End Class

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2017
    Posts
    10

    Re: Use Class for remembering the length of data

    Thank you for your reply .paul. !
    First of all, i'm sorry for my bad english, because english isn't my nattive language.

    When I put this in my code, I get in my Textbox "The persons are: 16" but that is not the intention.

    Perhaps I should have explained a little more about my assignment.
    I load an xml file that lists the people per line.
    The intent is to align these lines and split them up by the maximum length of the various data.

    But maybe i'm just doing something wrong or did i misunderstand you?


    Form 1:

    Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
    Public Persons As XElement
    Dim myNameLength As New LayoutClass
    
    
    If Persons Is Nothing Then
    
       TextBox1.Text = "no person was found"
            Else
                Dim queryData = From Person In Persons.Descendants("Person")
                    Where (Person.Attribute("Name")).Value <> ""
                  Select Naam = Person.Attribute("Name").Value,
                  Country= Person.Attribute("Country").Value
                  Order By (Name)
    
    TextBox1.Text = " "
    TextBox1.Text = "The persons are: " & vbCrLf & myNameLength.PersonNameLength
    
    End sub



    LayOut class:


    Code:
    Public Class LayoutClass
    
        Public Property NameLength As Short = 16
        Public Property CountryLength As Short = 16
     
        Public Function PersonNameLength(PersonLength As Short) As Short
            Return Math.Max(PersonLength, NameLength)
        End Function
    
    End Class

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width