input date from user

hi friends i m a new user of vb.net.
i want to get input from user as day then month and then year and then save it into any variable as date.
how can i do this.

plz help me.
pathak

Comments

  • : hi friends i m a new user of vb.net.
    : i want to get input from user as day then month and then year and then save it into any variable as date.
    : how can i do this.
    :
    : plz help me.
    : pathak
    :


    Try

    Dim SetDate As Date = New Date(TxtYear.Text, TxtMonth.Text, TxtDay.Text)

    I'm using textboxes for the input of the year,month and day.
    Hope that helps

  • thanks but wat abt validity of values since the text box can contain string but i need only numeric values.


    : : hi friends i m a new user of vb.net.
    : : i want to get input from user as day then month and then year and then save it into any variable as date.
    : : how can i do this.
    : :
    : : plz help me.
    : : pathak
    : :
    :
    :
    : Try
    :
    : Dim SetDate As Date = New Date(TxtYear.Text, TxtMonth.Text, TxtDay.Text)
    :
    : I'm using textboxes for the input of the year,month and day.
    : Hope that helps
    :

  • Try this:

    [code]

    Dim SetDate As Date = New Date(Cint(TxtYear.Text), Cint(TxtMonth.Text), Cint(TxtDay.Text))

    [/code]

    The Cint() funtion converts your text string into a integer, so it should work for you.
  • [b][red]This message was edited by DrMarten at 2006-3-30 6:25:5[/red][/b][hr]

    : hi friends i m a new user of vb.net.
    : i want to get input from user as day then month and then year and then save it into any variable as date.
    : how can i do this.
    :
    : plz help me.
    : pathak
    :
    ==================================================================
    This is from the help files>>

    Check the input is a number first using the function below>>

    IsNumeric Function
    See Also
    IsArray Function | IsDate Function | IsDBNull Function | IsError Function | IsNothing Function | IsReference Function | Object Data Type | TypeName Function
    Requirements
    Namespace: Microsoft.VisualBasic

    Module: Information

    Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)
    Returns a Boolean value indicating whether an expression can be evaluated as a number.

    Public Function IsNumeric(ByVal Expression As Object) As Boolean
    Parameter
    Expression
    Required. Object expression.
    Remarks
    IsNumeric returns True if the entire Expression is recognized as a number; otherwise, it returns False.

    IsNumeric returns True if the data type of Expression is Short, Integer, Long, Decimal, Single, or Short. It also returns True if Expression is a String that can be successfully converted to a Double. It returns False if Expression is of data type Date.

    Example
    This example uses the IsNumeric function to determine if the contents of a variable can be evaluated as a number.
    [code]
    Dim MyVar As Object
    Dim MyCheck As Boolean
    ' ...
    MyVar = "53" ' Assign value.
    MyCheck = IsNumeric(MyVar) ' Returns True.
    ' ...
    MyVar = "459.95" ' Assign value.
    MyCheck = IsNumeric(MyVar) ' Returns True.
    ' ...
    MyVar = "45 Help" ' Assign value.
    MyCheck = IsNumeric(MyVar) ' Returns False.
    [/code]

    You may also want to check the length of the strings>>

    [code]


    Dim myYear,myMonth,myDay As String
    myYear=TxtYear.Text
    myMonth=TxtMonth.Text
    myDay=TxtDay.Text

    If myYear.Length>4 then
    'Prompt to re-input the year.
    MessageBox.Show("Please re-type the YEAR in.")
    End IF

    If myMonth.Length>2 then
    'Prompt to re-input the month.
    MessageBox.Show("Please re-type the MONTH in.")
    End IF

    If myDay.Length>2 then
    'Prompt to re-input the day or date.
    MessageBox.Show("Please re-type the DAY/DATE in.")
    End IF

    [/code]

    Regards,

    Dr M.

  • thank Dr M

    i got exactly wat i want.
    thanks a lot.

    manoj kar pathak.


    ========================================================================

    : [b][red]This message was edited by DrMarten at 2006-3-30 6:25:5[/red][/b][hr]
    :
    : : hi friends i m a new user of vb.net.
    : : i want to get input from user as day then month and then year and then save it into any variable as date.
    : : how can i do this.
    : :
    : : plz help me.
    : : pathak
    : :
    : ==================================================================
    : This is from the help files>>
    :
    : Check the input is a number first using the function below>>
    :
    : IsNumeric Function
    : See Also
    : IsArray Function | IsDate Function | IsDBNull Function | IsError Function | IsNothing Function | IsReference Function | Object Data Type | TypeName Function
    : Requirements
    : Namespace: Microsoft.VisualBasic
    :
    : Module: Information
    :
    : Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)
    : Returns a Boolean value indicating whether an expression can be evaluated as a number.
    :
    : Public Function IsNumeric(ByVal Expression As Object) As Boolean
    : Parameter
    : Expression
    : Required. Object expression.
    : Remarks
    : IsNumeric returns True if the entire Expression is recognized as a number; otherwise, it returns False.
    :
    : IsNumeric returns True if the data type of Expression is Short, Integer, Long, Decimal, Single, or Short. It also returns True if Expression is a String that can be successfully converted to a Double. It returns False if Expression is of data type Date.
    :
    : Example
    : This example uses the IsNumeric function to determine if the contents of a variable can be evaluated as a number.
    : [code]
    : Dim MyVar As Object
    : Dim MyCheck As Boolean
    : ' ...
    : MyVar = "53" ' Assign value.
    : MyCheck = IsNumeric(MyVar) ' Returns True.
    : ' ...
    : MyVar = "459.95" ' Assign value.
    : MyCheck = IsNumeric(MyVar) ' Returns True.
    : ' ...
    : MyVar = "45 Help" ' Assign value.
    : MyCheck = IsNumeric(MyVar) ' Returns False.
    : [/code]
    :
    : You may also want to check the length of the strings>>
    :
    : [code]
    :
    :
    : Dim myYear,myMonth,myDay As String
    : myYear=TxtYear.Text
    : myMonth=TxtMonth.Text
    : myDay=TxtDay.Text
    :
    : If myYear.Length>4 then
    : 'Prompt to re-input the year.
    : MessageBox.Show("Please re-type the YEAR in.")
    : End IF
    :
    : If myMonth.Length>2 then
    : 'Prompt to re-input the month.
    : MessageBox.Show("Please re-type the MONTH in.")
    : End IF
    :
    : If myDay.Length>2 then
    : 'Prompt to re-input the day or date.
    : MessageBox.Show("Please re-type the DAY/DATE in.")
    : End IF
    :
    : [/code]
    :
    : Regards,
    :
    : Dr M.
    :
    :

  • or you could use standard error handling which is recomended in .net:

    [code]

    try
    ' your code
    catch ex as exception
    messagebox.show("Error...Not a number?", "Error")
    end try

    [/code]
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