borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Publishing an application)Next Topic (how to load an image from a web to visual basic) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : Is Double Dot Notation Possible in .NET? Solved Topic
Poster Message
matt_1ca
Level: Sage

Registered: 27-03-2005
Posts: 55

Ads by Lake Quincy Media
icon Is Double Dot Notation Possible in .NET?

I am trying to have a firm grasp of VB.NET and wondering if there is a way to use a double dot notation instead of the single dot notation people are normally accustomed to?

The double dot notation that I want to implement is shown directly below:

PersonData.Birthdate.IsValid  

Currently, the only way I know is by using the call shown below which I suspect is not using the full capabilities of .NET:

Validations.IsValid(PersonData.Birthdate)

My gut feeling is that there is a way to do it, and I am not about to give up unless experts out there like yourselves tell me that it is not possible.

Is it possible or not? If it is possible, then what changes do I need to do in my code to make it happen?

Thank you so much, I appreciate all the kind help you could give on this matter...

Gratefully,
Matt

My code is shown below:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    modVar.intDay = 25
    modVar.intMonth = 12
    modVar.intYear = 2009

    Dim PersonData As New Person(modVar.intMonth, modVar.intDay, modVar.intYear)
    Dim Validation As New Validations

    If Validations.IsValid(PersonData.Birthdate) = True Then
        MsgBox("Valid date")
    Else
        MsgBox("Date entered by user is invalid")
    End If
End Sub


Public Class DateProcessing

    Public Function Birthdate() As String
        Birthdate = CStr(intMonth) & "-" & CStr(intDay) & "-" & CStr(intYear)
    End Function

End Class


Public Class Person
    Inherits DateProcessing

    Public Sub New(ByVal intMonth As Integer, ByVal intDay As Integer, ByVal intyear As Integer)
        intMonth = intMonth
        intDay = intDay
        intyear = intyear
    End Sub

End Class


Public Class Validations

    Public Shared Function IsValid(ByVal strDateOfBirth As String) As Boolean
        Dim varData As Object

        IsValid = True
        varData = Split(strDateOfBirth, "-")

        If CStr(varData(0)).Length = 2 Then
        Else
            IsValid = False
            Exit Function
        End If

        If CStr(varData(1)).Length = 2 Then
        Else
            IsValid = False
            Exit Function
        End If

        If CStr(varData(2)).Length = 4 Then
        Else
            IsValid = False
            Exit Function
        End If

    End Function

End Class


Module modVar
    Public intYear As Integer
    Public intMonth As Integer
    Public intDay As Integer
End Module

11-04-2009 at 10:51 PM
View Profile Send Email to User Show All Posts | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 606
icon Re: Is Double Dot Notation Possible in .NET?

Hi Matt,
dot notation only extends to the properties or methods in a particular class, and IsValid is not a property or method of the PersonData class, its a method of the Validations class, so you cannot implement it the way you have shown.
You could use the DotNet Function "IsDate" to test the validity of the date :-

    If IsDate(PersonData.Birthdate)  Then
        MsgBox("Valid date")
    Else
        MsgBox("Date entered by user is invalid")
    End If
However, I would be inclined to test the validity of the date BEFORE passing it to the new Person Class to ensure that you are not creating a new instance of the class with invalid data.
Of course, if you used a DateAndTimePicker Control for the User Input then you would already know that the information was valid. You could then use the DatePart Function to extract the individual values of the Year, Month and Day.


[Edited by GeoffS on 14-04-2009 at 01:58 PM GMT]

____________________________
multi-tasking - the ability to hang more than one app. at the same time.

14-04-2009 at 01:56 PM
View Profile Send Email to User Show All Posts | Quote Reply
matt_1ca
Level: Sage

Registered: 27-03-2005
Posts: 55
icon Re: Is Double Dot Notation Possible in .NET?

Thank you very much ... your answer has saved me from hitting wall ... I really appreciate it  

Gratefully,
Matt  

Ads by Lake Quincy Media
15-04-2009 at 05:24 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB.Net : Is Double Dot Notation Possible in .NET? Solved Topic
Previous Topic (Publishing an application)Next Topic (how to load an image from a web to visual basic) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder