Solved

Find a number then replace characters before it in a string

Posted on 2003-10-24
2
224 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

737 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