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

find minimum and maximum 1

Status
Not open for further replies.

limeg95

Programmer
Oct 22, 2009
124
CA
hi!
i am trying to figure it out earlist starting time and latest finished time
here is the code. but i could not find out max and min
thanks in advance.
*****************************
If Right(JobName, 1) = "*" Then
For j = 1 To 16 '''

If Right(Trim(MyScreen.GetString(MyRw, 14)), 1) <> "p" Or _
Right(Trim(MyScreen.GetString(MyRw, 14)), 1) <> "z" Then '''
MyScreen.PutString "S", 6, 4
MyScreen.SendKeys ("<Enter>")
MyScreen.WaitHostQuiet (g_HostSettleTimE)
MyScreen.SendKeys ("F")
MyScreen.SendKeys (" '" + "STARTED - TIME" + "'")
MyScreen.SendKeys ("Enter")
MyRw = MyScreen.Row
myarray(j) = Trim(MyScreen.GetString(MyRw, 54, 6))
myarray2(j) = Trim(MyScreen.GetString(MyRw, 54, 6))
End If

Next j

MyStart = WorksheetFunction.Min(myarray2)

MyFinish = WorksheetFunction.Max(myarray)
Myjobloop = True
End If
'''''''''''''''''''''''''''''''''''''''''''''


 
thank you so much Skip you are really Great. i will try it tomrorow and let you know
thanks your valuable time.
 
skip
i have subscript out of range in
myarray
Cells(i, mycol).Value = TimeSerial(Left(myarray(j), 2), Right(myarray(j), 2), 0)
i already dim myarray(1 to 14)
myarray2(1to 14)

 


What is the value of j, when you get this error?

Common, man. This is 'programming 101'!!! Do some of the heavy lifting!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


Well then that should answer your question, shouldn't it?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
why it is coming subscript out of range?
 

If you do not know the answer to that, your handle should not be 'limeg95 (Programmer)'

As I stated before. This is programming 101.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


It is a good practice, when using loops to process arrays to use LBound and UBound...
Code:
for j = LBound(arry) to UBound(arry)
   msgbox arry(j)
next


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Skip
you have really helping tendency and vast knolowdge .
i have little bit problem here. could you help me again
it shows the last cells value it does not give minimum value
If Cells(i, "B").Value = "s" Then
For j = LBound(myarray) To UBound(myarray)
Cells(i, Mycol).NumberFormat = "h:mm"
Cells(i, Mycol) = TimeSerial(Left(myarray(j), 2), Right(myarray(j), 2), 0)

' MsgBox (Cells(i, Mycol).Value)

Next
Cells(i, Mycol).Value = WorksheetFunction.Min(Cells(i, Mycol))
MsgBox (Cells(i, Mycol))
 



You are not referencing the COLUMN to get Min. You are just referencing a SINGLE CELL...
Code:
    Cells(i, Mycol).Value = WorksheetFunction.Min(Range(Cells(1, Mycol),Cells(i-1, Mycol)))
    MsgBox (Cells(i, Mycol))

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
skip
array stored in one cell only it compares to previous cell to get min, it does not stored with anther cell
 



the MIN function references a RANGE of cells and returns the MIN value.

This...
Code:
Cells(i, Mycol).Value = WorksheetFunction.Min(Cells(i, Mycol))

is absolutely meaningless!!!



Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
skip
i lost totally and confused
myarray(j) = Trim(MyScreen.GetString(MyRw, 2, 5))

it does not store in cells. but from the array i need to get min value and need to store in cell
i think i need to store array values to in cell .and then only we will calculate min
is that any other way?
 



If you need to get the min & max values in your array, then my answer, way back on 24 Nov 09 21:06
Loop thru your array and find the min & max values.


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


BTW, if the ONLY thing you're using the arrays for is to find min & max values, there is no need at all to use arrays.

Just define a nMin and a nMax variables.

Then, as you encounter the actual values on the screen, compare each to the nMin and nMax values to determine if THAT is the new value to store. So when your done looping thru your pages and screens, the variables will contain THE min & max values.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
skip
i tried as per your advise.
but still some how missing my code.
could you please look at it.
thanks
here is the code
-----------------------
For j = 1 To 14

g_HostSettleTimE1 = 75
MyScreen.SendKeys ("<Enter>")

MyScreen.Moveto 2, 15

MyScreen.SendKeys ("F")
MyScreen.SendKeys (" '" + "STARTED - TIME=" + "'")
MyScreen.SendKeys ("<Enter>")
MyScreen.WaitHostQuiet (g_HostSettleTimE1)
MyRw = MyScreen.Row


myStart1 = Trim(MyScreen.GetString(MyRw, 2, 5))

MyScreen.Moveto 2, 15

MyScreen.SendKeys ("<pf3>") 'go to next j in screen
MyScreen.WaitHostQuiet (g_HostSettleTimE1)
MyScreen.SendKeys ("<Enter>")
MyScreen.Moveto 2, 15

MyScreen.SendKeys ("F")
MyScreen.SendKeys (" '" + "STARTED - TIME=" + "'")
MyScreen.SendKeys ("<Enter>")
MyScreen.WaitHostQuiet (g_HostSettleTimE1)
MyRw = MyScreen.Row


myStart2 = Trim(MyScreen.GetString(MyRw, 2, 5))

MyScreen.SendKeys ("<PF3>") 'go to next record in screen

If myStart2 = myStart1 Then
myStart3 = myStart2
ElseIf myStart2 < myStart1 Then
myStart3 = myStart2
ElseIf myStart1 < myStart2 Then
myStart3 = myStart1
End If
' End If

Next j
If Cells(i, "B").Value = "s" Then
Cells(i, Mycol).NumberFormat = "h:mm"
Cells(i, Mycol) = TimeSerial(Left(myStart3, 2), Right(myStart3, 2), 0)
End If
End If



 


Please explain what it IS doing and what it is NOT doing.

Please use REAL DATA examples.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Skip
i have starting time date like 14 data from the screen.like below
min of this data and put it in excel col.
as you said i put it in varibale and compare one and next one which is min store it another variable


20.20
24.15
15.25
20.32
17.28
15.28
17.50
18.25
 



You have TWO screens that you're getting values from. WHere are the values from the second screen?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 



AND...

Exactly WHAT is actually happening?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top