locked
store 23:23:30 in a variable RRS feed

  • Question

  • hello ,
    i have 23:23:30 in a texbox and i like to store this in a variable ,
    if i put a variable m1 as decimal, i have a message error,
    if i put string , i have 0 and not 23:23:30,
    why? thx
    Tuesday, April 14, 2009 9:40 AM

Answers

All replies

  • Try this:

    Dim x As String = TextBox1.Text.ToString


    Doug
    Tuesday, April 14, 2009 9:43 AM
  • Since its a date object you can use a DateTime object as

    Dim dt As DateTime = DateTime.Parse(TextBox1.Text)
    Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
    Tuesday, April 14, 2009 10:00 AM
  • you can use string datatype for storing this text.
    For eg ;

     

    string str;

    str = textBox1.Text; 


    MessageBox
    .Show(str);


    Regards,
    Jayakumar Natarjan
    Click Here :Blog


    [Click as Answer if my post is Useful]

     

     

     

    • Marked as answer by keithsize Tuesday, April 14, 2009 10:57 AM
    Tuesday, April 14, 2009 10:06 AM
  • thx a lot,
    i use string because in this memory they will be stocked 00:00:00 format and decimal number...
    Tuesday, April 14, 2009 10:07 AM
  • Are you still in need of help with this or has your question been answered?  If you still need some help with it, post the code you're having problems with so we can help you find a solution.


    Doug
    Tuesday, April 14, 2009 10:48 AM
  • its ok thx a lot
    Tuesday, April 14, 2009 10:57 AM
  • why u mark anser of C# when u queston for vb.net ?  u have 2 post show how to do in vb.net !
    O
    m
    a
    r
    Tuesday, April 14, 2009 11:15 AM
  • Try this:

    Dim x As String = TextBox1.Text.ToString


    Doug

    Where is the need of converting TextBox1.Text to string
    Asgar
    Tuesday, April 14, 2009 11:43 AM
  •         TextBox1.Text = "23:23:30"
            Dim dt As DateTime 'will hold datetime
            Dim dtAsNum As Long 'the datetime as a number
            If DateTime.TryParse(TextBox1.Text, dt) Then 'validate user input
    
                dtAsNum = dt.ToBinary 'convert datetime to a number
    
                dt = DateTime.FromBinary(dtAsNum) 'convert number to datetime
    
                TextBox1.Text = dt.TimeOfDay.ToString() 'back to string
                'at this point TextBox1 should be identical
            Else
                'user input in TextBox1.Text is not a time value
            End If
    
    @DR1 - There is no need for .ToString in the following statement.  The .Text property of a TextBox is a String
    Dim x As String = TextBox1.Text.ToString

    What your statement says is convert the String TextBox1.Text to a String.

    Looking for work - Zip 65101 http://www.vbforums.com/showthread.php?t=552774
    Tuesday, April 14, 2009 1:12 PM
  • I am confused by your response.  When you say things like "...added insurance..." you seem to be saying that
    dim s as String = Textbox1.Text might fail and that by adding .ToString it might work.

    This Dim x As String = TextBox1.Text.ToString looks like there is a general misunderstanding.  I'd rank it with

    Dim B as Boolean = True

    ...

    If B = True Then

    Looking for work - Zip 65101 http://www.vbforums.com/showthread.php?t=552774
    Tuesday, April 14, 2009 3:41 PM
  • dbasnett ,   you never hear of you langage "cover all bases" ?    try eveything obvious and if it fail u know ur problem in other place.   <smile>

    O
    m
    a
    r
    Wednesday, May 6, 2009 10:46 AM