Calculating not working correct?

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
13 posts Page 1 of 2
Contributors
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Calculating not working correct?
Dummy1912
Hello,

What are we doing wrong??
it seems when we load the data from our db it doesn't count correctly
when we do it manually it works fine??????

'not working we get 925.52
Code: Select all
'values are from db
290.00
172.76

iSpent = CDbl(.MyAmount)  + iSpent
'working manually correct value 462.76
Code: Select all
iSpent = Cdbl(290) + Cdbl(172.76)
everything works fine
only the expense won't count correctly :( no idea what we do wrong...
anyone please :D

'our code
Code: Select all
                    Dim attributes As String = "Transactions.setdate,category.name,transactions.amount,transactions.description,transactions.id,groups.type,vendors.name,transactions.status,accounts.type"

                    ' ''if specifying a class id, create appropriate query
                    Dim whereClause As String = "transactions.category ='" & lblwalletname.Tag & "' AND transactions.monthid ='" & iTheMonth & "' AND transactions.yearid ='" & iTheYear & "'"
                    Dim fromClause As String = "LEFT JOIN category ON transactions.category=category.id LEFT JOIN groups ON transactions.type=groups.id LEFT JOIN vendors ON transactions.vendor=vendors.id LEFT JOIN accounts ON transactions.account=accounts.id"

                    Dim empls As SQLiteDataReader = DataBase.executeQuery("SELECT " & attributes & " FROM transactions " & fromClause & " WHERE " & whereClause & " ORDER BY transactions.placecount ASC;")

                    While empls.Read() = True
                        Dim item As New BoxControlItem

                        For i = 0 To 1 Step 1
                            With item
                                .Controls.Clear()
                                .Name = empls.GetValue(4)
                                dates = empls.GetValue(0).ToString
                                .SystemDate = dates.ToString("MMM 
d
yyyy")
                                .MyAmount = CDbl(empls.GetValue(2).ToString)
                                .Amount = FormatCurrency(.MyAmount, 2)
                                If Not empls.GetValue(1).ToString = String.Empty Then
                                End If

                                If Not empls.GetValue(6).ToString = String.Empty Then
                                End If

                                If .SystemDate = dates.Today.ToString("MMM 
d
yyyy") Then
                                    .HighlightedToday = True
                                Else
                                    .HighlightedToday = False
                                End If

                                If empls.GetValue(7).ToString = "True" Then
                                    .mEnabled = True
                                Else
                                    .mEnabled = False
                                End If

                                Select Case empls.GetValue(5).ToString

                                    Case "Income"
                                        If .mEnabled = True Then
                                            .mColor = Color.Lime
                                            iTotAvailable = CDbl(.MyAmount) + iTotBudgetted
                                            .Balance = FormatCurrency(iTotAvailable, 2)
                                        End If
                                    Case "Refund"
                                        If .mEnabled = True Then
                                            .mColor = Color.SteelBlue
                                            iTotAvailable = CDbl(.MyAmount) + iTotBudgetted
                                            .Balance = FormatCurrency(iTotAvailable, 2)
                                        Else
                                        End If
                                    Case "Expense"
                                        If .mEnabled = True Then
                                            .mColor = Color.Crimson
                                            amexpense = CDbl(iTotAvailable - .MyAmount)
                                            iSpent = CDbl(.MyAmount) + iSpent
                                            .Balance = FormatCurrency(amexpense, 2)
                                        End If
                                End Select
                                .Refresh()
                                .Dock = DockStyle.Top
                            End With


                        Next
                        Me.Invoke(New UpdateProgessCallback(AddressOf Me.updateprogress), item)

                        txtTotSpent.Text = FormatCurrency(iSpent, 2)
                           iBalance = iTotAvailable - iSpent
                        If iBalance < 0 Then
                            'Gone over budget
                            Me.txtBalance.ForeColor = Color.Crimson
                            iBalance = -iBalance

                        Else
                            Me.txtBalance.ForeColor = Color.SteelBlue
                        End If
                        Me.txtBalance.Text = FormatCurrency(iBalance, 2)

                    End While

visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Not at my computer at the moment but why is it not...

ispent = Cdbl(.myamount) + Cdbl(iSpent)
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

oh no worries :)
hope your computer isn't broken.

Well... why should we if it doesn't matter if the result is the same :D
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

In your code I can't see where you're setting the value of iSpent?

Also I would check and make sure .MyAmount is the correct output value. Having a quick look over your code it should work...I suspect one of the values is incorrect which is why you're getting the wrong result.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Hi Again,

here is the part of the ispent code
Code: Select all
Case "Expense"
                                        If .mEnabled = True Then
                                            .mColor = Color.Crimson
                                            amexpense = CDbl(iTotAvailable - .MyAmount)
                                            iSpent = CDbl(.MyAmount) + iSpent
                                            .Balance = FormatCurrency(amexpense, 2)
                                        End If
but the output values are correct
so i don't known why it don't show the correct value :(
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

After keep checking and running
it seems it counts always * 2 so when we have the value of expense

172.76 * 2 = 345.52 + 290 = 635.52 + 290 = 925.52

it does always 172.76 *2 and 290 * 2
no idea why even when we add
Code: Select all
While empls.Read() = True
Dim item As New BoxControlItem
 ispent = 0 
then it seems that its calculated anymore :(

any ideas please
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

From the code you've submitted I can't see why your code isn't working. By all accounts it should be working fine and the only thing I can think of is that the ".MyAmount" value is incorrect..but you say it's not so I'm not sure what is going on.

As a quick a dirty fix if it is always outputting the result * 2 then just devide your output total by 2 to get correct result , for example:
Code: Select all
ispent = (CDbl(.MyAmount) + ispent) / 2
Hopefully that should give you the correct result :duh;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Sorry Codenstuff :(
don't work :(
now we get an complete other output

i think we need to restart completely over again by starting a new project :crying;
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Doesn't make sense lol

What about:
Code: Select all
ispent = (CDbl(.MyAmount)) / 2 + ispent
I can't see where/why .MyAmount or ispent is getting doubled.

Maybe:
Code: Select all
ispent = (CDbl(MyAmount)) / 2 + ispent / 2
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

if we use the while
that's a loop

and when we add a msgbox(ispent) we get to see everything from the db income,expense,refund
and then we see it show everytime 2x the same outputs

no idea why :(
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
13 posts Page 1 of 2
Return to “Coding Help & Support”