Ask Experts Questions for FREE Help !
Ask
    andirst's Avatar
    andirst Posts: 2, Reputation: 1
    New Member
     
    #1

    Jul 14, 2010, 08:26 PM
    Find and Replace text on text box in 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:000186350587 (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 :

    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.
    LTheobald's Avatar
    LTheobald Posts: 1,051, Reputation: 127
    Ultra Member
     
    #2

    Jul 14, 2010, 11:56 PM
    You need to figure out how long the text is and use that to create the 0's. I've not done much VB so this code may not be correct but try this. Instead of:

    Code:
    TextBox.Text = Replace(txt, ":25:", ":25:00")
    Insert this:
    Code:
    dim toAdd = 10 - (Len(txt)-4)
    dim zeros
    For i = 0 To toAdd
      zeros = zeros & "0"
    Next i
    TextBox.Text = Replace(txt, ":25:", ":25:" & zeros)
    That could be wrong but it gives you something to go from. Here's what it does line by line.
    Line 1: Create a variable containing how many zeros we need to add. It's the desired amount of numbers in total (10) minus the length of the string minus 4 (the length of ":25:").
    Line 2: Create a variable to hold the text containing our extra 0's
    Line 3: Loop for the amount of zeros we want to add
    Line 4: Append an extra 0 to the end of the zeros variable
    Line 5: Quit the loop
    Line 6: Perform the replacement with our string containing the extra zero's

    Hope that helps (and works!)
    LTheobald's Avatar
    LTheobald Posts: 1,051, Reputation: 127
    Ultra Member
     
    #3

    Jul 14, 2010, 11:57 PM
    Comment on LTheobald's post
    Better formatted code:

    dim toAdd = 10 - (Len(txt)-4)
    dim zeros
    For I = 0 To toAdd
    zeros = zeros & "0"
    Next I
    TextBox.Text = Replace(txt, ":25:", ":25:" & zeros)
    andirst's Avatar
    andirst Posts: 2, Reputation: 1
    New Member
     
    #4

    Jul 15, 2010, 12:24 AM
    Thanks LThebald
    It give me some new perspective.

    Andi

    FYI
    This is the link of my complete program and sample data that I want to change
    http://docs.google.com/leaf?id=0B8HOcoYLae3IMTU5YjMxNjUtNjg3MS00MjQwLTkwZ mUtNjI2M2ZiMDNkMmM2&sort=name&layout=list&num=50

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Excel 15 digit issue, tried converting to text, text to column feature negates fix [ 6 Answers ]

I have the following numbers that exceed 15 characters that needs to be split into its own columns. Down the road, there would be thousands of such rows of data with the first couple set of unique numbers. 890432453253208820,5004500558,05CC,1,0,0,0,0,0,0, 0000,5.0000,2007-01-11...

How can I get a 9-digit numeric datapoint to format as text, and link up to text [ 2 Answers ]

How can I get a 9-digit numeric datapoint to format as text, and link up to text? I was able to convert a column of 9-digit Social Security Numbers to 9-digit text, but they don't link up to =if statetments as I try to match them up. Thanks for your help

List box to text box one by one in vb6 [ 1 Answers ]

I am working with vb6 & I am novice too. I have 5 text boxes and only one list box and I want to select list from list box to text box one after another. It is a single list only to text box. With advanced thanks S. Jeyaraman


View more questions Search