Results 1 to 13 of 13
  1. #1
    nguyenak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    23

    Split Function Error Handling

    Hi,



    I link an csv file to Microsoft Sccess and wanted to create a module to do the following.

    1. Extract the first url
    2. Extract the second url

    ColumnA(Page) - From CSV File
    1. /www.thisite.com/audio-visual/,http://download.thisite.com2. /www.thisite.com/audio-visual/amps/series/product/

    ColumnB (Clicked Page)
    Function ClickedPage(sPage As String) As String
    ClickedPage = Split(Page, ",")(0)
    End Function

    ColumnC (EndPage)
    Function EndPage(sPage As String) As String
    EndPage = Split(Page, ",")(1)
    End Function

    Problem
    I keep getting an error for EndPage for situation where
    /www.thisite.com/audio-visual/amps/series/product/

    How do I modify the Function EndPage so that

    If Split(Page, ",")(1) is empty, then "" .
    Else EndPage = Split(Page, ",")(1)

    I keep getting the error message "Subscript Out of Range"

  2. #2
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    extracting one page at a time? what for? why not just put the strings into an array and write a loop after it?

    Code:
    dim pages() as string
    pages = split(pagestring, ",")
    
    for i = 0 to ubound(page())
      'do
    next i
    is there something special about each url placement in the array? if you can sequence them it or patternize them, you can do the code looping and forget about the static code you're using now and extracting strings from specific parts of the array.

  3. #3
    nguyenak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    23
    Hi,

    Answers to question:
    1. is there something special about each url placement in the array?
    A: Yes, the first URL in the string represents the clicked Page.
    The second URL represents the OutgoingLink. I only need the first 2 URLs. When I export from the analytics tool, its one string and I wanted to extract only specific parts of the array. Unfortunately, the string is not always clean and can have no deliminiters. For those situations, I dont need those parts.

    2. For the above code, where do I put that in?
    Basically, I wanted to extract the first part of the array, and the second part

    thanks for your help!

  4. #4
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    well if the delimiter is not consistent, you're screwed. there's nothing you can do about that.

    if the delimiter IS consistent however, use the above code and loop from 0 to 1 only. assign both array vals to whatever you want. that simple.!

  5. #5
    nguyenak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    23
    Ok, so lets say it is consistent. Im not sure how the function looks. (Im sorry, Im a beginner learning on the fly)

    Lets say its only to loop from 0 to 1. I've attached the access file.
    Attached Files Attached Files

  6. #6
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    ok, well aside from accessing the data, here is the coding:

    Code:
    public function getArrayStrings()
    
    dim i as integer
    dim arr() as string
    
    arr = split(yourdata)
    
    for i = 0 to 1
      'do something with the data
    next i
    
    end function
    the rest you never specified on. e.g. - what to do with the data!!

  7. #7
    nguyenak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    23
    2 Examples

    Sheet1_result

    Column (export) - These are the strings I import from CSV.
    Column (Array0) - this is the value I want to extract from the string (from Column (export))
    Column (Array1) - this is the value I want to extract from the string (from Column (export))

    If there is no data for Array, then the field will be ""

    Example2
    Field 1 = Imported Fields from CSV
    Field 2 = need a function to extract Array1
    Field 3 = need a function to extract Array2

    If it is an empty array, then it will be ""

    When I use the Split Function in my previous code(mine, not the one you gave me), I keep getting this error message and it goes to debug.

    I know you're doing the right thing, but Im not able to make it work for me.
    Attached Files Attached Files

  8. #8
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    well without seeing the code you're using, I can't do anything else for you. post it.

  9. #9
    nguyenak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    23
    Attached is the DB.

    Basically, the query shows "errors" and was hoping it would be NULL.

    I really do appreciate your efforts!
    Attached Files Attached Files

  10. #10
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You functions that you showed in your initial posts contain errors. You don't apply the Split function to the input argument - there is an "S" missing. they should read:

    Function ClickedPage(sPage As String) As String
    ClickedPage = Split(sPage, ",")(0)
    End Function

    and

    Function EndPage(sPage As String) As String
    EndPage = Split(sPage, ",")(1)
    End Function

    does that change things?

    John

  11. #11
    nguyenak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    23
    Hi John,

    I already corrected it. Basically, Im hoping to get another approach so that an empty array is "" instead of "Error"(The "Subscript out of Range" appears) and the DB becomes too slow. I have over 100K Patterns like this.

    But thank you for your response

    Quote Originally Posted by John_G View Post
    You functions that you showed in your initial posts contain errors. You don't apply the Split function to the input argument - there is an "S" missing. they should read:

    Function ClickedPage(sPage As String) As String
    ClickedPage = Split(sPage, ",")(0)
    End Function

    and

    Function EndPage(sPage As String) As String
    EndPage = Split(sPage, ",")(1)
    End Function

    does that change things?

    John

  12. #12
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    try changing this:

    EndPage = Split(sPage, ",")(1)

    to this

    endpage = ""
    EndPage = if ubound(Split(sPage, ",")) > 0 then EndPage = Split(sPage, ",")(1)

    That should eliminate the subscript error.

    John
    Last edited by John_G; 06-22-2012 at 03:54 PM. Reason: Correct the IF statement

  13. #13
    nguyenak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    23
    Here's the solution I found

    Function TSplit(varInput As Variant, intNr As Integer) As String
    Dim myArray() As String
    myArray = Split(Nz(varInput, ""), ":") 'Choose your delimiter', use NZ function to return ""
    TSplit= ""
    If intNr <= UBound(myArray) Then TSplit= myArray(intNr)
    End Function



    try changing this:

    EndPage = Split(sPage, ",")(1)

    to this

    endpage = ""
    EndPage = if ubound(Split(sPage, ",")) > 0 then EndPage = Split(sPage, ",")(1)

    That should eliminate the subscript error.

    John[/QUOTE]

Please reply to this thread with any new information or opinions.

Similar Threads

  1. On Error handling
    By rivereridanus in forum Access
    Replies: 2
    Last Post: 06-18-2012, 07:46 AM
  2. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 PM
  3. Error Handling
    By jgelpi16 in forum Programming
    Replies: 4
    Last Post: 09-14-2010, 12:17 PM
  4. Error Handling
    By trb5016 in forum Access
    Replies: 2
    Last Post: 08-10-2010, 08:37 AM
  5. #error handling
    By mws5872 in forum Access
    Replies: 4
    Last Post: 05-12-2010, 07:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums