Results 1 to 4 of 4

Thread: how do i make a period instead of a comma if it's at the end of the textbox?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2002
    Posts
    121

    how do i make a period instead of a comma if it's at the end of the textbox?

    when one of my checkboxes is checked, it adds something to my textbox in the format "phrase." how do can i make the period turn into a comma then phrase and then a period (, phrase.) if it's the last item in the textbox?

    i've tried this and all i get is an infinite loop where the textbox keeps filling up with empty strings:

    Code:
    Private Sub ListTxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PreviewTxt.TextChanged
            Dim Flag As Boolean
            Flag = False
            If Flag = False Then PreviewTxt.Text = PreviewTxt.Text.Replace(".", ", ")
            If PreviewTxt.Text.EndsWith(".") = False Then
            PreviewTxt.Text += "."
            Flag = True
            End If
            End Sub
    (the flag was to try to avoid the infinite loop)

  2. #2
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322
    Instead of the Flag, try Exit Sub. I know tons of ppl out there will say both are ugly both they both work !
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

  3. #3
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322
    I see your problem...

    Your Flag was declared locally within the Sub and therefore loses scope after the End Sub and when your text changes again, your variable is re-initialized to FALSE all over again. In other words, your Flag will always be false when the flow goes into the routine. You therefore get an endless loop. Either declare the FLAG to be of a private scope within the form class or EXIT SUB to terminate the routine flow.
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

  4. #4
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322
    To deter the perfectionists out there criticizing , the FLAG doesnt just lose its scope, its life is terminated when the routine it is declared in is terminated. Therefore your FLAG will always be initialized as FALSE as you enter the routine again.

    Your local DIMension variable is the monkey wrench
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

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