Solved

Find a number then replace characters before it in a string

Posted on 2003-10-24
2
218 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
2 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 250 total points
Comment Utility
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
Comment Utility
Thanks a lot bobbit31!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now