VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 306,824 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,759 people online right now. Registration is fast and FREE... Join Now!




URGENT. VB6 ->2005 Code change

 

URGENT. VB6 ->2005 Code change, Can you do it?

cgorny80

16 May, 2009 - 01:07 AM
Post #1

New D.I.C Head
*

Joined: 16 May, 2009
Posts: 2

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:
IPB Image
CODE

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:
CODE
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


User is offlineProfile CardPM
+Quote Post


firebolt

RE: URGENT. VB6 ->2005 Code Change

16 May, 2009 - 01:10 AM
Post #2

D.I.C Lover
Group Icon

Joined: 20 Feb, 2009
Posts: 5,475



Thanked: 77 times
Dream Kudos: 1675
My Contributions
Look in the tutorials.
User is online!Profile CardPM
+Quote Post

cgorny80

RE: URGENT. VB6 ->2005 Code Change

16 May, 2009 - 01:59 AM
Post #3

New D.I.C Head
*

Joined: 16 May, 2009
Posts: 2

Ye looked there. Cant really see anything that helps.

Any help would be greatly appreciated
User is offlineProfile CardPM
+Quote Post

BobRodes

RE: URGENT. VB6 ->2005 Code Change

19 May, 2009 - 05:24 PM
Post #4

New D.I.C Head
*

Joined: 19 May, 2009
Posts: 4

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.
User is offlineProfile CardPM
+Quote Post

JackOfAllTrades

RE: URGENT. VB6 ->2005 Code Change

19 May, 2009 - 07:10 PM
Post #5

I exist to Google your problems.
Group Icon

Joined: 23 Aug, 2008
Posts: 5,311



Thanked: 453 times
Dream Kudos: 50
Expert In: Being annoyed with lazy people.

My Contributions
Yeah, let's try VB.NET.
User is offlineProfile CardPM
+Quote Post

tony013

RE: URGENT. VB6 ->2005 Code Change

19 May, 2009 - 09:40 PM
Post #6

New D.I.C Head
*

Joined: 5 May, 2009
Posts: 10



Thanked: 1 times
My Contributions
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
User is offlineProfile CardPM
+Quote Post

noorahmad

RE: URGENT. VB6 ->2005 Code Change

20 May, 2009 - 04:39 AM
Post #7

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,086



Thanked: 142 times
Dream Kudos: 1350
My Contributions
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

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 10:36PM

Live VB.NET Help!

Be Social

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

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month