Solved

Find a number then replace characters before it in a string

Posted on 2003-10-24
2
225 Views
Last Modified: 2010-05-01
Hello Gurus,

I have a textbox that contains something like "blablablabla777.JPG". I'm trying find the first number in that string and them replace whatever is before the first number with the text "slide", so that It would say "slide777.JPG".  For some reason, the code that I have finds the last number in "blablablabla777.JPG", then it replaces whatever is before that last "7" including the two 7s before it.  Here's the code:

Private Sub Command1_Click()
For i = 1 To 9
    pos = InStr(Text1.Text, i & ".JPG")

    If (pos <> 0) Then
        charsToReplace = Mid(Text1.Text, 1, pos - 1)
        Text1.Text = Replace(Text1.Text, charsToReplace, "slide")
        Exit Sub
    End If
Next i
End Sub


Can you guys please help?

Thanks in advance.

JH.
0
Comment
Question by:frankmorrison
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 250 total points
ID: 9616840
Private Sub Command1_Click()
Dim s As String
s = "blablablabla777.JPG"

For i = 1 To Len(s)
   If IsNumeric(Mid(s, i, 1)) Then
      s = Right(s, Len(s) - i + 1)
      Exit For
   End If
Next

s = "slide" & s
MsgBox s

End Sub
0
 
LVL 1

Author Comment

by:frankmorrison
ID: 9617035
Thanks a lot bobbit31!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question