If Statment Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nickwalnut
    New Member
    • Aug 2008
    • 2

    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_Mcho ice(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 "AnswerConditio n" 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.Check ed = True".

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

    For example,

    If strAnswerCondit ion Then Word_GeneralRes ult += 1

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

    What do I do?
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    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 strAnswerCondit ion = "<TEXT>" Then Word_GeneralRes ult += 1

    otherwise you will need

    if stranswerquesti on1.checked then Word_GeneralRes ult += 1

    the fact that you have called it stranswercondit ion implies that it is a string in which case you cannot check it for a true/false as it is not a boolean value.

    Comment

    • jg007
      Contributor
      • Mar 2008
      • 283

      #3
      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 <:)

      Comment

      • nickwalnut
        New Member
        • Aug 2008
        • 2

        #4
        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.Check ed = True" inside strAnswerCondit ion to the Next Button subroutine, pass "opt1.Check ed" and then have the "= True" in the actual subroutine. Or pass "chk1.Check ed 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 strAnswerCondit ion literally (ie. read the text inside as program code, not as a string)?

        Comment

        • jg007
          Contributor
          • Mar 2008
          • 283

          #5
          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?

          Comment

          Working...