I see...
quote:
Originally posted by DJeX
The code it said it had the error on was:
code:
List1.ListIndex = List1.ListIndex + 1
which indeed confirms point 5 from my previous post...
So use the method described in point 4 in my previous post.
---
Oh and loose the "Goto", that's bad programming practice.
And:
s = ""
s = s + blahblah
Is simply the same as:
s = blahblah
--------
And another possible cause for errors:
The IsEmpty() function only returns meaningful information for
variants. Since you have defined "unfSite" and "remHost" as strings, the IsEmpty() function will not work as you intended it!
IsEmpty() does not check if a string is empty...
IsEmpty() is used to check if a variant variable is initialized. Remember that the "
Empty" statement in VB does not mean 'nothing', it means 'not initilized'. Big difference there... If a string contains 'nothing' it is still a string, it is still 'something': a string with no characters, aka "".
IsEmpty(): The required expression argument is a
Variant. IsEmpty() returns a Boolean value indicating whether a variable has been initialized. It returns
True if the variable is uninitialized, or is explicitly set to
Empty; otherwise, it returns
False.
False is always returned if the expression contains more than one variable. IsEmpty() only returns meaningful information for variants, not for other types!
All this means that if IsEmpty() is used with other types than variants, it will always return
False! There is no way that "
If IsEmpty(unfSite) Or IsEmpty(remHost) Then" ever becomes
True, hence your program will never ever perform "
UnloadProxyUser (Index)".
If you want to check if a string is empty, aka it is has no characters, you use:
If mystring = "" Then
Or a very fast alternative (because it does not use dead slow string manipulations or comparissons):
If LenB(mystring) = 0 Then
For your code that means:
If unfSite = "" Or remHost = "" Then
Or with the fast method:
If LenB(unfSite) = 0 Or LenB(remHost) = 0 Then
Or even:
If LenB(unfSite) + LenB(remHost) = 0 Then
--------
Another remark:
' Fetch the targeted site
tarSite = StripHost(unfSite)
You nowhere use
tarSite in your code, so what's the use?
--------
Another remark:
You have lots of double code.
Statr by loosing that
Goto statement and put everything in proper IF THEN ELSE structures. Then you'll see that many code is duplicated and executed in both the
True and
False cases of the IF THEN ELSE structure. This means that this duplicated code can be put outside of the IF THEN ELSE structure.
eg:
If saying = "Bye" Then
Print "bye bye now"
Call ShowSchedule
Else
Print "Hello there"
Call ShowSchedule
End If
The above has duplicated code and can be shortened:
If saying = "Bye" Then
Print "bye bye now"
Else
Print "Hello there"
End If
Call ShowSchedule
--------
Another remark:
The variable "a" isn't defined anywhere in your sub procedure. This means that you didn't use
Option Explicit at the beginning of each module, form, class, etc. Otherwise your code wouldn't have runned in the first place since VB then would have detected an uninitialized variable.
Add
Option Explicit at the beginning of each module, form, class, etc. to avoid undeclared variable errors and many other mistakes which could happen if you don't do this.
(and declare the variable "a").
--------
Attached is the fixed and optimized code. Note that it can still be optimized (and made more logic to follow), example is seen in the
srvIn_DataArrival_ALTERNATIVE procedure. Also note that all I did was optimizing the logic behind the procedure (fixing and simplifying the logic), I didn't alter how the procedure works. This means errors could still occur because for example
tarSite isn't used anywhere, possible bad entries in the list, etc)