Find and replace text di vb6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Andi Rustandi
    New Member
    • Jul 2010
    • 9

    Find and replace text di vb6

    Hi All,

    I have some problem with vb6 code.
    I have a data contain :

    :25:0186350587
    :25:186350587
    :25:86350587
    :25:6350587
    :25:350587
    :25:50587
    :25:587
    :25:87
    :25:7

    I want it to insert zero number after :25: , but the number after :25: is always has to be 10 digit. So it would be :

    :25:0186350587
    :25:0186350587
    :25:0086350587
    :25:0006350587
    :25:0000350587
    :25:0000050587
    :25:0000000587
    :25:0000000087
    :25:0000000007

    I have a code in vb6 but it only insert two digit of zero number, so it would be :

    :25:00018635058 7 (more than 10 digit)
    :25:00186350587 (more than 10 digit)
    :25:0086350587 (10 digit)
    :25:006350587 (less than 10 digit)
    :25:00350587 (less than 10 digit)
    :25:0050587 (less than 10 digit)
    :25:00587 (less than 10 digit)
    :25:0087 (less than 10 digit)
    :25:007 (less than 10 digit)

    this is my code with textbox and command :

    Code:
    Private Sub cmdProses_Click()
    Dim txt
    txt = TextBox.Text
    If InStr(1, TextBox.Text, ":25:") > 0 Then
    TextBox.Text = Replace(txt, ":25:", ":25:00")
    End If
    End Sub
    Would you like to help me with the new code please

    Thank you
    Andi.

    FYI
    The link below is the complete of my program and the data that I want to change
    http://docs.google.com/leaf?id=0B8HOco YLae3IMTU5YjMxN jUtNjg3MS00MjQw LTkwZmUtNjI2M2Z iMDNkMmM2&sort= name&layout=lis t&num=50
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    I hope this will help You: (see also attachment)

    Code:
    Private Sub Command1_Click()
    Dim ARRAYTEXT1() As String
    Dim LINEidx As Integer
    Dim TEXT1LINE As String
    Dim TEXT1LINELAST As String
    Dim TEMPTEXT2 As String
       ARRAYTEXT1 = Split(Text1.Text, vbNewLine)
       For LINEidx = 1 To UBound(ARRAYTEXT1)
          TEXT1LINE = ARRAYTEXT1(LINEidx)
          TEXT1LINELAST = Mid(TEXT1LINE, 5)
          If InStr(TEXT1LINE, ":25:") Then
             If Len(TEXT1LINELAST) > 10 Then
                TEMPTEXT2 = Mid(TEXT1LINE, Len(TEXT1LINE) - 9)
             ElseIf Len(TEXT1LINELAST) = 10 Then
                TEMPTEXT2 = TEXT1LINELAST
             Else
                Select Case Len(TEXT1LINELAST)
                Case 1
                   TEMPTEXT2 = "000000000" & TEXT1LINELAST
                Case 2
                   TEMPTEXT2 = "00000000" & TEXT1LINELAST
                Case 3
                   TEMPTEXT2 = "0000000" & TEXT1LINELAST
                Case 4
                   TEMPTEXT2 = "000000" & TEXT1LINELAST
                Case 5
                   TEMPTEXT2 = "00000" & TEXT1LINELAST
                Case 6
                   TEMPTEXT2 = "0000" & TEXT1LINELAST
                Case 7
                   TEMPTEXT2 = "000" & TEXT1LINELAST
                Case 8
                   TEMPTEXT2 = "00" & TEXT1LINELAST
                Case 9
                   TEMPTEXT2 = "0" & TEXT1LINELAST
                End Select
             End If
          End If
          Text2.Text = Text2.Text & ":25:" & TEMPTEXT2 & vbNewLine
       Next
    End Sub
    PS:
    I can't download Your attachment with the program and the data.
    If necessary in the future, please ZIP it and attach it in Bytes.
    Attached Files

    Comment

    • vb5prgrmr
      Recognized Expert Contributor
      • Oct 2009
      • 305

      #3
      As on TWO other sites... "Format" it out...
      Code:
      Dim My1stArray() As String, My2ndArray() As String, S As String
      Dim LB As Integer, UB As Integer, LoopCnt As Integer
      
      S = ":25:0186350587,:25:186350587,:25:86350587,:25:6350587,:25:350587,:25:50587,:25:587,:25:87,:25:7"
      
      My1stArray = Split(S, ",")
      
      LB = LBound(My1stArray)
      UB = UBound(My1stArray)
      
      For LoopCnt = LB To UB
        
        My2ndArray = Split(My1stArray(LoopCnt), ":25:")
        Debug.Print ":25:" & Format(My2ndArray(1), "0000000000")
        
      Next LoopCnt


      Good Luck

      Comment

      • Andi Rustandi
        New Member
        • Jul 2010
        • 9

        #4
        Find and replace text di vb6

        But the number is not always just :

        ":25:0186350587 ,:25:186350587, :25:86350587,:2 5:6350587,:25:3 50587,:25:50587 ,:25:587,:25:87 ,:25:7"

        It can be :

        ":25:0006350007 ,:25:186350587, :25:86350587,:2 5:6350587,:25:3 50587,:25:50587 ,:25:587,:25:87 ,:25:7"

        Or :

        ":25:0006352207 ,:25:186236117, :25:86350587,:2 5:6324487,:25:3 50587,:25:50333 ,:25:587,:25:87 ,:25:4"

        and so on.

        Cause I knew in VB6 I can not understand what you are trying to explain.
        Maybe it will figure out by downloading the link at the above post.

        Thanks anyway
        Andi

        Comment

        • vb5prgrmr
          Recognized Expert Contributor
          • Oct 2009
          • 305

          #5
          Put the code in form_load and press F8 to walk through... Look at the debug window to see the results...



          Good Luck

          Comment

          • Guido Geurs
            Recognized Expert Contributor
            • Oct 2009
            • 767

            #6
            Is it possible to attach Your document in BYTES?
            I get an error on Your URL link !!!

            "Sorry, the page (or document) you have requested is not available.
            Please check the address and try again."

            Comment

            • Guido Geurs
              Recognized Expert Contributor
              • Oct 2009
              • 767

              #7
              This is an example with "Format".
              You will see : it works for the numbers in your mail which I have placed in a TextBox to test the algorithm.

              If You want an example of a program with Your original datafile, please attach it in BYTES because I'm not able to download it with Your URL.
              Attached Files

              Comment

              • Andi Rustandi
                New Member
                • Jul 2010
                • 9

                #8
                Dear all,

                Finally I know why my code and your code can never be executed, the user does not ever mention that in the search string that exists between two strings. I will be working on this code to start all over again. Thanks for all your help, I really appreciate it. I'll be back again if need your help. Once again thank you all.

                Thanks,
                Andi

                Comment

                • Andi Rustandi
                  New Member
                  • Jul 2010
                  • 9

                  #9
                  Hi again All,

                  This is what I've figure out :

                  If between ":25:" and ":28:" there is 10 character e.g 0123456789 then do nothing
                  If between ":25:" and ":28:" there is 9 character e.g 12345678 then replace ":25:" with ":25:0"
                  If between ":25:" and ":28:" there is 8 character e.g 12345678 then replace ":25:" with ":25:00"
                  If between ":25:" and ":28:" there is 7 character e.g 1234567 then replace ":25:" with ":25:000"
                  and so on.

                  So is there a code related to my problem?

                  Thanks
                  Andi

                  Comment

                  • Guido Geurs
                    Recognized Expert Contributor
                    • Oct 2009
                    • 767

                    #10
                    Is it possible to attach your document (mentioned in your first call) in BYTES so we can see with what we are starting ?

                    Comment

                    • Andi Rustandi
                      New Member
                      • Jul 2010
                      • 9

                      #11
                      I am sorry but I can't attach anything because all blocked by office proxy.

                      Regards
                      Andi

                      Comment

                      • Guido Geurs
                        Recognized Expert Contributor
                        • Oct 2009
                        • 767

                        #12
                        Can You download from this address (from your first call)?



                        Because I get an error ! = "Sorry, the page (or document) you have requested is not available"

                        Is it shared on Google ? = " Anyone with the link
                        Anyone who has the link can access. No sign-in required. "

                        Because I have a file shared on Google and the address is different !

                        Comment

                        • Andi Rustandi
                          New Member
                          • Jul 2010
                          • 9

                          #13
                          Maybe this link will work

                          Comment

                          • Guido Geurs
                            Recognized Expert Contributor
                            • Oct 2009
                            • 767

                            #14
                            Originally posted by Andi Rustandi
                            This one is OK.
                            The data is in UNIX format (only Linefeed)!
                            Can I change it to DOS format (CrLF) ?

                            Comment

                            • Guido Geurs
                              Recognized Expert Contributor
                              • Oct 2009
                              • 767

                              #15
                              I think this will do the job=

                              Code:
                              Private Sub cmdProses_Click()
                              Dim ARRAYTEXT() As String
                              Dim ARRAYTEXTidx As Integer
                                 ARRAYTEXT = Split(TextBox.Text, vbCrLf)
                                 TextBox.Text = ""
                                 For ARRAYTEXTidx = LBound(ARRAYTEXT) To UBound(ARRAYTEXT) - 1
                                    If (Left(ARRAYTEXT(ARRAYTEXTidx), 4) = ":25:" Or _
                                          Left(ARRAYTEXT(ARRAYTEXTidx), 4) = ":28:") And _
                                          Len(Mid(ARRAYTEXT(ARRAYTEXTidx), 5)) < 10 Then
                                       TextBox.Text = TextBox.Text & Left(ARRAYTEXT(ARRAYTEXTidx), 4) & _
                                          Format(Mid(ARRAYTEXT(ARRAYTEXTidx), 5), "0000000000") & vbCrLf
                                    Else
                                       TextBox.Text = TextBox.Text & ARRAYTEXT(ARRAYTEXTidx) & vbCrLf
                                    End If
                                 Next
                              End Sub
                              PS:
                              I had also so questions with Your code:
                              - Why "New" in the menu when You will open a new file or Exit?
                              - Why "Close" button when You have "Exit" in the menu ?

                              I have taken the liberty to do some modifications (see attachment).
                              So if You want to use them, be my guest.
                              Attached Files

                              Comment

                              Working...