Results 1 to 7 of 7

Thread: find date in string replace with new date

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    find date in string replace with new date

    i have a string for example:

    %X %N SHIP 3/30/2014

    i have a datetimepicker to choose the date, if i choose a date, it gets added to the string.

    i have a checkbox that if checked, it will add the date to the string

    but if i uncheck the checkbox, i would like to remove the date from the string or if i change the date in the datetimepicker i would like to change the date in the string.

    any suggestions?

    maybe with regex, but i don't know enough about regex to do it that way.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: find date in string replace with new date

    How about you always keep the root value, i.e. the text without the date, in another String variable? Whenever you need to change the current text, just copy that String, either as is or with the selected date appended.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: find date in string replace with new date

    hmmm. i will play with that idea, but it gets a little tricky because the user can manually enter text into the text box.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: find date in string replace with new date

    i will use two variables. one for the text with out the date and one for the date

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: find date in string replace with new date

    Quote Originally Posted by bezaman View Post
    hmmm. i will play with that idea, but it gets a little tricky because the user can manually enter text into the text box.
    So, are you saying that you are appending the date to the actual contents of the TextBox, i.e. the date is displayed in the TextBox? That is a bit flawed because the user could then add more text after the date and then you would be appending a second date.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: find date in string replace with new date

    exactly. but i think i got it working pretty good.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: find date in string replace with new date

    form load
    Code:
            Me.InfoLine2Text = Me.TextBoxInfoLine2.Text
            Me.InfoLine2Date = "SHIP " & Me.DateTimePickerDropDate.Text
            Me.CheckBoxUseDropDate.Checked = True
    Code:
        Private Sub DateTimePickerDropDate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePickerDropDate.ValueChanged
            Me.InfoLine2Date = "SHIP " & Me.DateTimePickerDropDate.Text
            If Me.CheckBoxUseDropDate.Checked = True Then
                Me.TextBoxInfoLine2.Text = Me.InfoLine2Text & " " & Me.InfoLine2Date
            End If
        End Sub
    Code:
        Private Sub CheckBoxUseDropDate_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxUseDropDate.CheckedChanged
            If Me.CheckBoxUseDropDate.Checked = True Then
                Me.TextBoxInfoLine2.Text = Me.InfoLine2Text & " " & Me.InfoLine2Date
            ElseIf Me.CheckBoxUseDropDate.Checked = False Then
                Me.TextBoxInfoLine2.Text = Me.InfoLine2Text
            End If
        End Sub

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