.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Double dot notation is it possible in VB.NET or not

4 REPLIES 4
Reply
Message 1 of 5
matt_1ca
618 Views, 4 Replies

Double dot notation is it possible in VB.NET or not

I am wondering if there is a way to use a double dot notation instead of the single dot notation people are
normally accustomed to?

Currently the company bigwigs have decided that we will have to go with new AutoCAD program developments
using VB.net.

Since all the people in our group are new in .NET there has been a debate as to whether a double dot net
call as shown below is at all possible. On my side I have exhausted all the books in my arsenal but cannot
find a single example showing how to implement it.

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)

In other words what I want to do is to somehow be able to replace the Validations.IsValid(PersonData.Birthdate) with a
PersonData.Birthdate.IsValid call.

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
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: matt_1ca


If you create a BirthDay type which has a Valid
method and this type is a field in your PersonData class you could call
it

like you want. IMO you usually don't want to create
an instance of a type if you have bad data. I would handle it
something

like the attached sample. Also you guys should find
a good newsgroup to ask these questions that don't involve the
Autocad

dot NET api. The sample is in c# but you should get
the idea.

 

 


style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px">
I
am wondering if there is a way to use a double dot notation instead of the
single dot notation people are normally accustomed to? Currently the company
bigwigs have decided that we will have to go with new AutoCAD program
developments using VB.net. Since all the people in our group are new in .NET
there has been a debate as to whether a double dot net call as shown below is
at all possible. On my side I have exhausted all the books in my arsenal but
cannot find a single example showing how to implement it. 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) In other words what I want to do is
to somehow be able to replace the Validations.IsValid(PersonData.Birthdate)
with a PersonData.Birthdate.IsValid call. 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
Message 3 of 5
Anonymous
in reply to: matt_1ca


I don't understand how the txt file code ended
up on one line - it's fine on my end. Maybe this

will be better.

 

{code}

using System;

 

namespace ConsoleApplication1
{
  class
Program
  {
    static void Main(string[]
args)
    {
     
try
     
{
        PersonData pd = new
PersonData(new DateTime(2009,4,12));
     
}

 

      catch
(ArgumentException ae)
     
{
        // do bad data
stuff
      }
     

    }

 

    public class
PersonData
    {
     

      private DateTime birthday;

 

      public
PersonData(DateTime dt)
     
{
        BirthDay =
dt;
      }

 

      public DateTime
BirthDay
     
{
        get { return birthday;
}
       
set
       
{
          if
(ValidBirthDay(value))
           
birthday = value;
         
else
           
throw
             
(new ArgumentException("Bad
birthday"));
       
}
      }

 

      private bool
ValidBirthDay(DateTime d)
     
{
        //do your testing return true or
false
        return
false;
      }
    }
 
}
}

{code}


style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"
dir=ltr>
"Paul Richardson" <prichardson<lastpoint> wrote in message
href="news:6160791@discussion.autodesk.com">news:6160791@discussion.autodesk.com
...


If you create a BirthDay type which has a Valid
method and this type is a field in your PersonData class you could call
it

like you want. IMO you usually don't want to
create an instance of a type if you have bad data. I would handle it
something

like the attached sample. Also you guys should
find a good newsgroup to ask these questions that don't involve the
Autocad

dot NET api. The sample is in c# but you should
get the idea.

 

 


style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px">
I
am wondering if there is a way to use a double dot notation instead of the
single dot notation people are normally accustomed to? Currently the company
bigwigs have decided that we will have to go with new AutoCAD program
developments using VB.net. Since all the people in our group are new in .NET
there has been a debate as to whether a double dot net call as shown below
is at all possible. On my side I have exhausted all the books in my arsenal
but cannot find a single example showing how to implement it. 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) In other words what I want to do
is to somehow be able to replace the
Validations.IsValid(PersonData.Birthdate) with a
PersonData.Birthdate.IsValid call. 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
Message 4 of 5
matt_1ca
in reply to: matt_1ca

Thank you so much for this valuable answer, I really appreciate it.

Gratefully,
Matt
Message 5 of 5
Anonymous
in reply to: matt_1ca


You're welcome. Try looking into the msdn groups
for .net and stackoverflow - both have some very helpful people on
basic-

advanced .net stuff. Here is the idea creating a
seperate class for your Birthday type and using it as a field in your PersonData
type.

 

{code}

using System;

 

namespace ConsoleApplication1
{
  class
Program
  {
    static void Main(string[]
args)
    {
     
try
     
{
        PersonData pd = new
PersonData(new
DateTime(2009,4,12));
       

        //If you make BirthDay.Valid
public you could call it like
such.
        //I'd leave it as a private
method of the class like my first example.

 

        //if
(pd.Bd.Valid(new DateTime(2009, 4,
12)))
       
//{
        // 
//...
       
//}
      }

 

      catch
(ArgumentException ae)
     
{
        // do bad data
stuff
      }
     

    }

 

    public class
PersonData
    {

      //readonly
makes bd only able to be set during instantiation of the type.

      //remove and
add a setter to the BirthDay property to be able to set this

      //property whenever
you like.

      private readonly
BirthDay bd;

 

      public
PersonData(DateTime dt)
     
{
          bd = new
BirthDay(dt);
      }

 

      public BirthDay
Bd
     
{
        get { return bd;
}
      }
    }

 


    public class BirthDay
   
{
      private DateTime dt;

 

      public BirthDay(DateTime
dt)
     
{
        Dt =
dt;
      }

 

      //throw an error if bad data is passed
in.
      public DateTime
Dt
     
{
        get { return dt;
}
       
set
       
{
          if
(Valid(value))
           
dt = value;
         
else
            throw

             
(new ArgumentException("Bad
birthday"));
       
}
      }

 

      private bool Valid(DateTime
d)
     
{
        //do your testing return true or
false
        return
false;
      }
    }
 
}
}

{code}


style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px">
Thank
you so much for this valuable answer, I really appreciate it. Gratefully,
Matt

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost