3 Replies - 1319 Views - Last Post: 27 December 2012 - 09:54 PM Rate Topic: -----

#1 bloodzdevil  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 56
  • Joined: 12-June 10

extracting Substrings from Multiline textbox

Posted 27 December 2012 - 11:58 AM

Hi
I tried to extract some substrings from a multiline textbox using the Instr function, But it is not working...

Private Function GetBetween(ByVal Start As Long, Data As String, Startstr As String, Endstr As String) As String
    Dim lonstart As Long, lonend As Long
    lonstart = InStr(1, Data, StartString, vbTextCompare)
    MsgBox lonstart 'Not modifing Lonstart
    
    If lonstart > 0 Then
       
        lonstart = lonstart + Len(StartString)

        
        lonend = InStr(lonstart, Data, EndString, vbTextCompare)
        
        If lonend > 0 Then
            
            GetBetween = Mid$(Data, lonstart, lonend - lonstart)
        End If
    End If
    
End Function


As I have mentioned in between, When I output the Lonstart variable, all it gives is the value of Start variable.
Is there something wrong with the code? Is there any other way to do the task?

Is This A Good Question/Topic? 0
  • +

Replies To: extracting Substrings from Multiline textbox

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3522
  • View blog
  • Posts: 12,022
  • Joined: 12-December 12

Re: extracting Substrings from Multiline textbox

Posted 27 December 2012 - 01:10 PM

Your variables are named inconsistently: StartString, Startstr, EndString, Endstr. This is the first thing to correct. You should use Option Explicit to discover these errors.

Add Option Explicit On to the top of your module.

This post has been edited by andrewsw: 27 December 2012 - 01:13 PM

Was This Post Helpful? 0
  • +
  • -

#3 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: extracting Substrings from Multiline textbox

Posted 27 December 2012 - 09:18 PM

View Postandrewsw, on 27 December 2012 - 02:10 PM, said:

Your variables are named inconsistently: StartString, Startstr, EndString, Endstr. This is the first thing to correct. You should use Option Explicit to discover these errors.

Add Option Explicit On to the top of your module.

Correction: Add Option Explicit to the top of your module.
Was This Post Helpful? 0
  • +
  • -

#4 bloodzdevil  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 56
  • Joined: 12-June 10

Re: extracting Substrings from Multiline textbox

Posted 27 December 2012 - 09:54 PM

Problem Solved. Cant believe I didnt spot it :death: Thanks :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1