• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

Select Text between two points

Hello All,

VB6(sp5)

I need to select text between two points.

112344_123456.htm

The information between the underscore charactor ( _ ) and the period ( . ) charactor. The information between these points (HHHH-YY) are never the same length.

Thanks,.

ADawn
0
ADawn
Asked:
ADawn
1 Solution
 
vinnyd79Commented:
Private Sub Command1_Click()
Dim strExample As String, NewStr As String
strExample = "112344_123456.htm"

Dim pos1 As Integer, pos2 As Integer
pos1 = InStr(strExample, "_") + 1
pos2 = InStr(strExample, ".")

NewStr = Mid$(strExample, pos1, pos2 - pos1)

MsgBox NewStr

End Sub
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Option Explicit

Private Sub Command1_Click()
    Dim strInput As String
    Dim underscore As Integer
    Dim period As Integer
   
    Dim valueA As String
    Dim valueB As String
   
    strInput = "112344_123456.htm"
    underscore = InStr(strInput, "_")
    period = InStrRev(strInput, ".")
    If underscore > 0 And period > 0 And period > underscore Then
        valueA = Left(strInput, underscore - 1)
        valueB = Mid(strInput, underscore + 1, (period - underscore) - 1)
        MsgBox "valueA = " & valueA & vbCrLf & "valueB = " & valueB
    Else
        MsgBox "Invalid Input"
    End If
End Sub
0
 
GrahamSkanCommented:
Another way:

Private Sub Command1_Click()
Dim strExample As String, NewStr As String
strExample = "112344_123456.htm"

NewStr = split(split(strExample,"_")(1),".")(0)
MsgBox NewStr

End Sub
0
 
rajasachinCommented:

Hello Brother!!

Private Function GetWanted(ByVal StrSrc as String) as String
     GetWanted=Mid$(strSrc,InStr(strSrc, "_") + 1,InStr(strSrc, ".") - InStr(strSrc, "_") + 1)
End function

Copy this GetWanted in your code as it is and make a call for the same as :
strResult = GetWanted(112344_123456.htm)

Cheers!!!
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now