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.
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)