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: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Visual Basic Help
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)

.zip File Attachment: Module1.zip (1.48 KB)
This file has been downloaded 96 time(s).

This post was edited on 03-20-2006 at 09:45 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
03-20-2006 08:31 PM
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