Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Visual Basic for Applications

Post new topic   Reply to topic
Timming principles/arrays/graphs
View previous topic :: View next topic  
Author Message
gphillips
Newbie


Joined: 13 Oct 2005
Posts: 22

PostPosted: Oct 27th, 2005 07:19 AM    Post subject: Timming principles/arrays/graphs Reply with quote

This is the timing code my friend:-

Using vb 6.0.
Basically I am creating an application with three command buttons start , exit, export. Once the user presses start, it produces a random letter a-z (ascii) after a random time of between 1 and 5 seconds. The user then types the letter appearing in the start command and the timer monitors how long it took to produce type this letter.N.B I have used the timer from the tool box. A yellow graph (histogram) will record time taken and frequency. The horizontal x axis has a range of 0 to 2 seconds and increments of 0.2 on the label. The y axis (vertical) will record the frequency, i.e. how many times it took 0.2 seconds. The y axis vertical has a range 0 to 20 with increments of 0.5 on the label. There should be three text boxes but this one contains 2 textbox and 1list box that is supposed to be be “displaying a record of all times taken”. The two text boxes are txtouput/txttime.text. Time records single time as per letter shown, but the list box shows a list of all time records.

This is the code I have so – I would really appreciate a simpler break down as I don’t understand. Some of this code might not be tidy i.e missing properties like before, misplacing etc. Just point them out m8. Key preview was set to false by default , it needs to be set to true for this to work , what is key preview and why is this the case?


‘why does the freq need to be declared as an array?
Dim freq(20) as integer
Dim timetaken as double
Dim endtime as double
Dim start time as integer
Dim correctkey as integer
Dim seconds as integer.


Private Sub cmdStart_Click()
‘ Is the if correct key key > 122 needed , thought it would recognise that it should only be 26 characters above i.e a- z. frmkeypresstimer.Setfocus?. tmrone.interval – what the theory behind 1000 + 4000 * rnd , why not 5000 * rnd. Why two randomise and rnd (). My belief is the interval is creating a delay which is good but the theory I don’t follow.

Randomize
tmrone.interval = 1000 +4000 * Rnd ()
txtoutput.text = “”
txttime.text = “”
correctkey = 97 + (26 * Rnd())
If correctkey > 122 then
correctkey = 122
End if
frmkeypresstimer.SetFocus
End Sub

Private Sub Form Load()

‘What is the theory behind including these and or anything in form load. I am told that colour won’t be shown visible unless its in the form load (initialisation). Why is the for i code placed in the form load. Is this misplaced. What is it doing? Why does seconds have to go here.

seconds = 0
frmkeypresstimer.show
Line (500, 4500)-(5500, 2500), vbWhite, BF
For i = 1 to 20
Freq(i) = 0
Next i
End sub

Private Sub tmrone_Timer()
‘Why $ on Chr, don’t understand this function, why does it recognise “timer” as a valid and useable. Why space before character function. Don’t understand the logic here.

txtoutput.text = “ “ & Chr$(correctkey)
starttime = timer
tmrone.interval = 0
End Sub

Private Sub Form_Keypress (keyascii as integer)

‘ Don’t understand this, what is the int(1000 *, doing – what the logic here and why).
‘ How does the computer recognise – bar – does it need to be declared as variable.
‘ What is the maths that making the bar chart to work, I apreciate 1000 milliseconds – is eqiv to 1 seconds. How does the maths work in relation to 0 to 2 (timetaken –x axis) 0 to 20 in relation to freq (y axis). bar = timetaken/100 – why? etc etc.
‘ is the list box just showing time taken and not frequency i.e both.
' simple break down would greatly appreciated.


If keyascii = correctkey then
endtime = timer
timetaken = Int(1000 * (endtime-starttime))
txttime.text = str(timetaken)
lst.AddItem str(timetaken)

‘Getting lost here with the maths – and the breakdown.

bar =timetaken/100
If bar >20 then
Bar =20
End If

‘why bar in bracket- don’t follow the theory.
Freq(bar) =freq(bar) + 1

Line (500, 4500)-(5500,2500),vbWhite, BF
Line (500,4000)-(5500,4000),vbBlack
Line (500,3500)-(5500,3500),vbBlack
Line (500,3500)-(5500,3000),vbBlack
X1=500
Y1=4500

For i = 1 to 20
X2 = X1+250
Y2 = Y1 – 100 * freq (i)
Line (x1,y1)-(x2,y2), vbYellow, BF
Line (x1, y1)-(x2,y2), vbBlack, B
X1 = X1 + 250
Next i

End sub


Thanks very much Pal,

G
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Visual Basic for Applications All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic