|
-
Jul 14th, 2010, 11:10 PM
#1
Thread Starter
New Member
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: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.
-
Jul 15th, 2010, 02:43 AM
#2
New Member
Re: Find and replace text di vb6
Oho ! try this one dear
Code:
Private Sub Command1_Click()
Dim txt As String
txt = TextBox.Text
txt = (Format(Mid(txt, 5, 10), "0000000000")) ' use format() & Mid() command
TextBox.Text = ":25:" & txt
End Sub
Last edited by ahsan_ali; Jul 15th, 2010 at 02:51 AM.
-
Jul 15th, 2010, 03:02 AM
#3
Thread Starter
New Member
Re: Find and replace text di vb6
It does not work.
FYI this link is the complete of my program along with sample text that I want to edit
http://docs.google.com/leaf?id=0B8HO...ut=list&num=50
Thanks
Andi
-
Jul 15th, 2010, 04:23 AM
#4
Re: Find and replace text di vb6
Thread moved from the 'CodeBank VB6' forum (which is for you to post working code examples, not questions) to the 'VB6 and earlier' forum
-
Jul 16th, 2010, 01:21 AM
#5
New Member
Re: Find and replace text di vb6
 Originally Posted by andirst
Andi,
Your above link is http://docs.google.com/leaf?id=0B8HO...ut=list&num=50 does not contain any sample. Please, attach your sample file here to let me know what is your motive
-
Jul 16th, 2010, 02:37 AM
#6
Thread Starter
New Member
Re: Find and replace text di vb6
Somehow I can not upload the sample here, but I have another Link to my sample VB6
http://365files.com/6hd0b88aamzk/Rep...ext_4.zip.html
Thanks
Andi
-
Jul 16th, 2010, 05:32 AM
#7
Re: Find and replace text di vb6
what does this mean?
i tried like this after copying the data (ctrl C) from the original post
vb Code:
myarr = Split(Clipboard.GetText, vbNewLine) For i = 0 To UBound(myarr) myarr(i) = Left(myarr(i), 4) & Format(Mid(myarr(i), 5), "0000000000") Next Debug.Print Join(myarr, vbNewLine)
result
Code:
:25:0186350587
:25:0186350587
:25:0086350587
:25:0006350587
:25:0000350587
:25:0000050587
:25:0000000587
:25:0000000087
:25:0000000007
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 16th, 2010, 05:41 AM
#8
Re: Find and replace text di vb6
Here's another way that does not rely on the clipboard, akthough I think westconns is more elegant.
Code:
Dim A$(8), I As Integer, X As Integer
A$(0) = ":25:0186350587"
A$(1) = ":25:186350587"
A$(2) = ":25:86350587"
A$(3) = ":25:6350587"
A$(4) = ":25:350587"
A$(5) = ":25:50587"
A$(6) = ":25:587"
A$(7) = ":25:87"
A$(8) = ":25:7"
For I = 0 To 8
Print Left$(A$(I), 4) & String$(14 - Len(A$(I)), "0") & Mid$(A$(I), 5)
Next I
-
Jul 16th, 2010, 05:46 AM
#9
Re: Find and replace text di vb6
i assumed the data comes from some file, so substituting an array from file input is quite similar to the result from clipboard
and i was lazy to type in 8 lines of data
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 18th, 2010, 08:05 PM
#10
Thread Starter
New Member
Re: Find and replace text di vb6
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.
Warm regards
Andi
-
Jul 18th, 2010, 10:17 PM
#11
Thread Starter
New Member
Re: Find and replace text di vb6
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.
is it possible to do it wit InStr?
-
Jul 19th, 2010, 04:29 AM
#12
Re: Find and replace text di vb6
Code:
Dim A$(8), I As Integer
A$(0) = ":25:0186350587"
A$(1) = ":28:186350587"
A$(2) = ":29:86350587"
A$(3) = ":30:6350587"
A$(4) = ":25:350587"
A$(5) = ":25:50587"
A$(6) = ":25:587"
A$(7) = ":25:87"
A$(8) = ":25:7"
For I = 0 To 8
If val(Mid$(A$(I),2))>24 and val(Mid$(A$(I),2))<29 then
Debug.Print Left$(A$(I), 4) & String$(14 - Len(A$(I)), "0") & Mid$(A$(I), 5)
end if
Next I
I have tested the code above and I hope I've understood your requirements.
Last edited by Steve Grant; Jul 19th, 2010 at 04:34 AM.
Reason: Forced the Print to the Debug window
-
Jul 19th, 2010, 04:38 AM
#13
Re: Find and replace text di vb6
the user does not ever mention that in the search string that exists between two strings.
i do not understand this at all
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 19th, 2010, 08:27 AM
#14
Frenzied Member
Re: Find and replace text di vb6
and still I bet OP has not tried this code...
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
Option Explicit should not be an Option!
-
Jul 19th, 2010, 09:27 PM
#15
Thread Starter
New Member
Re: Find and replace text di vb6
the user does not ever mention that in the search string that exists between two strings.
I mean They don't even mention that I have to find the length of the text between two string.
For example I have a data contain :
:25:0123456789:28:abcdef:25:123456789:28:defgh:25:12345678:28:ijklm:25:1234567:28:
if between ":25:" and ":28:" there is 10 char e.g 0123456789 then do nothing or
if between ":25:" and ":28:" there is 9 char e.g 123456789 then insert 0 after ":25:" or
if between ":25:" and ":28:" there is 8 char e.g 12345678 then insert 00 after ":25:" or
if between ":25:" and ":28:" there is 7 char e.g 1234567 then insert 000 after ":25:"
so the result will be
:25:0123456789:28:abcdef:25:0123456789:28:defgh:25:0012345678:28:ijklm:25:0001234567:28:
Your code works fine but how about my new problem?
Thanks for your kindness
Andi
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|