School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,154 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,958 people online right now. Registration is fast and FREE... Join Now!



URGENT. VB6 ->2005 Code change

Page 1 of 1

URGENT. VB6 ->2005 Code change Can you do it? Rate Topic: -----

#1 cgorny80  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 2
  • Joined: 16-May 09


Dream Kudos: 0

Posted 16 May 2009 - 01:07 AM

Hey

i have code of a reaction time test in VB6 that works fine however i need it in VB 2005... im assuming its the same as 2008?

The code isnt that big its fairly understandable however i just cant get it to work as some things in vb6 are different to 2005.

What the program does is. You click the green GO and it changes to a yellow. Then random time intervals a box will turn red and you click it as fast as you can.. then a msgbox pops up. you do this 5 times and get an average.

Things i cant work out how to fix when i convert:
Timer
Wait
DoEvents
Checkbox = 1 or 0 .. always underlined under the 1 and 0

What are the equivalent of those in the newer versions?


Thats it, image:
Posted Image
Public fin As Integer


Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If (Not UserForm1.CommandButton1.BackColor = &HFFFF&) Then

Dim score(1 To 5) As Double
UserForm1.CommandButton1.BackColor = &HFFFF&

Rem: wait a random time 1-5 seconds

Dim PauseTime, Start, Finish, TotalTime, butto

While fin < 6
fin = fin + 1
	PauseTime = Rnd * 4 + 2   ' Set duration 2 to 6 seconds
	Wait = Timer	' Set start time.
	Do While Timer < Wait + PauseTime
		DoEvents	' Yield to other processes.
	Loop

	butto = Int(Rnd * 4)
	Select Case butto
	Case 0
			UserForm1.CommandButton6.BackColor = &HFF&
	Case 1
			UserForm1.CommandButton3.BackColor = &HFF&
	Case 2
			UserForm1.CommandButton4.BackColor = &HFF&
	Case 3
			UserForm1.CommandButton5.BackColor = &HFF&
	Case 4
			UserForm1.CommandButton5.BackColor = &HFF&
	End Select
	
   
	Start = Timer	' Set Go time.
		Do While UserForm1.CheckBox1 = 0 And Timer < Start + 5
		DoEvents	' Yield to other processes.
	Loop
	Finish = Timer
	TotalTime = Finish - Start	' Calculate total time.
	score(fin) = TotalTime
	
	
	MsgBox "Try " & fin & ":  You took " & TotalTime & " seconds"
  
	
	If (fin >= 5) Then
	ave = (score(1) + score(2) + score(3) + score(4) + score(5)) / 5
	Comment = " Not Bad!"
	If ave < 0.75 Then Comment = " Pretty good!"
	If ave > 1# Then Comment = " Not so good, perhaps you should try again."
	MsgBox "Average reaction time = " & ave & " seconds. " & Comment
	
	Sheet1.Cells(10, 3) = ave
	
	End
	End If
	

Rem: activate one of 4 buttons, record time

	UserForm1.CommandButton6.BackColor = &H8000000F
	UserForm1.CommandButton3.BackColor = &H8000000F
	UserForm1.CommandButton4.BackColor = &H8000000F
	UserForm1.CommandButton5.BackColor = &H8000000F
	UserForm1.CheckBox1 = 0
	
Wend

UserForm1.CommandButton1.BackColor = &HFF00&
End If
End Sub



Sub CommandButton3_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If (UserForm1.CommandButton3.BackColor = &HFF&) Then UserForm1.CheckBox1 = 1
End Sub

Sub CommandButton4_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If (UserForm1.CommandButton4.BackColor = &HFF&) Then UserForm1.CheckBox1 = 1
End Sub

Sub CommandButton5_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If (UserForm1.CommandButton5.BackColor = &HFF&) Then UserForm1.CheckBox1 = 1
End Sub

Sub CommandButton6_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If (UserForm1.CommandButton6.BackColor = &HFF&) Then UserForm1.CheckBox1 = 1
End Sub





My 2005 Version so far not working at all:
Public Class UserForm
	Public fin As Integer
	Dim Comment As String
	Dim ave As Integer
	Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
		If (Not CommandButton1.BackColor = Color.Yellow) Then

			Dim score(0 To 5) As Double
			CommandButton1.BackColor = Color.Yellow


			REM: wait a random time 1-5 seconds

			Dim PauseTime, Start, Finish, TotalTime, butto

			While fin < 6
				fin = fin + 1
				PauseTime = Rnd() * 4 + 2   ' Set duration 2 to 6 seconds
				Wait = Timer	' Set start time.
				Do While Timer1 < Wait + PauseTime
					DoEvents() ' Yield to other processes.
				Loop

				butto = Int(Rnd() * 4)
				Select Case butto
					Case 0
						CommandButton6.BackColor = Color.Red
					Case 1
						CommandButton3.BackColor = Color.Red
					Case 2
						CommandButton4.BackColor = Color.Red
					Case 3
						CommandButton5.BackColor = Color.Red
					Case 4
						CommandButton5.BackColor = Color.Red
				End Select


				Start = Timer1	' Set Go time.
				Do While CheckBox1 = 0 And Timer < Start + 5
					DoEvents() ' Yield to other processes.
				Loop
				Finish = Timer
				TotalTime = Finish - Start	' Calculate total time.
				score(fin) = TotalTime


				MsgBox("Try " & fin & ":  You took " & TotalTime & " seconds")


				If (fin >= 5) Then
					ave = (score(1) + score(2) + score(3) + score(4) + score(5)) / 5
					Comment = " Not Bad!"
					If ave < 0.75 Then Comment = " Pretty good!"
					If ave > 1.0# Then Comment = " Not so good, perhaps you should try again."
					MsgBox("Average reaction time = " & ave & " seconds. " & Comment)



					End
				End If


				REM: activate one of 4 buttons, record time

				CommandButton6.BackColor = Color.White
				CommandButton3.BackColor = Color.White
				CommandButton4.BackColor = Color.White
				CommandButton5.BackColor = Color.White
				CheckBox1 = 0

			End While

			CommandButton1.BackColor = Color.White
		End If
	End Sub


	Sub CommandButton3_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
		If (CommandButton3.BackColor = Color.Red) Then CheckBox1 = 1
	End Sub

	Sub CommandButton4_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

		If (CommandButton4.BackColor = Color.Red) Then CheckBox1 = 1
	End Sub

	Sub CommandButton5_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

		If (CommandButton5.BackColor = Color.Red) Then CheckBox1 = 1
	End Sub

	Sub CommandButton6_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

		If (CommandButton6.BackColor = Color.Red) Then CheckBox1 = 1
	End Sub
End Class


Was This Post Helpful? 0
  • +
  • -


#2 firebolt  Icon User is offline

  • D.I.C Lover
  • Icon
  • View blog
  • Group: Author w/DIC++
  • Posts: 5,555
  • Joined: 20-February 09


Dream Kudos: 1675

Posted 16 May 2009 - 01:10 AM

Look in the tutorials.
Was This Post Helpful? 0
  • +
  • -

#3 cgorny80  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 2
  • Joined: 16-May 09


Dream Kudos: 0

Posted 16 May 2009 - 01:59 AM

Ye looked there. Cant really see anything that helps.

Any help would be greatly appreciated
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 4
  • Joined: 19-May 09


Dream Kudos: 0

Posted 19 May 2009 - 05:24 PM

This is essentially a VB.Net question, if you think about it. I would suggest that you do what you can on the conversion, then find specific areas of difficulty and ask about them in the VB.Net forum. I would also make sure that you only post the relevant code rather than the whole thing. If you do this, you're more likely to get help.
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is online

  • Mayor of Simpleton
  • Icon
  • View blog
  • Group: Moderators
  • Posts: 7,131
  • Joined: 23-August 08


Dream Kudos: 50

Expert In: Being annoyed with lazy people.

Posted 19 May 2009 - 07:10 PM

Yeah, let's try VB.NET.
Was This Post Helpful? 0
  • +
  • -

#6 tony013  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 10
  • Joined: 05-May 09


Dream Kudos: 0

Posted 19 May 2009 - 09:40 PM

I will not open a new thread for this , I wonder if it can be converted VB 6 code to VB 2008 code.For once I have now found that could be converted code vb 6 to vb 2008.Thanxs
Was This Post Helpful? 0
  • +
  • -

#7 noorahmad  Icon User is offline

  • Author
  • Icon
  • View blog
  • Group: Author w/DIC++
  • Posts: 2,198
  • Joined: 12-March 09


Dream Kudos: 1600

Posted 20 May 2009 - 04:39 AM

Replace of DoEvents you can use Application.DoEvents()
Replace of Checkbox.value = 0 or 1 you can use Checkbox1.Checked
For Waiting you need a Timer.Tick() and Interval Property to 1000 for one seconds
hope it will help you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month