Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Find a number then replace characters before it in a string

Posted on 2003-10-24
2
Medium Priority
?
227 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Suggested Courses

604 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