Question Any helpful eyes spot the Problem here

djowatts

New member
Joined
Jun 23, 2011
Messages
1
Programming Experience
3-5
Hi all,

This is my first post here, and I was unsure of whether to post in the database area or the general VB area as I am using DAO to connect to an Access Database (There was no sub board for that) but my question is regarding a calculation and control display that I am doing.

The application is a project tracker, and I am trying to calculate the total spend of the project and display it on either the first tab if it is an open project or the second tab if it is a completed project. For some reason, it is showing 0 for all but one of the projects. If anyones eyes can see the problem I would be really greatful. The code is below

[XCODE] Do While rs2.EOF <> True
If rs2.Fields(0).Value.ToString = pCdeLbl(i).Text.ToString Then
totalspend(i) = totalspend(i) + Int(rs2.Fields(2).Value)
rs2.MoveNext()
Else
rs2.MoveNext()
End If
i = i + 1
Loop
rs2.MoveFirst()
.MoveFirst()
i = 0


Do
While .EOF <> True

If .Fields(0).Value.ToString = pCdeLbl(i).Text And .Fields(19).Value.ToString = "" Then

' Display the total spend for each project

ttlSpendLbl(i) =
New Label
ttlSpendLbl(i).Text = totalspend(i).ToString
ttlSpendLbl(i).Location =
New Point(getx(h), gety(v))
ttlSpendLbl(i).Size =
New Size(50, 30)
v = v + 30
TabPage1.Controls.Add(ttlSpendLbl(i))
ttlSpendLbl(i).Visible =
True

.MoveNext()
i = i + 1
Else

ttlSpendLbl(i) =
New Label
ttlSpendLbl(i).Text = totalspend(i).ToString
ttlSpendLbl(i).Location =
New Point(getx(h), gety(v2))
ttlSpendLbl(i).Size =
New Size(50, 30)
v2 = v2 + 30
TabPage2.Controls.Add(ttlSpendLbl(i))
ttlSpendLbl(i).Visible =
True

.MoveNext()
i = i + 1
End If

Loop
[/XCODE]
 
Is this VB6 code? I didn't realize you could use recordsets in .NET. But I see New Point and stuff that tells me its .NET. I am just reposting to make the code a little more readable. It also seems like you left a With statement out of the code. I would definitely suggest using OleDb .NET objects instead of doing things this way.

 DoWhile rs2.EOF <> True
If rs2.Fields(0).Value.ToString = pCdeLbl(i).Text.ToString Then
totalspend(i) = totalspend(i) + Int(rs2.Fields(2).Value)
rs2.MoveNext()
Else
rs2.MoveNext()
EndIf
i = i + 1
Loop
rs2.MoveFirst()
.MoveFirst()
i = 0


DoWhile .EOF <> True

If .Fields(0).Value.ToString = pCdeLbl(i).Text And .Fields(19).Value.ToString = ""Then

' Display the total spend for each project

ttlSpendLbl(i) = New Label
ttlSpendLbl(i).Text = totalspend(i).ToString
ttlSpendLbl(i).Location = New Point(getx(h), gety(v))
ttlSpendLbl(i).Size = New Size(50, 30)
v = v + 30
TabPage1.Controls.Add(ttlSpendLbl(i))
ttlSpendLbl(i).Visible = True

.MoveNext()
i = i + 1
Else

ttlSpendLbl(i) = New Label
ttlSpendLbl(i).Text = totalspend(i).ToString
ttlSpendLbl(i).Location = New Point(getx(h), gety(v2))
ttlSpendLbl(i).Size = New Size(50, 30)
v2 = v2 + 30
TabPage2.Controls.Add(ttlSpendLbl(i))
ttlSpendLbl(i).Visible = True

.MoveNext()
i = i + 1
EndIf

Loop
 
Last edited:
Back
Top