473,387 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 :

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdProses_Click()
  2. Dim txt
  3. txt = TextBox.Text
  4. If InStr(1, TextBox.Text, ":25:") > 0 Then
  5. TextBox.Text = Replace(txt, ":25:", ":25:00")
  6. End If
  7. End Sub
  8.  
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=0B8HOcoYLae3IMTU5YjMxNjUtNjg3MS00MjQwLTkwZ mUtNjI2M2ZiMDNkMmM2&sort=name&layout=list&num=50
Jul 15 '10 #1

✓ answered by Guido Geurs

I think this will do the job=

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdProses_Click()
  2. Dim ARRAYTEXT() As String
  3. Dim ARRAYTEXTidx As Integer
  4.    ARRAYTEXT = Split(TextBox.Text, vbCrLf)
  5.    TextBox.Text = ""
  6.    For ARRAYTEXTidx = LBound(ARRAYTEXT) To UBound(ARRAYTEXT) - 1
  7.       If (Left(ARRAYTEXT(ARRAYTEXTidx), 4) = ":25:" Or _
  8.             Left(ARRAYTEXT(ARRAYTEXTidx), 4) = ":28:") And _
  9.             Len(Mid(ARRAYTEXT(ARRAYTEXTidx), 5)) < 10 Then
  10.          TextBox.Text = TextBox.Text & Left(ARRAYTEXT(ARRAYTEXTidx), 4) & _
  11.             Format(Mid(ARRAYTEXT(ARRAYTEXTidx), 5), "0000000000") & vbCrLf
  12.       Else
  13.          TextBox.Text = TextBox.Text & ARRAYTEXT(ARRAYTEXTidx) & vbCrLf
  14.       End If
  15.    Next
  16. 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.

18 3087
Guido Geurs
767 Expert 512MB
I hope this will help You: (see also attachment)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim ARRAYTEXT1() As String
  3. Dim LINEidx As Integer
  4. Dim TEXT1LINE As String
  5. Dim TEXT1LINELAST As String
  6. Dim TEMPTEXT2 As String
  7.    ARRAYTEXT1 = Split(Text1.Text, vbNewLine)
  8.    For LINEidx = 1 To UBound(ARRAYTEXT1)
  9.       TEXT1LINE = ARRAYTEXT1(LINEidx)
  10.       TEXT1LINELAST = Mid(TEXT1LINE, 5)
  11.       If InStr(TEXT1LINE, ":25:") Then
  12.          If Len(TEXT1LINELAST) > 10 Then
  13.             TEMPTEXT2 = Mid(TEXT1LINE, Len(TEXT1LINE) - 9)
  14.          ElseIf Len(TEXT1LINELAST) = 10 Then
  15.             TEMPTEXT2 = TEXT1LINELAST
  16.          Else
  17.             Select Case Len(TEXT1LINELAST)
  18.             Case 1
  19.                TEMPTEXT2 = "000000000" & TEXT1LINELAST
  20.             Case 2
  21.                TEMPTEXT2 = "00000000" & TEXT1LINELAST
  22.             Case 3
  23.                TEMPTEXT2 = "0000000" & TEXT1LINELAST
  24.             Case 4
  25.                TEMPTEXT2 = "000000" & TEXT1LINELAST
  26.             Case 5
  27.                TEMPTEXT2 = "00000" & TEXT1LINELAST
  28.             Case 6
  29.                TEMPTEXT2 = "0000" & TEXT1LINELAST
  30.             Case 7
  31.                TEMPTEXT2 = "000" & TEXT1LINELAST
  32.             Case 8
  33.                TEMPTEXT2 = "00" & TEXT1LINELAST
  34.             Case 9
  35.                TEMPTEXT2 = "0" & TEXT1LINELAST
  36.             End Select
  37.          End If
  38.       End If
  39.       Text2.Text = Text2.Text & ":25:" & TEMPTEXT2 & vbNewLine
  40.    Next
  41. 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
File Type: zip Find and replace text di vb6_v1.zip (1.9 KB, 96 views)
Jul 15 '10 #2
vb5prgrmr
305 Expert 100+
As on TWO other sites... "Format" it out...
Expand|Select|Wrap|Line Numbers
  1. Dim My1stArray() As String, My2ndArray() As String, S As String
  2. Dim LB As Integer, UB As Integer, LoopCnt As Integer
  3.  
  4. S = ":25:0186350587,:25:186350587,:25:86350587,:25:6350587,:25:350587,:25:50587,:25:587,:25:87,:25:7"
  5.  
  6. My1stArray = Split(S, ",")
  7.  
  8. LB = LBound(My1stArray)
  9. UB = UBound(My1stArray)
  10.  
  11. For LoopCnt = LB To UB
  12.  
  13.   My2ndArray = Split(My1stArray(LoopCnt), ":25:")
  14.   Debug.Print ":25:" & Format(My2ndArray(1), "0000000000")
  15.  
  16. Next LoopCnt
  17.  


Good Luck
Jul 15 '10 #3
But the number is not always just :

":25:0186350587,:25:186350587,:25:86350587,:25:635 0587,:25:350587,:25:50587,:25:587,:25:87,:25:7"

It can be :

":25:0006350007,:25:186350587,:25:86350587,:25:635 0587,:25:350587,:25:50587,:25:587,:25:87,:25:7"

Or :

":25:0006352207,:25:186236117,:25:86350587,:25:632 4487,:25:350587,: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
Jul 16 '10 #4
vb5prgrmr
305 Expert 100+
Put the code in form_load and press F8 to walk through... Look at the debug window to see the results...



Good Luck
Jul 16 '10 #5
Guido Geurs
767 Expert 512MB
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."
Jul 16 '10 #6
Guido Geurs
767 Expert 512MB
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
File Type: zip Find and replace text di vb6_with format_v2.zip (5.7 KB, 97 views)
Jul 16 '10 #7
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
Jul 19 '10 #8
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
Jul 19 '10 #9
Guido Geurs
767 Expert 512MB
Is it possible to attach your document (mentioned in your first call) in BYTES so we can see with what we are starting ?
Jul 19 '10 #10
I am sorry but I can't attach anything because all blocked by office proxy.

Regards
Andi
Jul 20 '10 #11
Guido Geurs
767 Expert 512MB
Can You download from this address (from your first call)?

http://docs.google.com/leaf?id=0B8HO...ut=list&num=50

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 !

http://docs.google.com/leaf?id=0BzRq...thkey=CL_zhPkJ
Jul 20 '10 #12
Guido Geurs
767 Expert 512MB
@Andi Rustandi
This one is OK.
The data is in UNIX format (only Linefeed)!
Can I change it to DOS format (CrLF) ?
Jul 20 '10 #14
Guido Geurs
767 Expert 512MB
I think this will do the job=

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdProses_Click()
  2. Dim ARRAYTEXT() As String
  3. Dim ARRAYTEXTidx As Integer
  4.    ARRAYTEXT = Split(TextBox.Text, vbCrLf)
  5.    TextBox.Text = ""
  6.    For ARRAYTEXTidx = LBound(ARRAYTEXT) To UBound(ARRAYTEXT) - 1
  7.       If (Left(ARRAYTEXT(ARRAYTEXTidx), 4) = ":25:" Or _
  8.             Left(ARRAYTEXT(ARRAYTEXTidx), 4) = ":28:") And _
  9.             Len(Mid(ARRAYTEXT(ARRAYTEXTidx), 5)) < 10 Then
  10.          TextBox.Text = TextBox.Text & Left(ARRAYTEXT(ARRAYTEXTidx), 4) & _
  11.             Format(Mid(ARRAYTEXT(ARRAYTEXTidx), 5), "0000000000") & vbCrLf
  12.       Else
  13.          TextBox.Text = TextBox.Text & ARRAYTEXT(ARRAYTEXTidx) & vbCrLf
  14.       End If
  15.    Next
  16. 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
File Type: zip Find and replace text di vb6_with format_v6.zip (13.8 KB, 80 views)
Jul 20 '10 #15
Expand|Select|Wrap|Line Numbers
  1. PS:
  2. I had also so questions with Your code:
  3. - Why "New" in the menu when You will open a new file or Exit?
  4. - Why "Close" button when You have "Exit" in the menu ?
Some time user want to have button to click but another user feel more comfortable with drop down menu.
But anyway thanks for the modification, it bring me new idea for the program.

Best Regards
Andi
Jul 21 '10 #16
Guido Geurs
767 Expert 512MB
I have done some cleanup and modifications (see attachment)

PS: if the text must put back to UNIX format: add a command with:
Expand|Select|Wrap|Line Numbers
  1. textbox.text=replace(textbox.text,vbcrlf,vblf)
Attached Files
File Type: zip Find and replace text di vb6_v7.zip (17.7 KB, 78 views)
Jul 21 '10 #17
@ggeu
Thanks ggeu,

It really works, you are doing great job.

Thanks Again,
Andi
Jul 21 '10 #18
Best Answer I've ever have

Great Job
http://docs.google.com/leaf?id=0B8HO...YzhmODMy&hl=in

Andi
Jul 22 '10 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Svennglenn | last post by:
I'm having problems replacing text in a unicode string. Here's the code: # -*- coding: cp1252 -*- titel = unicode("ä", "iso-8859-1") print titel print type(titel)
4
by: JackRazz | last post by:
I'm trying to use Visual Studio's Find/Replace to match VB declarations. This RegEx works fine in Regulator: ...
2
by: :\\\\derian | last post by:
anyone know where i could find the equivalent of the find / replace windows control for my project? :\\derian
2
by: scorpion53061 | last post by:
This excel find/replace code works great under Excel 2003 but bombs with an error (pasted below the code) in Excel 2000. Can anyone suggest an alternative to make both happy? I am using vb.net...
1
by: Mark | last post by:
Hello, Can anyone help me on how to find and replace text within a .txt file using vb.net? Any help would be greatly appreciated! Thanks in advance.
0
by: D Brown | last post by:
Does anyone know why my .NET development would hang / freeze when performing a Global Find / Replace on all files? I have a large ASP.NET VB Application. I have left the machine for 24 hours but...
5
by: Casey | last post by:
Hello, Can someone give me specific code to replace text on a page using server side javascript? I need to use server-side because I need the output to be recognized in the final HTML so that...
2
by: cewyattjr | last post by:
In a mediumtext field I have many instances of a URL, eg: 'http://myurl.com/index.php' that I want to replace with just '/' How can I write an update query that will update all instances of the...
8
by: John Pye | last post by:
Hi all I have a file with a bunch of perl regular expressions like so: /(^|)\*(.*?)\*(|$)/$1'''$2'''$3/ # bold /(^|)\_\_(.*?)\_\_(|$)/$1''<b>$2<\/ b>''$3/ # italic bold...
1
by: Lengara | last post by:
I have an Access form that will be FTPing information. The FTP info will be using a text file located on the hard drive. This text file will have symbolics in it that will be replaced by entries on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.