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.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
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
only the expense won't count correctly :( no idea what we do wrong...
anyone please
'our code
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
'working manually correct value 462.76
'values are from db
290.00
172.76
iSpent = CDbl(.MyAmount) + iSpent
Code: Select all
everything works fineiSpent = Cdbl(290) + Cdbl(172.76)
only the expense won't count correctly :( no idea what we do wrong...
anyone please

'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
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
Not at my computer at the moment but why is it not...
ispent = Cdbl(.myamount) + Cdbl(iSpent)
ispent = Cdbl(.myamount) + Cdbl(iSpent)
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
oh no worries 
hope your computer isn't broken.
Well... why should we if it doesn't matter if the result is the same

hope your computer isn't broken.
Well... why should we if it doesn't matter if the result is the same

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
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
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.
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.
Hi Again,
here is the part of the ispent code
so i don't known why it don't show the correct value :(
here is the part of the ispent code
Code: Select all
but the output values are correctCase "Expense"
If .mEnabled = True Then
.mColor = Color.Crimson
amexpense = CDbl(iTotAvailable - .MyAmount)
iSpent = CDbl(.MyAmount) + iSpent
.Balance = FormatCurrency(amexpense, 2)
End If
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
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
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
any ideas please
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
then it seems that its calculated anymore :(While empls.Read() = True
Dim item As New BoxControlItem
ispent = 0
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
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
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:

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
Hopefully that should give you the correct result ispent = (CDbl(.MyAmount) + ispent) / 2

Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
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
don't work :(
now we get an complete other output
i think we need to restart completely over again by starting a new project

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
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
Doesn't make sense lol
What about:
Maybe:
What about:
Code: Select all
I can't see where/why .MyAmount or ispent is getting doubled.ispent = (CDbl(.MyAmount)) / 2 + ispent
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.
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 :(
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
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
Copyright Information
Copyright © Codenstuff.com 2020 - 2023