multiple choice quiz- adding up score - button

so my intention is to build a quiz on visual basic it is a multiple choice quiz,
i am using 4 buttons as the answer so what I want to do is if they click the correct answer it adds 1 to the score but if they click the wrong button it doesn't add anything. I'm going to be using like 5 questions per level and there are 5 levels and I am going to display the total after they have answered on separate form at the end. Does anyone know how I would go about doing all this

First of all, on the questions if you've got it advancing to the next stage I imagine you have a method to determine whether the answer that they are inputting is correct? If I am right, then this should be pretty simple to do.
You want to declare total score as a variable, this will store the overall score.
To do this you can go like...
Dim totalscore As Integer
totalscore = "0"
It is important to set the score on the startup.
Now on the process when you click the correct answer you want to just put a simple statement like
totalscore = totalscore + 1
This'll add 1 to the score when they advance. You can implement this anyway you like for example you can say
If correctanswer.checked = true then
totalscore = totalscore + 1
End If
Let me know how you get on

Related

Asp.net create function Student of the day

Im working on a ASP.net web application about my class.
All students have their own webform site with an own link refering to thier page.
But I´m trying to do a function for the homepage "student of the day".
I know that i have to put all student links in an array and randomize them.
My problem is that i want the studentlink to change every 24 hours.
How can I make a timer to pick a new object from the array.
Cheers
I'd agree with the comment that has been posted, however I am going to assume that you dont have a database at the moment, or you would alreday be using that rather than an array...
I minght have missed something in your question but I think we can use the pseudo random number generator with a seed based on today to get the "Random Number"
//I am assumung that you already have an array of students created at this point.
Random rnd = new Random(DateTime.Now.Day);
int selectedStudent = Console.WriteLine(rnd.Next(1, 6));
object student = studentArray[selectedStudent];
Because the seed is the same every time you should get the same result every time until the seed changes and that happens when the day changes.
Of course this will not work unless you create a new instance of rnd each time that you need to generate the number.
Hope this helps, if not let me know.

How to update the particular column values of gridview on specific dates using vb.net?

I have column in database
ID From To s1from s2to s2price fare
1 Delhi Manali 17-Dec-2010 19-Dec-2010 $900 $600
2 USA Canada 18-Dec-2010 20-Dec-2010 $500 $800
3 Newyork salinas 19-Dec-2010 22-Dec-2010 $760 $1000
I want when any user search For: Delhi to Manali on between 17-Dec-2010 to 19-Dec-2010 then the price would be automatically changes to $900 in gridview else the default price wold be displayed in fare is $600 if he search for DelHi to Manali after 19-Dec-2010.
I m confused how to implement this logic ... using vb.net ...
If I understand correctly, I think you could do using this query:
SELECT DateSpecificFare = CASE WHEN s1from <= inDate AND s2to >= inDate THEN s2price ELSE fare END FROM YourTable WHERE From = inFrom AND To = inTo
Where inDate, inFrom and inTo would be the parameters the user selects.
Your previous query also made it look like you might not know how to make the calls to the database so if that's the case, look at SqlCommand.ExecuteScalar which includes some sample code showing you how to do that. Or if you need to return more than one column and/or record from your table, look at SqlCommand.ExecuteReader instead.
Btw, you should really edit your previous question rather than create a new one, otherwise it might get closed as a duplicate. But in this case I'll answer this one rather than the previous ones since this is the one with the best question.

Weighting function for favorites

I've got a list of items. Users can occasionally select them. Now I want to order the items by their popularity. What's a good weighting function for that?
Constraints:
The weight should be in [0,1)
Recursive calculation is prefered (not required)
Newer events must have more influence than old ones.
I'd favor approved functions. As I've developped something like this once and it worked not as expected.
Now I want to order the items by their popularity.
So you order by the number of times some user selected the item.
The weight should be in [0,1).
Fine, divide by the total number of times some user selected some item plus one.
Recursive calculation is prefered
Why? Maybe I'm missing the point of what you're trying to do because otherwise this constraint is lost on me.
Edit:
Responding to your edit, try
sum ( 1 / age of vote ) / age of item
the sum being taken over all votes for a given item.
If you have a counter of votes per item, you can use a 'fading constant' in order to make older votes "fade away" with time. Something like:
Nvotes(i) = IsClicked(i) + Nvotes(i) * Kfade
where: 0 < Kfade < 1
Thus, whenever a new click is intercepted, all counters are advanced where only the selected item is incremented by 1.
EDIT: Since the total is less than 1, you may want to normalize Nvotes by the total number of clicks so far.
Keep a list items of the items that need sorting. Let each item have a score. Keep a list clicks of the N most recent clicks, in order of decreasing recency. Each item can appear more than once in the list. Choose a constant fade a little smaller than 1. Then do:
for item in items:
item.score = 0.0
bonus = 1.0
for item in clicks:
item.score += bonus
bonus *= fade
Now sort the items by score, highest first.
The score isn't in the range 0 to 1, but i don't see why you actually need that. It would be straightforward to normalise the scores afterwards.
This isn't recursive, but it's straightforward to put in recursive form.
This isn't a known algorithm. I don't know of any known algorithms for this except move-to-front, which is almost certainly more aggressive than you want.

Change item sortorder in gridview - LINQToSQL

I've got a gridview with a list of categories. In the database (MSSQL2008), the category table has a SortOrder(INT) NULL field.
Currently categories are retrieved using:
Galleries.DataSource = From G In DB.GalleryCategories Order By G.SortOrder, G.Name
Now, what I need to be able to do is add "Move Up" and "Move Down" buttons to each row to allow the user to sort the items in an arbitrary way.
My initial thoughts are along the lines of:
Identify ID of selected item.
Identify ID of item before/after selected item.
Swap of identified items in the DB SortOrders.
I would then have make the sortorder NOT NULL and make sure it's initialised to a unique number
I'd appreciate any alternative suggestions / comments on this approach
Many thanks
I have generally seen it done this way, and have done it myself
SortOrder is an int
Each item increases by 10 (so, 10,20,30,40) or suitable increment
To move an item up, subtract 15
To move an item down, add 15
To insert an item, take the target and add/subtract 1
Apply a NormalizeSort() routine which resets the values to even intervals
10,20,25,30,40 => 10,20,30,40,50
That makes it all pretty simple, since inserting something above something else is just:
list.Add( New Item(..., target.SortOrder +1) )
list.NormalizeSort()
// or
item.SortOrder += 11, etc
If you want to make it a decimal, then you can just make it all sequential and just add .1, etc to the sort order and re-normalize again.
// Andrew
I believe
Galleries.AllowSorting = true;
would be far enough ;)

Adding up total cost - ASP while

i am simple cart page where it displays the content in table form and I am trying to find a way to add up the Cost column then display the total price at the bottom. Does anyone have any suggestions how to do that? The part that is confusing me is that it the table is dynamically created via ASP.
My code can be found here: http://pastie.org/341676
Any suggestions?
First off, that is a special kind of painful (asp classic in all its glory)
What you need is another variable to hold your values, and then sum it in each loop iteration
While Not objRS.EOF
totalCost = trim(objRS.Fields("quantity"))*trim(objRS.Fields("p_price"))
absoluteTotal = absoluteTotal + totalCost
...
Wend
Response.Write absoluteTotal
That will output a sum of all the totals, although you would probably want to format it better with html and whatnot

Resources