Click here to Skip to main content
15,908,661 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
May I know how to do calculation in vb.net?

I have a project which I need to use calculation in the button, when clicked the button, it will minus 1 each time for example. And it will minus off the points in the database.

To be exact, there is a table in database called table1. and there is column call points.

I am thinking of doing it in the way that everytime I click the button, the points of that particular column will be minus off.
Posted

1 solution

To take one off of the value of an item each time the button is pressed, you would do something like this inside the button event:

VB
value = value - 1


In C#, you can use the -= operator to take one off of a value, but I don't believe there is a similar operator in VB.NET.

Adding a database to the mix will make this more complicated. You need to figure out if you want to write to the database each time the button is pressed. If so, you will need to write a query that adds the new value into the spot of the old value. It will most likely be a sql UPDATE statement. Something like this:
SQL
UPDATE yourTable
SET Points = <newvalue>
WHERE id = <the id of the record you are going to update>

If you are just getting started in VB.NET, I would recommend you take a step back at this point and look through some basic tutorials on data access. Read through a few and follow along. That will give you a better grasp of how to attack this type of problem. Trying to solve specific problems without a good foundational understanding of the language makes even simple tasks very difficult.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900