Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 31st, 2008, 04:06 AM
Newbie
 
Join Date: Aug 2008
Posts: 2
Default If Statment Help

Hi.

I'm currently developing a self-test application to be used by the staff at my school (SDD assignment), and I've hit a snag. I've created around 7 different "base" forms, each of which will be inherited for the particular questions that are going to be asked to the user.

Now, I created some subroutines to easily create those question forms. All you have to do to load a form is type in, say:

Createform_Mchoice(formID, Question, answer1, answer2, answer3, answer4, answerCondition)

The question and multiple choice answers will then be automatically filled into a new form dimensioned. I then have a subroutine for the "Next Question" button on each form, which is meant to test the "AnswerCondition" and if it is true then award a point to a variable. The answer condition changes for every form, so for example I would make it "chk1.Checked = True".

Now when I put this condition into an If statement, it comes up with a conversion error.

For example,

If strAnswerCondition Then Word_GeneralResult += 1

The error states that it cannot convert a string (strAnswerCondition) to boolean.

What do I do?
Reply
  #2  
Old August 31st, 2008, 12:01 PM
Familiar Sight
 
Join Date: Mar 2008
Posts: 247
Default

Sorry, I am a little unclear on what you are trying to do but if you are using a string you will need to have something like -

If strAnswerCondition = "<TEXT>" Then Word_GeneralResult += 1

otherwise you will need

if stranswerquestion1.checked then Word_GeneralResult += 1

the fact that you have called it stranswercondition implies that it is a string in which case you cannot check it for a true/false as it is not a boolean value.
Reply
  #3  
Old August 31st, 2008, 12:04 PM
Familiar Sight
 
Join Date: Mar 2008
Posts: 247
Default

looking again I would guess that you would be better passing the correct answer number to the function then getting it to return a boolean value for if it is correct

sorry my programming is really messy so I won't try to provide an example as I tried to create this with two forms and ended up with a bizzare mess of a function and a timer control on form1 to check when to change the question text on form2 <:)
Reply
  #4  
Old September 1st, 2008, 09:18 AM
Newbie
 
Join Date: Aug 2008
Posts: 2
Default

Hey, thanks for replying.

The thing is, I have several different forms which the correct answer can take. In one form, it can be one of four options, another 0-4 of four options, another an actual text answer typed in by the user etc.


Would I be able to, for each specific form type, pass at least the actual answers instead of the whole condition? For example, instead of passing "opt1.Checked = True" inside strAnswerCondition to the Next Button subroutine, pass "opt1.Checked" and then have the "= True" in the actual subroutine. Or pass "chk1.Checked And chk2.Checked" to the subroutine.

Will this work, or will it come up with another conversion error?

And if it won't work, is there any other solution you can think of, or is there a way to instruct the compiler to actually read the string strAnswerCondition literally (ie. read the text inside as program code, not as a string)?
Reply
  #5  
Old September 1st, 2008, 06:55 PM
Familiar Sight
 
Join Date: Mar 2008
Posts: 247
Default

Sorry, I'm still a little bit usure what you are doing and the question you are asking , would it be possible to post some of the code for how the form is called and the nextbotton event


are you actually checking the answers when the users press next or are you storing them into an array or something to be checked at the end?
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles