Question Loop Thru Functions

inkedgfx

Well-known member
Joined
Sep 29, 2012
Messages
139
Location
USA
Programming Experience
Beginner
I am writting a Trivia Game.....there will be 12 catagories , each catagory will have at least 100 question.....I will create 10 different functions for each catagory to randomly pick a question from a list of 10 questions.....is it poosible to loop thru the 10 functions and randomly select a function to run when the user clicks the next buttoon?

Thank You for your help

InkedGFX
 
Hi,

I cannot see what's at fault from what you have posted so far so you will need to post everything you have so far so that we can check through what's gone wrong.

Cheers,

Ian

NB, will not be able to get back to you a for a few hours now.
 
no problem...I appreciate the help..... heres the whole QuizQuestion Class

Imports System.Collections.Generic
Public Class QuizQuestion
    Public Property Question As String
    Public Property AvailableAnswers As New List(Of String)
    Public Property CorrectAnswer As Integer
    Public Enum TriviaCatagories
        GeneralKnowledge
        Arts
        Bible
        Entertainment
        Food
        Mythology
        Science
        Sports
    End Enum
    Public TotalCatagories As Integer = [Enum].GetValues(GetType(TriviaCatagories)).Length
    Public myQuestions As New Dictionary(Of TriviaCatagories, List(Of QuizQuestion))
    Public Sub CreateMyQuizQuestions()
        Dim myQuizQuestion1 As New QuizQuestion
        With myQuizQuestion1
            .Question = "What is the surname of the Hungarian inventor whose multicolored, rotatable cube became a world cult?"
            .AvailableAnswers.Add("Chacofski")
            .AvailableAnswers.Add("Rubik")
            .AvailableAnswers.Add("Rollins")
            .CorrectAnswer = 1
        End With
        AddQuestionToDictionary(TriviaCatagories.GeneralKnowledge, myQuizQuestion1)
        Dim myQuizQuestion2 As New QuizQuestion
        With myQuizQuestion2
            .Question = "How long is the appointed term of office of the secretary general of the United Nations?"
            .AvailableAnswers.Add("12 Years")
            .AvailableAnswers.Add("5 Years")
            .AvailableAnswers.Add("2 Years")
            .CorrectAnswer = 1
        End With
        AddQuestionToDictionary(TriviaCatagories.GeneralKnowledge, myQuizQuestion2)
        Dim myQuizQuestion3 As New QuizQuestion
        With myQuizQuestion3
            .Question = "What is the term for a person with assets of over 1,000 million dollars?"
            .AvailableAnswers.Add("Billionaire")
            .AvailableAnswers.Add("Millionaire")
            .AvailableAnswers.Add("Zillionaire")
            .CorrectAnswer = 0
        End With
        AddQuestionToDictionary(TriviaCatagories.GeneralKnowledge, myQuizQuestion3)
        Dim myQuizQuestion4 As New QuizQuestion
        With myQuizQuestion4
            .Question = "Carlo Collodi wrote a story about a wooden puppet which became human. What is its title?"
            .AvailableAnswers.Add("Dumbo")
            .AvailableAnswers.Add("Chuckie")
            .AvailableAnswers.Add("Pinocchio")
            .CorrectAnswer = 2
        End With
        AddQuestionToDictionary(TriviaCatagories.GeneralKnowledge, myQuizQuestion4)
    End Sub
    
    Public Sub AddQuestionToDictionary(ByVal SelectedCatagory As TriviaCatagories, ByVal NewQuizQuestion As QuizQuestion)
        If myQuestions.ContainsKey(SelectedCatagory) Then
            myQuestions(SelectedCatagory).Add(NewQuizQuestion)
        Else
            myQuestions(SelectedCatagory) = {NewQuizQuestion}.tolist <------ this is the problem area.....
        End If
    End Sub
   
End Class



another quick question....at some point will there be performance issues if the "CreateMyQuizQuestions() " is lets say 500(or more) questions long?


InkedGFX
 
Hi,

Very quickly since I need to go, but as the class stands I get no syntax or compilation errors with the class that you posted and the ToList method does not give me any errors whatsoever. So, I am not really sure what to say???

However, that said, have a look again at how I designed to Quiz project and more importantly the QuizQuestion class since you are causing yourself a whole world of trouble by coding this the way you are and embedding everything within the QuizQuestion class.

Cheers,

Ian
 
the only thing you have in the QuizQuestion class is the three property values?

I dont really understand where I should have different parts of code... I thought is was correct to create a class to hold all the subs and functions and then to call the subs or functions from the form

lol..I think I need to take a night course.....

thank you for the help

InkedGFX
 
Hi,

A night course, Yes, but otherwise, No, you have misinterpreted what has been posted. Go back to the example Quiz that I posted and check specifically which context and / or event I created each part of the Quiz objects.

You will see that some objects are create at the Class level (being a Form) so that they are available to every routine within the Form. Two examples are the Dictionary and the QuizQuestion class. You will also see that some routines run in the Form Load event and others run in a Button Click event. These events are examples of where you, COULD, if you wanted to, build and use the objects you need to make the Quiz work.

As it stands right now, just one example of your misinterpretation is that each time you declare a New Instance of your QuizQuestion class you create a new Dictionary which would hold every question defined within your QuizQuestion class. This is not what you want and is not the right way to do this. What you are trying to do is create One Dictionary with multiple questions of your choosing.

I hope that helps to get you to understand where you need to be doing things.

Cheers,

Ian
 
thank you for taking the time to help me out with this, but I dont want to take any more of your time...this is over my head because I really have no Idea what Im doing with this.......

InkedGFX
 
Hi inkedGFX,

No Problem and that's fine. You have the example source code for future reference if you need it and no doubt this will make more sense to you when you get further on with your programming experience.

Good luck for the future and we will always try and help where we can.

Kind regards,

Ian
 
lol...as always I appreciate you taking the time to help...but I think I need more help than anyone would be willing to give......I really have no business trying to program....so maybe I will stick to Graphics......as much as I would like to learn this.....I think my only option would be to take a night course on VB.NET

InkedGFX
 
Hi inkedGFX,

I though I would just post one final point before you effectively close off this thread.

Firstly, try this in your spare time. It should help to give you some structured learning:-

Microsoft Visual Basic .NET tutorials for Beginners

Secondly, please do not get despondent or feel like your confidence has been knocked sideways all because you have come up with something you have not been able to get your head round just yet. Programming is not learnt in a day, as can be said about any profession, and with time and determination all will become clear in the end.

To put things into perspective, I am an experienced programmer with the majority of my experience on a different platform to .NET, but when I look at some of the things that the experts post on this site I feel like a total novice myself. However, I never let that knock my confidence and I always try and use their experience and knowledge to expand my own learning.

Good luck and cheers,

Ian
 
lol...as always I appreciate you taking the time to help...but I think I need more help than anyone would be willing to give......I really have no business trying to program....so maybe I will stick to Graphics......as much as I would like to learn this.....I think my only option would be to take a night course on VB.NET
InkedGFX
Don't give up dude.. keep studying and learning with patient... I am doing this, it will take time to get better and then we will be happy to handle issues ;)

The following link shows how many VB.Net tutorial videos I have :) It indicates that I need to learn more and then maybe one day I will make a tutorial to people about VB.Net. Lets wish that so :) Don't give up buddy.
https://www.youtube.com/watch?v=xchefjl6ZOM
 
Last edited:
Hi inkedGFX,

I though I would just post one final point before you effectively close off this thread.

Firstly, try this in your spare time. It should help to give you some structured learning:-

Microsoft Visual Basic .NET tutorials for Beginners

Secondly, please do not get despondent or feel like your confidence has been knocked sideways all because you have come up with something you have not been able to get your head round just yet. Programming is not learnt in a day, as can be said about any profession, and with time and determination all will become clear in the end.

To put things into perspective, I am an experienced programmer with the majority of my experience on a different platform to .NET, but when I look at some of the things that the experts post on this site I feel like a total novice myself. However, I never let that knock my confidence and I always try and use their experience and knowledge to expand my own learning.

Good luck and cheers,

Ian


Don't give up dude.. keep studying and learning with patient... I am doing this, it will take time to get better and then we will be happy to handle issues ;)

The following link shows how many VB.Net tutorial videos I have :) It indicates that I need to learn more and then maybe one day I will make a tutorial to people about VB.Net. Lets wish that so :) Don't give up buddy.
https://www.youtube.com/watch?v=xchefjl6ZOM

thank you both for the links...I will keep at this until I get it.....I wont give up......im going to read the info now :)

InkedGFX
 
Socarsky...
where did you find all those videos?

I could really use a resource like that.

InkedGFX
 
is there another namespace I should import other than the System.Collections.Generic to get the List to work?

InkedGFX
 
I have been searching google all day today , trying to get more info on Dictionaries.....and List's ...can you believe there isnt one site that really explains how to create and use the List(Of...) object.....even Microsoft doesnt explain it very well.....am I supposed to create a class just for the questions , then call everything else in the form class?

also ...how do I load the questions into a label and fill the radio buttons with the answers? this is what I have been trying to find all day.......

I am really no better off now than I was this morning .......ahhhhhhhh!

InkedGFX
 
Hi,

I think I might have just uncovered why you are getting the ToList issue. After looking on the Net there seems to be a lot of references to the fact the .ToList method was introduced in VS2008. So the first question for you is what version of Visual Studio are you using? If you are using a version earlier than 2008 then replace the subroutine AddQuestionToDictionary with this one:-

VB.NET:
Private Sub AddQuestionToDictionary(ByVal SelectedCatagory As QuizCategories, ByVal NewQuizQuestion As QuizQuestion)
  If myQuestions.ContainsKey(SelectedCatagory) Then
    myQuestions(SelectedCatagory).Add(NewQuizQuestion)
  Else
    Dim myNewQuestionCategorylist As New List(Of QuizQuestion)
    myNewQuestionCategorylist.Add(NewQuizQuestion)
    myQuestions.Add(SelectedCatagory, myNewQuestionCategorylist)
  End If
End Sub

In this example you can see I have removed the .ToList method and physically created a new List for each new Quiz Category.

If you are using 2008 or above, then I also found references to the fact that in the .NET 3.5 Framework you need to add the System.Linq namespace to be able to access the ToList method? So try adding "Imports System.Linq" to the class. Guessing and hoping a bit really on that last bit.

Please let us know if that solves this particular issue with the .ToList method.

Cheers,

Ian
 
Back
Top