Results 1 to 11 of 11

Thread: Subscript out of Range? What does that mean?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    148

    Subscript out of Range? What does that mean?

    When I run this code:

    VB Code:
    1. Dim S As String
    2. S = wb.Document.body.innerHTML
    3.  
    4.  
    5.  If TempPass Then
    6.                             v = Split(S) ', vbNewLine)
    7.                                 For Each w In v
    8.                                     w = Split(w, "=")
    9.                         'Debug.Print w(0), w(1)
    10.                         If w(0) = "username" Then Form1.username.Text = w(1)
    11.                 Next
    12.  
    13.                             Form18.Hide
    14.                             Form1.Show
    15.                
    16.         End If

    on a webpage that looks like this

    Code:
    level=4
    [email protected]
    first_name=Dave
    last_name=Machews
    When in debugging mode, the W = "" for some reason and I get a subscript out of range...what does that mean?

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Subscript out of Range? What does that mean?

    How do you declare w?
    Also..
    Code:
    ThisMustBeAnArray = Split(ThisMustBeString, "=")
    String declaration:
    Dim s As Atring

    Array Declaration (String Array):
    Dim MyArray() As Atring

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    148

    Re: Subscript out of Range? What does that mean?

    Dim S As String, v As Variant, w As Variant

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Subscript out of Range? What does that mean?

    Its because your setting the same array as your trying to split from.
    VB Code:
    1. [b]w[/b] = Split([b]w[/b], "=")
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Subscript out of Range? What does that mean?

    Quote Originally Posted by takamine334
    v = Split(S) ', vbNewLine)
    Why did you comment the vbNewLine part?

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    148

    Re: Subscript out of Range? What does that mean?

    but it works until the last time when it makes w=""

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    148

    Re: Subscript out of Range? What does that mean?

    what should it be?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    148

    Re: Subscript out of Range? What does that mean?

    Quote Originally Posted by jcis
    Why did you comment the vbNewLine part?
    because the code doesn't work with vbNewLine in...

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    148

    Re: Subscript out of Range? What does that mean?

    Quote Originally Posted by RobDog888
    Its because your setting the same array as your trying to split from.
    VB Code:
    1. [b]w[/b] = Split([b]w[/b], "=")
    that doesn't seem to be the problem. It splits it fine, it just seems to be putting a w="" after the last line for some reason

  10. #10
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Subscript out of Range? What does that mean?

    v = Split(S) ', vbNewLine)
    For Each w In v
    w = Split(w, "=")
    'Debug.Print w(0), w(1)
    If w(0) = "username" Then Form1.username.Text = w(1)
    why are you using the same variable in all the places
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  11. #11
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Subscript out of Range? What does that mean?

    For Each w In v ?, usually used for collections.

    You should use a For Next statement plus what is the value of "S" before you split because at the moment you are splitting at default which is a space and try to avoid variants

    Dim S As String, v() As String, w() As String

    casey.

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