Login Register


[Share] Useful Codes filter_list
Author
Message
RE: [Share] Useful Codes #2
By headlines:

1. "Open Something" - Don't use shell, the Process class will work just fine still for doing this.

2. "Delete a file"
Code:
If System.IO.File.Exists(FileToDelete) = True Then

You don't need "= True" in there. That's just an extra unnecessary step in evaluating the boolean expression.

3. [color=red]"Kill a process"
- This code assumes that there is a process running by the name of taskmgr.exe, at least one, and so if there is no running processes by that name, you'll get an exception for referencing index (0). Secondly, the name, you want to input without the ".exe".

4. "Delete a registry key" - Microsoft.Win32 has functionality to interact with the registry as a note here. In your other Registry "snippet" you are using Microsoft.Win32, while here you are using My.Computer from Microsoft.VisualBasic.

5. "Text To Speech" - SpeechSynthesizer is 100 times better than using old SAPI here. This is more the VB6 way of doing it... And it promotes poor code for how you create the object.

6. "Fade in"
Code:
For FadeIn = 0.0 To 1.1 Step 0.1

Why 1.1? Opacity is from 0.0 to 1.0. I wouldn't do it this way though either.

7. "Fade out" - Same thing as Fade in, you may want to go to 0... Although why start with Integers here and have to divide by 100 each time? In "Fade in" Double was used.

8. "Gmail bomber" - SmtpClient implements the IDisposable interface, and no Dispose() method is being called here... You could also use the Using statement.

9. "Info Grabber" - The Environment class would work here too for a few of these, and I would recommend it as well.

10. "Case Example" - You've got implicit type casting going on in this bit of code, and Rnd() should be replaced with the functionality from the Random class in my opinion. Int() is an old VB6 carry over as well...

11. "Login Example" - Should be noted here that this should not be used for a very secure application.

12. "Xfire Add Friender and status changer (Just an example)" - Could do this with webrequests unless for some reason the elements on the page have to be loaded as well for a visual?

13. "Screen Capture" - Should be disposing of a few resources here...

14. "Add Your Application To Startup" - Not very pretty code here. Bad use of Try Catch. Performance loss is to be mentioned here as a consideration for what the way this code is written.

15. "HotKeyChat Spammer" - GetAsyncKeyState is not being used in a suitable manner here. It is not event based, so the reason for why you need a timer here that calls it consistently is a sign of poor application design.

16. "CD-Rom Prank" - There are better ways to do this as well through P/Invoke Win32 functions. This is the worst way of doing it, and probably something more suited if programming in VB6.

17. "Shutdown Manager" - I'm seeing Shell() again... The Process class from System.Diagnostics should be used instead.

*Note: I skipped over some. This was just a running post of what I seen as I skimmed through some of the examples.
-- cxS

[ Haskell/.NET/C/C++ - Software Engineer ]

Reply





Messages In This Thread
[Share] Useful Codes - by shizelkid - 02-26-2013, 08:03 AM
RE: [Share] Useful Codes - by cxS - 02-27-2013, 03:05 AM
RE: [Share] Useful Codes - by shizelkid - 02-27-2013, 08:35 PM
RE: [Share] Useful Codes - by cxS - 02-27-2013, 08:42 PM
RE: [Share] Useful Codes - by shizelkid - 02-28-2013, 07:25 AM
RE: [Share] Useful Codes - by cxS - 02-28-2013, 07:54 AM
RE: [Share] Useful Codes - by BreShiE - 02-28-2013, 09:10 AM
RE: [Share] Useful Codes - by cxS - 02-28-2013, 09:18 AM
RE: [Share] Useful Codes - by BreShiE - 02-28-2013, 09:22 AM



Users browsing this thread: 1 Guest(s)