Results 1 to 11 of 11

Thread: VB.NET: Extract day, month or year from the Listbox..[Unresolved]

  1. #1

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    VB.NET: Extract day, month or year from the Listbox..[Unresolved]

    Say I have these dates in the listbox...

    First Date: 10/2/2004
    Second Date: 12/4/2004

    but how to extract the "2" from the first date into the textbox..

    Since i need to display all the dates and from there the user will choose from any of the dates..

    lastly, the choosen day, month and year will be separately display into 3 textboxes...

    Is there any way to solve it or i should not use the listbox to do it...

    any suggestion..

    Thanks
    Last edited by toytoy; Jan 24th, 2005 at 01:24 AM.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    If I understand correctly what you need, you have to use Split method (using "/"c as separator) on the selected item.

    You will obtain a three elements string array that you can assign to your textbox as needed.

    Hope, this helps.
    Live long and prosper (Mr. Spock)

  3. #3

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    but i have already use the separator on the dates before displaying in the listbox to get "10/2/2004" and "12/4/2004"..

    how to use it again on the Selected Items...

    I don't understand how to use again..

    cboInfo.SelectedItem & "/" ?...

    Could you show some examples..

    And also that all the dates are display in one listbox only..

    and after chosen all are display in 3 different textboxes..

    Thanks
    Last edited by toytoy; Oct 22nd, 2004 at 05:32 AM.

  4. #4
    Lively Member
    Join Date
    Oct 2004
    Posts
    68
    You can use Month(), Day(), & Year() functions passing in the date in questions. This will extract the values you need.

    Looking further there doesn't seem to be a Day() function, but I'm sure it's called something else. Look in to it.

  5. #5
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Uhmmm....sorry dear friend Toytoy, now I'm sure I've not understand your problem. It often happens to me, because I should study english more seriously, but I've not sufficient time
    I hope our friend RickP, gave you what you need. Good job!
    Live long and prosper (Mr. Spock)

  6. #6

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    I solve it...

    Since the number that I want to extract is the Date so the coding should be...

    the blue part is what i want..

    Code:
    Private Sub lstListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstListBox1.SelectedIndexChanged 
    Try 
    Me.TextBox1.Text = Convert.ToDateTime(lstListBox1.SelectedItem.ToString).Date.Day 
    Me.TextBox2.Text = Convert.ToDateTime(lstListBox1.SelectedItem.ToString).Date.Month 
    Me.TextBox3.Text = Convert.ToDateTime(lstListBox1.SelectedItem.ToString).Date.Year
    Catch ex As Exception 
    End Try 
    End Sub
    Last edited by toytoy; Dec 3rd, 2004 at 07:54 AM.

  7. #7
    Lively Member
    Join Date
    Oct 2004
    Posts
    68
    I solve it...


    Did I at least point you in the right direction? That's usually my goal for every answer I give.

  8. #8

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    anyway.....

    thanks all of you for the suggestion.

  9. #9

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    Re: VB.NET: Extract day, month or year from the Listbox

    Say i have these dates:

    12-2-05......can
    12-12-05....can
    12-13-05....cannot
    12-22-05....cannot

    Refer to the above dates, why the below XML tag could not work well with days above "12"... when i send to server..
    I could only send 1,2,3,4,5,....up to 12 only.
    Code:
    "<" & "Date" & " " & "day=" & """" & Convert.ToDateTime(lst.SelectedItem.ToString).Date.Day & """" & " "    
    & "month=" & """" & Convert.ToDateTime(lst.SelectedItem.ToString).Date.Month & """" & " " & "year=" & """" 
    & Convert.ToDateTime(lst.SelectedItem.ToString).Date.Year & """" & " >" & _
    </" & "Date" & ">" & _
    The error message is:
    Code:
    Additional information: String was not recognized as a valid DateTime.
    Does anyone have better solution to solve it....

    Thanks
    Last edited by toytoy; Jan 24th, 2005 at 01:50 AM.

  10. #10

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    Re: VB.NET: Extract day, month or year from the Listbox..[Unresolved]

    For the above problem....

    I am not sure why if i use other set of computers with the same Visual Studio 2003, it works...

    how to update all the classes so that my computer could also be use..

  11. #11

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    Re: VB.NET: Extract day, month or year from the Listbox..[Unresolved]

    I find the problem is on the Format of the D/MM/YYYY...

    After i change the date format, it could work...

    Is there any way to format the date so that the program could works well in all computers without having to worry about whether the computer have set to the required date format.....

    Thanks

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