What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Plug-Ins » Known Problems with VB

Known Problems with VB
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Known Problems with VB
Remember to save settings per user, and not globally! There's nothing so annoying for a user not to be able to set specific options only for that specific account of his. eg: If you don't do that and if your little brother signs in he will also be using the very same settings and can change them to whatever he likes. There is nothing so annoying to reset all the settings each time because your bro messed them up (or have set them in the way you don't like).

The user's email is giving in the Initialize() function, so that can be used to create a subkey to save the settings for that user only.

(same story goes for when you save stuff in a INI file instead)


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

Looking at your code, the bugs are not because of the "not to do for a plugin" list, but because your own code is buggy:

quote:
Originally posted by Heffy
Instead of trying to fix the problem, I'll just move over to using the registry for saving settings.
code:
Public Function InitVars()
    (...)
    ini = regQuery_A_Key(HKEY_LOCAL_MACHINE, "SOFTWARE\Patchou\MsgPlus2", "PluginDir")
    ini = iniSettings + "\Freedom.ini"
    sWry = GetFromINI("Settings", "Wry", "False", ini)
End Function
You've nowhere defined the variable iniSettings. Because of that it will always be empty. And thus your ini file will be created/read from the current hard drive in the main root; "\Freedom.ini" (eg: if C is the current hard drive being used then "c:\Freedom.ini" will be read).

To avoid such errors (using non declared variables) always include the line "Option Explicit" as the very first line in every module, form, class, etc...

Also you've defined the global variable sWry as a boolean! So if you assign something to the variable it should be a boolean and not a string. Otherwise you will produce errors!

To fix the bug:
code:
Public Function InitVars()
    (...)
    ini = regQuery_A_Key(HKEY_LOCAL_MACHINE, "SOFTWARE\Patchou\MsgPlus2", "PluginDir")
    ini = ini + "\Freedom.ini"
    sWry = GetFromINI("Settings", "Wry", "False", ini) = "True"
End Function
Though it doesn't check if the registry key exists or not. So you need to add that too and/or define a default directory. Otherwise, in that situation, the variable 'ini' will still be "\Freedom.ini" in the end and you still would get problems.


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

code:
Private Sub cmdDone_Click()
    frmConfig.Hide
    Unload frmConfig
    spam = GetFromINI("Settings", "Wry", "False", ini)
    If spam = "True" Then
        chkWry.Value = 1
    Else
        chkWry.Value = 0
    End If
End Sub
That routine is useless.

You nowhere use the global variable 'spam' for anything, so why reading it from the INI file?

Besides the routine being useless, the first line 'frmConfig.Hide' is also useless as you unload the form right after.

Besides that, the unload line is again counteracted by the use of 'chkWry.Value'. Whenever you use a reference to a control on a form which is not yet loaded or already unloaded, the form will be reloaded again (which is rather very logical because otherwise the reference would be invalid)! In other words, if you want to unload a form, do it as the very last thing in the procedure.

Besides that the IF THEN ELSE can be written in 1 line very in a very short way.

So besides that setting the chkWry checkbox is useless because you unload the form (and thus will loose such settings anyways), the routine can/should be written like:
code:
Private Sub cmdDone_Click()
    spam = GetFromINI("Settings", "Wry", "False", ini)
    chkWry.Value = abs(spam = "True")
    Unload frmConfig
End Sub
And because you wont do anything with the 'spam' variable anywhere else in your project, it can/should be shortenend to:
code:
Private Sub cmdDone_Click()
    Unload frmConfig
End Sub

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

code:
If IsNumeric(sCommandArg) Then
    sRoll = Int(Rnd * sCommandArg) + 1
    sSides = sCommandArg
Else
sCommandArg is defined as a string! Therefor 'Rnd * sCommandArg' will produce an error.
code:
Else
    sRoll = Int(Rnd * 6) + 1
    sSides = 6
End If
sSides is defined as a string! Therefor 'sSides = 6' will produce an error.

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

code:
spam = regQuery_A_Key(HKEY_LOCAL_MACHINE, "SOFTWARE\Patchou\MsgPlus2", "PluginDir")
Instead of using this API registry function (with all the problems it can cause) to get the plugin directory (if it exists at all!!!!), simply use 'App.Path' to get the directory where the plugin is located (this is afterall the plugin direcotry):
code:
spam = App.Path
If you do this you wont need to rely on (potential buggy) registry reading and you wont have problems when the regisrty can't be accessed, etc etc.

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


etc...

Lots of other comments and stuff are added in the fixed files which I'll attach later on...

PS: If you do use the registry to save settings, do not forget to remove all the settings if you uninstall the plugin. If you use an ini file for settings don't forget to remove it also when uninstalling (same with the wav sound).

EDIT: Attached is the fixed source, compare each procedure in every module with your original code to see where the bugs were.

.zip File Attachment: Freedom143src_fixed.zip (19.8 KB)
This file has been downloaded 238 time(s).

This post was edited on 01-11-2006 at 08:58 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-11-2006 05:18 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Known Problems with VB - by Heffy on 01-10-2006 at 08:36 AM
RE: Known Problems with VB - by Dempsey on 01-10-2006 at 08:39 AM
RE: Known Problems with VB - by Heffy on 01-10-2006 at 08:50 AM
RE: Known Problems with VB - by RaceProUK on 01-10-2006 at 12:22 PM
RE: RE: Known Problems with VB - by Heffy on 01-10-2006 at 01:44 PM
RE: Known Problems with VB - by Kryptonate on 01-10-2006 at 12:29 PM
RE: Known Problems with VB - by RaceProUK on 01-10-2006 at 12:37 PM
RE: Known Problems with VB - by CookieRevised on 01-10-2006 at 06:16 PM
RE: Known Problems with VB - by RaceProUK on 01-11-2006 at 12:49 AM
RE: RE: Known Problems with VB - by Heffy on 01-11-2006 at 08:33 AM
RE: Known Problems with VB - by Heffy on 01-11-2006 at 02:09 PM
RE: RE: Known Problems with VB - by eSouL on 01-11-2006 at 05:57 PM
RE: Known Problems with VB - by CookieRevised on 01-11-2006 at 05:18 PM
RE: Known Problems with VB - by Heffy on 01-12-2006 at 02:20 AM
RE: RE: Known Problems with VB - by CookieRevised on 01-12-2006 at 06:31 AM
RE: Known Problems with VB - by Chestah on 01-12-2006 at 06:30 AM
RE: Known Problems with VB - by Chestah on 01-12-2006 at 11:35 AM


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