Results 1 to 2 of 2

Thread: Error with Split Function

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    2

    Unhappy Error with Split Function

    Hi Guys,

    I am trying to split a string of integers but I keep getting this error:
    Index was outside the bounds of the array.

    Here is my code:

    VB Code:
    1. Public Shared Function picastopoints(ByVal sTemp)
    2.         'For example sTemp could equal 6p10
    3.  
    4.         Dim whole, remainder, convert, strInt
    5.         whole = Split(sTemp, "p", -1, 0)
    6.         strInt = whole(0)
    7.         remainder =whole(1)
    8.         convert = strInt * 12000 + remainder * 1000
    9.         Return convert
    10.     End Function

    Please Please Help..I dont know what I am doing wrong..

    Thanks!

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: Error with Split Function

    Here try this

    VB Code:
    1. Public Shared Function picastopoints(ByVal strTemp As String) As Integer
    2.         Dim strWhole() As String, intNum1 As Integer, intRemainder As Integer, intConvert As Integer
    3.         strWhole = Split(strTemp, "p")
    4.         intNum1 = CInt(strWhole(0))
    5.         intRemainder = CInt(strWhole(1))
    6.         intConvert = intNum1 * 12000 + intRemainder * 1000
    7.         Return intConvert
    8.     End Function
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width