[RESOLVED] [2005] New to VB seeking advice / criticism
I have just recently began learning Visual Basic. Read a "few" chapters from some books and began diving in. I have never really programmed before, a little PLC experience is all I have. I have made a functional game application, it actually works. My question is this, although it is functional I was wondering if I were to post the code on here or the complete solution, could I get some advice on how to condense the code or optimize it somewhat, I am sure I did not do everything correctly because the more I read from the forums, the more I realize I did not do everything the correct way. I would just like someone to point out the error of my ways.This is just a program for personal use, basically just to get my feet wet so no concerns about anyone stealing the code, etc.
why don't you ZIP up your project files (after deleting the obj and bin folders which contain compiled code) and post the zip file, instead of doing what you are doing.
If you don't know how to do what I am saying, let me know and I will help.
All you should have to do is go into the folder where your project files are, and delete the bin/obj folders (they will be recreated the next time you build your project from Visual Studio)
Then just right click on your entire folder where the source code is, and select send to -> compressed (zipped) folder.
This will zip up all the files, and then you just post here and select to add an attachment (note you have to be in normal reply mode, not quick reply)s
Ok, hopefully this is correct. I had to remove two of the sound files to get it down to a small enough size to attach. If these are needed I will attach to another post. Thanks.
1) Turn Option Strict ON. This is a key element, and will produce dozens or even hundreds of errors and warnings, but the changes you will make to fix these things will make your program both faster, and better. You can set this option for all projects, and you should definitely do so. At first, I didn't care so much, but it really does matter. This should be on by default, but for some reason MS doesn't see it that way. I can tell you on't have it on, because you put an integer into a textbox. That implicitly converts an integer to a string. With option strict on, you will have to do this explicitly. By telling the compiler exactly what you want done, the code produced will be faster.
2) Get rid of randomize and rnd. That's old VB6 stuff, and neither efficient, nor easy to use. The new Random object is MUCH easier. Look it up, and you'll agree. I believe this will allow you to get rid of the Index and Index2 functions, though you may leave them if you prefer. Getting rid of an extra function call will make no noticeable difference, but would be vaguely faster.
3) A minor quibble: BetMax has a hardcoded bet of 2. Wouldn't it be somewhat better to have that 2 be a variable that could be set elsewhere in code? You could make a form level variable which could be set via some other control, menu item, or on startup. It could be 2 by default, but could be changed to something else as needed.
Well, that's all the suggestions you are getting from me. While I agree with Kleinma that posting the code for something that big can get a bit long, I can't be downloading zips, and won't be back to somewhere that I can until Friday.
Shaggy, that is exactly the kind of stuff I am looking for, I want to get better at this and helpful advice is more than welcome. I appreciate your insite.
That's as far as I got before Kleinma removed your code in favor of the zips. I really don't like zip files, though as long as they are source code, that would be ok, but I can't do anything with them now. However, the first suggestion I made will keep you busy for a few hours. The VAST majority of the changes that Option Strict will require will be invalid cast changes, where you have to add the .ToString or directcast or CInt() or some such. These will increase performance without changing anything. However, Option Strict can catch some fairly subtle bugs, but your code looked pretty reasonable, so you may not see any.
1) Turn Option Strict ON. This is a key element, and will produce dozens or even hundreds of errors and warnings, but the changes you will make to fix these things will make your program both faster, and better. You can set this option for all projects, and you should definitely do so. At first, I didn't care so much, but it really does matter. This should be on by default, but for some reason MS doesn't see it that way. I can tell you on't have it on, because you put an integer into a textbox. That implicitly converts an integer to a string. With option strict on, you will have to do this explicitly. By telling the compiler exactly what you want done, the code produced will be faster.
Ok, I turned Option Strict On, it didn't seem to change anything, no errors or warnings came up and after building the project again it ran just the same. Is there something I am missing?
Ok, fixed the errors generated when Option Strict was turned ON, was simple enough.
2) Get rid of randomize and rnd. That's old VB6 stuff, and neither efficient, nor easy to use. The new Random object is MUCH easier. Look it up, and you'll agree. I believe this will allow you to get rid of the Index and Index2 functions, though you may leave them if you prefer. Getting rid of an extra function call will make no noticeable difference, but would be vaguely faster.
Got rid of Randomize and rnd, this did allow me to rid myself of the index functions, and I used the Random object instead, worked like a charm.
3) A minor quibble: BetMax has a hardcoded bet of 2. Wouldn't it be somewhat better to have that 2 be a variable that could be set elsewhere in code? You could make a form level variable which could be set via some other control, menu item, or on startup. It could be 2 by default, but could be changed to something else as needed.
Want to leave this at 2 because the payout is based on single coin or 2 coin bets. Trying to keep it as close to a real slot machine as possible.
Thanks for all the help. Rest assured I will be back for more advice as I get deeper and deeper into the world of VB .NET.