Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help with increasing Value of Variable in Loop

Status
Not open for further replies.

GPUser05

Technical User
May 31, 2005
32
US
Hi all!

Hope somebody can help me with this.

I have given the Code below. I am trying to increase a varible in loop based on condition and case with 1 or 0.50. For some reason, AmtRP is not increasing by 0.50. It goes to that line of code but it will not increase it by 0.50. If I change the value to say 4 it will increase the AmtRP but not 0.50. I don't have problem with AmtPd and AmtNpd, they do increase by 0.50. Can somebody please look at the code and let me know what I am missing.

I appreciate any help on this. Thank you,


Public Sub CalcAMT()
'determine amount type and add to appropriate bucket
Dim AmtPd, AmtNpd, AmtRP As Integer
Dim AmtFld, TOTFld As Object
Dim fldno As Integer

AmtPd = 0
AmtNpd = 0
AmtRP = 0

For fldno = 1 To 16
Set TOTFld = Me.Controls("TOTD" & fldno)
Set AmtFld = Me.Controls("AMTD" & fldno)
If TOTFld = 0 Then
If Not IsNull(AmtFld) Then
Select Case AmtFld
Case "P"
AmtPd = AmtPd + 1
Case "NP"
AmtNpd = AmtNpd + 1
Case "AH"
AmtRP = AmtRP + 1
End Select
End If
Else
If Not IsNull(AmtFld) Then
Select Case AmtFld
Case "P"
AmtPd = AmtPd + 0.5
Case "NP"
AmtNpd = AmtNpd + 0.5
Case "AH"
AmtRP = AmtRP + 0.5
End Select
End If
End If
Next fldno
Me.TotAmtPd = AmtPd
Me.TotAmtNP = AmtNpd
Me.TotAmtRP = AmtRP
End Sub
 
This line:

Dim AmtPd, AmtNpd, AmtRP As Integer

Says that AmtRP is an integer. If you add .5 to an integer it is no longer an integer.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 




"Dim AmtPd, AmtNpd, AmtRP As Integer

Says that AmtRP is an integer. If you add .5 to an integer it is no longer an integer. "

If you add .5 to an integer the result that NOTHING has been added to the variable.

ALSO your declaration means that AmtPd & AmtNpd are declared as VARIANTS while AmtRP as an INTEGER. EACH variable declaration must have an As DataType following or they DEFAULT to VARIANT.


Skip,

[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue]
 
Sorry I should have been more explicit. I was simply trying to point out the logical inconsistency of trying to add .5 to an integer. Not trying to imply that it would become something else, although reading back over it I can see that it sounds like that.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thank you EBGreen and SkipVought for your prompt response. After I posted here, I realised my mistake that I am declaring as an integer. I just changed it and it worked.
What confused me was that other two were increasing and SkipVought cleared that confusion.

Thank you both for your time.

I appreciate it.

GPuser05
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top