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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to get the minimum value to load in a var...

Status
Not open for further replies.

MkIIISupra

Programmer
Apr 17, 2002
108
US
I am doing a search for the high and low of a series of records, from there I will get the standard deviation and then compare a new read against that to see if it is within the realm of reasonable. If it isn't then I can research the problem and correct it before I update any tables. Here is the complete code string so it all makes sense:

Option Compare Database
Option Explicit


' Public Variables
Dim stDocName, stLinkCriteria, tblClr, strInput, strMsg, stHold _
, stHigh, stLow As String
Dim intCnt, intCnt2, intHigh, intLow As Integer

Private Sub Form_Load()

DoCmd.Maximize
stHigh = Me.USAGE ' Initialize USAGE to get the high low
stLow = Me.USAGE ' Initialize USAGE to get the high low
stHold = Me.ID_CODE
intCnt = 0

Do

If (Me.USAGE) > stHigh Then
stHigh = Me.USAGE
End If

' Here is where I am having problems! I have tried several iterations of this and all of them fail. I want the lowest number encountered to be trapped in the stLow field. But it's not happening. When I step through the code 385 is the lowest, the number right after that is 1149... now last time I checked 1149 in NOT less than 385... and yet, even though I have specified NOT to load stLow with USAGE... it still does! WHY?

If (Me.USAGE) < stLow Then
stLow = Me.USAGE
Else
stLow = stLow
End If

If (stHold) = (Me.ID_CODE) Then
intCnt = intCnt + 1
DoCmd.GoToRecord , , acNext
Else
Me.Text22.VALUE = Me.Text22 & vbCrLf & "ID_CODE = " & stHold & " Records = " _
& intCnt & " HIGH USAGE = " & stHigh & " LOW USAGE = " & stLow

stHold = Me.ID_CODE
stHigh = Me.USAGE
stLow = Me.USAGE
intCnt = 0

End If

Loop Until
IsNull(Me.ID_CODE)

Me.Text22.VALUE = Me.Text22 & vbCrLf & "ID_CODE = " & stHold & " Records = " _
& intCnt & " HIGH USAGE = " & stHigh & " LOW USAGE = " & stLow

End Sub

Again, I do not understand why the > works just fine and gives me the Max value and skips like it is supposed to and yet the < doesn't work at all!

One by one the penguins return my sanity, as day by day Microsoft steals my sanity!

OpenSuSE 10.0 kicks fanny!
 
Here is some output to help...

This is the actual output of the code in my first post:
ID_CODE = E10301 Records = 9 HIGH USAGE = 1819 LOW USAGE = 1149

This is the output, what I have done is concated each instance of LOW USAGE writing. So what you are seeing are
the LOW USAGE numbers in the sequence they are listed in the table. Note that 1149 is the final output above, yet
386 is the lowest number and according to the code should be the only one listed.
ID_CODE = E10301 Records = 9 HIGH USAGE = 828 1149 LOW USAGE = 828 525 386 1149 1457 1248 1592 1211 1819 722

One by one the penguins return my sanity, as day by day Microsoft steals my sanity!

OpenSuSE 10.0 kicks fanny!
 
Seems you compare strings, so "1149" is less than "386".

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Oh... man do I feel like a knuckle head... Thanks!

One by one the penguins return my sanity, as day by day Microsoft steals my sanity!

OpenSuSE 10.0 kicks fanny!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top