What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Visual Basic Help

Visual Basic Help
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Visual Basic Help
quote:
Originally posted by Matty
InStr() needs 3 parameters:
InStr(CharToStartAt,String,TextToFind)
Nope, the first paramater is optional though...

If omitted it will always be 1.

----------------------

quote:
Originally posted by DJeX
Can any one help?
It would have been better if you said on what line that error occurs. And that you provided more code (eg: what are the declarations, what is s used for, etc.. etc..)

Anyways, with the info given:
  1. I hope you used Option Explicit at the beginning of each module, form and/or class

  2. Always explicitly use the property name you want to use. Never relay on default property names:
       Don 't use: s = List1
       but use: s = List1.Text

  3. Why using the "s" variable in that way?

       a) This:
               s = ""
               s = s + Mid$(List1, InStrRev(List1, "-") + 2)
               s = Replace(s, "http://", "")
          can be much shorter and faster by doing:
               s = Replace(Mid$(List1, InStrRev(List1, "-") + 2), "http://", "")

       a) What are actually trying to do with that string manipulation? (because at first sight, it seems a bit dodgy (no offense) eg: what if the url itself contains a "-"? What if the whole string doesn't contain a "-"?)

       c) What is the use in calculating/creating that "s" variable anyways; It isn't used anywhere and you also always set it to an empty string first (so it can't be a global kind of stringlist either)?

  4. If you need to parse thru a list, never use the .ListIndex property. This is dead, extremely dead slow...

    Use the .List() property for that. No need for resetting and updating the listindex at all, it is completely useless, makes bigger code and is very slow. Only do what you did when you explicitly need a visual update on each line (but even then your code will not work as it is supposed because Windows will not update the control on screen as long as it don't have th time to do it (not being idle))

    The .List() property is an array containing all the data from the list starting at index 0 to ListCount-1.

    Thus instead of:

          List1.ListIndex = 0
          For a = 0 To List1.ListCount - 1
              If InStr(List1.Text, websitein2) Then
                 s = blahblah
              Else
                 List1.ListIndex = List1.ListIndex + 1
              End If
          Next a

    Do:

          For a = 0 To List1.ListCount - 1
             If InStr(List1.List(a), websitein2) Then
                s = blahblah
             End If
          Next a

  5. Finally, and to come to your actual problem:

      a) What is "websitein2". Is it defined as a string?

      b) What if your list doesn't not contain any elements? Setting ListIndex to 0 will not work then and will produce an error.

      c) If you come to the end of your loop, thus with "a" being equal to listcount-1, there is a big possebility that you set the listindex to one element higher than what the list contains. If that happens an error will occur:

    If ListCount = 5 (meaning there are 5 elements) and "a" is 4 (index of 5th element):

       For a = 0 To List1.ListCount - 1
          If InStr(List1, websitein2) Then
             s = ""
             s = s + Mid$(List1, InStrRev(List1, "-") + 2)
             s = Replace(s, "http://", "")
          Else
             List1.ListIndex = List1.ListIndex + 1
               ' ListIndex can not be set higher than the index of the last element in the list!!!
               ' This is what gives you that error.
               ' But don't try to fix this with ways like If Then Else structures.
               ' Use the method described in point 4 instead

          End If
       Next a

----------------------

;)

This post was edited on 03-20-2006 at 06:51 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
03-20-2006 12:04 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Visual Basic Help - by DJeX on 03-19-2006 at 11:21 PM
RE: Visual Basic Help - by matty on 03-19-2006 at 11:45 PM
RE: Visual Basic Help - by CookieRevised on 03-20-2006 at 12:04 AM
RE: Visual Basic Help - by DJeX on 03-20-2006 at 01:18 AM
RE: Visual Basic Help - by CookieRevised on 03-20-2006 at 08:31 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On