-
Jan 29th, 2012, 04:15 PM
#1
Thread Starter
New Member
adding totals?
hi im new to programming, started only a few days ago, so i don't know most of the definitions or jargon!
but iv got a a asisignment where i have to a daily total and add it to the weekly total if that makes sense?
basically
weekTotal = 0 + dailyTotal
now i know thats not the proper way beacause it resets each time. what i wana do is
weekTotal = weekTotal + dailyTotal
but i dont know how to do it! i read something online about using += to do it but when i do i get end of statement expected.
what do i do?
-
Jan 29th, 2012, 04:37 PM
#2
Re: adding totals?
Code:
weekTotal = weekTotal + dailyTotal
would work same as below. You must be doing something else. Please post your code.
Code:
weekTotal += dailyTotal
-
Jan 29th, 2012, 09:16 PM
#3
Re: adding totals?
I would imagine that this is a scope issue. If you are declaring 'weekTotal' inside a method then it only exists inside that method, so it's value defaults to zero each time. If you want it to maintain its value between method calls then it must exist outside the method, i.e. you must declare it outside the method.
-
Jan 31st, 2012, 01:55 PM
#4
Thread Starter
New Member
Re: adding totals?
Originally Posted by jmcilhinney
I would imagine that this is a scope issue. If you are declaring 'weekTotal' inside a method then it only exists inside that method, so it's value defaults to zero each time. If you want it to maintain its value between method calls then it must exist outside the method, i.e. you must declare it outside the method.
erm do you mean a global variable? if so how do i go about setting it up? iv only started rogramming recently as part of my ict class, and had a few lessons so fr, so tryin to do a crash course!
-
Jan 31st, 2012, 02:41 PM
#5
Hyperactive Member
Re: adding totals?
Unless I have grossly misunderstood, you are pretty much there. Try this on for size.
http://pastebin.com/7F0U41mF
(If you need to enter values through text boxes on a form. Try something like this.)
http://pastebin.com/Q51kCawj
Last edited by intraman; Jan 31st, 2012 at 02:46 PM.
-
Jan 31st, 2012, 05:33 PM
#6
Re: adding totals?
Originally Posted by moynzzee
erm do you mean a global variable? if so how do i go about setting it up? iv only started rogramming recently as part of my ict class, and had a few lessons so fr, so tryin to do a crash course!
No I don't mean a global variable. I mean just what I said. A variable declared inside a method (Sub, Function or the Get or Set of a property) is a "local variable" while anything declared outside is a "member variable", also known as a "field". Any properties, methods, events, non-local variables, etc, that you declare within a type, e.g. a form, are all known as members. E.g.
vb.net Code:
Public Class SomeType
Private memberVariable As Object
Public Sub SomeMethod()
Dim localVariable As Object
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|