• The VOIDRUNNER'S CODEX is LIVE! Explore new worlds, fight oppressive empires, fend off fearsome aliens, and wield deadly psionics with this comprehensive boxed set expansion for 5E and A5E!

Help with Visual Basic

Majin Trugeta

First Post
Hi, I'm a pretty inexperienced programmer, but I'm majoring in Comp Sci in college so am learning as I go. I just recently finished taking a Visual Basic course and wanted to try to make a D&D alignment generator for fun, just to see if I could do it. It's a 36 questionnaire based out of the Hero Builder's Guidebook. Not sure if that would present a problem because of copyright so I'm not sure if I could release it after I've finished. I never intended to though, this is just for private use and just to experiment with.

Well either way I've hit a major roadblock. In class we barely scraped the surface of using multiple forms, and didn't get into global variables. So thats where I'm stuck. I have 36 seperate forms (one for each question with 4 radio buttons for the choices) I know this may be inefficient but it's the only way I could think of getting it to work with the knowledge I know of. I of course forgot to factor in global variables. These seem to be needed all over the place and I've declared them as Public and the "g" is in front of the variable name as well but I still get errors.

Namely, the form that I have the calculation code under complains that it doesn't recognize the variables I've declared globally. I'm not really sure what other info anyone else would need as this is my first time asking such a question and this type of board. But if any experienced VB programmers wanna give me a hand so I can figure this out you can email me at timoan@comcast.net

It would be greatly appreciated, TIA!
 

log in or register to remove this ad

Mynex

First Post
VB Help

Instead of using 34 different forms, why not make one form, scrollable, with all 34 questions on it, the radio selections to the right of the questions.

This solves the problem of making the global variables across all the forms.

Just a thought. :)
 

smetzger

Explorer
I hope VB isn't the first language they are teaching you. My first language was Lisp, something you can really sink your teeth into. But then them I'm EE.

Just poking a little fun at the Comp Sci majors out there. :)

*:> Scott
 

Nazrog

First Post
You might not need the global variables, as you can access the items on the form remotely.

Say you have a form called frmForm, and a CheckBox call chkCheck.

From any of the other forms all you have to do is;

frmForm.chkCheck.Value and you get the value of the check box.

Although the option of putting them all on the same form is a better idea. Then you don't have to worry about making variables public.
 
Last edited:

Majin Trugeta

First Post
Well..

Thanks for the replies. Putting it all on one form occured to me but in the end I decided to go with multiple forms for multiple reasons, most self evident in some way. Each way has its advantages. (like if I woulda put it all on one form I prolly wouldn't be here bugging you guys, lol) but since I've taken the time to design all those forms and put individual code behind them I'd like to keep them and find some sort of work around for this. I just dont understand why the global variables aren't "catching hold" to the other forms.

The way I have it is I have 6 integers dimensioned. (one for each alignment piece, two for neutral (ethical/moralistic versions) They act as counters basically and when you go on to the next page I have code that (by if statements) determines which radio button's value is "true" and it increments the particular variable. (ie. If you chose option button number 4 (optFour, conveniently) then depending on the "alignment" of the answer will increment that variable 1 or 2. (People with the HBG should know what I'm talking about if they take a look at the scoring system)

It does this seperately for each form (because each set of answers is different, having different combinations of alignment choices.) I also have two integers (used to be strings) declared for a the moral alignment value, and the ethical one. Then on the very last form I have the code that determines this: Depending on which ethical alignment you chose most and what moralistic alignment you chose most in your question answering each is supposed to be assigned a value. Then I have a large if/elseif statement determined which variables are both true. lets say the value of "1" for the ethical alignment integer = lawful and "2" for the moral alignment = evil. I test to see if both of these is true. If not then I pass on to another combination running down the line of all 9 alignments. If one comes out to be true then it outputs the data in some local strings I've defined and filled in based on which alignment it came out to be. The corresponding string holds the PHB's description of said alignment.

This is where I'm getting the error. The last form with all the code complains that it doesn't recognize all the integers I have selected. First off they were only declared as modular (stupid me) but even when searching for every instance and changing everything that I can think of to Public g**** it still doesn't work.

Also if I just declare the variables locally in the last form that does all the calculations just to get a result it gives me an error box (error checking implemented by myself, meaning that out of the 9 "correct" outcomes of the test, neither of them is true. So I'm just stumped totally on how to get that to work. I'm not sure if the above suggestion would help because of the way I'm going about doing things, but this is a much more detailed explanation on what my code is doing so hopefully this helps explain my current situation better and somebody can make some sort of sense out of it. Thanks for any more help you can give on this.
 

Za the Demon

First Post
Where are you defining the global variables? If you define them in a form, then they are not global, but instead modular to that form. If you want true global variables, then you need to create a Bas module and declare them in that module as global.
 
Last edited:

Majin Trugeta

First Post
Hmmm

That could be the problem as well. For a fleeting moment I thought I might resort to a module but I have no previous experience with using them so I'd be going into it pretty blind except what I could find on it in my textbook. I declared the global variables in the general declarations section of the parent form. Guess that isn't good enough if I gotta give a module a try then maybe? What should I include to get the best efficiency and effectiveness out of it?

BTW tho, after the user would click to progress the test along I systematically unload each of the previous forms (for clean up purposes basically) could this be whats screwing things up? I figured that if it would be, it would be just the main module that I originally declared them in..

/**********Update**********/

<laughs maniacally>
Well I "took the plunge" and made a module.. just cut and pasted my globals into it and whammo the thing seems to work. If only I'd have actually given it a try instead of disregarding it. Thanks for the extra incentive to give it another try. I might actually have this thing working now! I got real output! Now to make sure its the correct output heh. Don't let this discourage anyone else from leaving their comments/updates/suggestions and such. This may just be a snap judgement from me to begin with. I will do some more testing to make sure I got my logic right and stuff and will check back here as well later on. Thanks again everyone!
 
Last edited:

dvvega

Explorer
When you're ready to progress in your Visual Basic skills consider doing the following. Your project is small enough to use it for a learning excercise, and the skills will be valuable.

1) create an object/class that handles a single questions
2) create an object/class that handles a questionaire (it will keep score in a variable)
3) create some form of data format to store questions with their possible answers and weightings
4) create a form as part of the questionaire class
5) basically loop through questions until all displayed, updating the form with the newest question, keep a running score tally.

If you do it this way (I know it might seem like a lot for just a simple task) you will have gained more OO knowledge (Visual asic OO), learnt about dynamic forms, and you will have a compact program that will work for any style questionaire, requiring only the change of the data file.
 
Last edited:

towngen

First Post
Personally, I wouldn't recommend trying to do anything with Object Oriented programming concepts at all just yet. Having just declared your first global variable yesterday, I think it would be prudent to get comfortable with programming first. Then worry about implementing OO classes later.

If I were you, I would go to a used book store and buy a copy of one of those "teach yourself VB in 21 days" type books. Then go through that whole book and do all the examples it talks about. Don't just skim through it, you need to actually type in the examples they provide. There is something about actually doing it which makes it sink in better. By the end of the book, you should be able to write this program easily.

After you've written several programs of larger and larger complexity, you'll start to notice that the programs get harder to manage. You'll spend lots of time trying to track down where a global gets written to and trying to figure out what is overwriting the value you KNOW you put in there just a few lines of code before. This is when the it pays to know OO programming. It takes a little longer to write (not a lot extra really once you're used to it), but writing programs using OO programming techniques helps make the complexity of large programs more manageable.
 

MJEggertson

First Post
>> You'll spend lots of time trying to track down where a global gets written to and trying to figure out what is overwriting the value you KNOW you put in there just a few lines of code before. (towngen)

That's the single worst (and potentially disasterous) problem with using globals. They work fine if you have a simple program that goes from line 1 to the end all in a direct sequence. But as soon as you start hanling events and your program has no defined excecution path, globals become very difficult to use.
 

Voidrunner's Codex

Remove ads

Top