Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

VB 2008 Help

Name: Anonymous 2009-05-21 17:07

Help /prog/, why does this program keep freezing?

'Reaction.exe'

'Picture comes up once, user presses left side of keyboard (Q,A,or Z)'
'Picture comes up a second time, user presses right side of keyboard (P,L,or M)'

'A total of 10 .jpgs, pictures show up randomly, a picture will only show up twice'

'Time (in millisecods) is recorded for each attempt'

'If user presses correct key,'
'For example if user presses 2 and it is the 2nd time the picture has shown up'
'Accuracy goes up a point (maximum of 10)'
'If user presses wrong key, '
'For example if user presses 2 even though the picture has only shown up once'
'Accuracy goes down a point (minimum of 0)'


Public Class Form_Main
    'Declare Globals'
    Public X, I, Num, Flag, Accuracy As Integer = 0
    Public Speed, Timer_Start, Timer_End As Double = 0
    Public Times(20) As Double  'Holds 20 times (since each picture will pop up twice)'

    'MainArray'
    'value = How many images will be used (Default is 10, for 10 pictures)'
    '                           0 = Picture hasn't been used yet'
    '                           1 = Picutre has been used'
    '                           2 = Picture has already been used twice, and will not appear again'
    Dim MainArray(10) As Integer


    ' Start Button click (Main Function)'
    Private Sub Button_Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Start.Click
        'Images branch'
        If RadioButton_Images.Checked Then
            Images()
        End If

    'Functions'
    'Images() Function'
    Private Function Images() As Action
        Do Until (Num = 10)
            Timer_Start = 0
            Timer_End = 0
            Flag = 0
            Timer_Delay.Enabled = False
            Timer_Delay.Interval = Rand(3000, 5000) 'Random delay between 3 seconds and 5 seconds'
            Timer_Delay.Enabled = True
            Do While (Flag = 0)
                Timer_Delay.Enabled = False
                If PictureBox.Visible = False Then
                    DisplayImage()
                    Timer_Start = TimeOfDay.Millisecond
                End If
            Loop
            CalcTime()
        Loop
    End Function

    'Rand() Function (returns a random integer between (x,y) )'
    Private Function Rand(ByVal Low As Long, ByVal High As Long) As Long
        'randomize function
        Randomize()
        Rand = Int((High - Low + 1) * Rnd()) + Low
    End Function

    'DisplayImage() Function'
    Private Function DisplayImage() As Action
        Do Until PictureBox.Visible = True

            Randomize()
            X = Rand(1, 10)  'Get a random number from 1 to 10'

            Select Case X
                Case Is = 1
                    If MainArray(X) = 0 Then                    'First time the picture is used'
                        PictureBox.ImageLocation = "C:\Reaction\Images\1.jpg"
                        MainArray(X) = 1
                        PictureBox.Visible = True
                    ElseIf MainArray(X) = 1 Then                'Second time the picture is up'
                        PictureBox.ImageLocation = "C:\Reaction\Images\1.jpg"
                        MainArray(X) = 2
                        Num = Num + 1
                        PictureBox.Visible = True
                    Else                                        'If MainArray(X) doesn't = 1 or 0'
                    End If                                      'Then endif and get another rand #'
                Case Is = 2
                    If MainArray(X) = 0 Then
                        PictureBox.ImageLocation = "C:\Reaction\Images\2.jpg"
                        MainArray(X) = 1
                        PictureBox.Visible = True
                    ElseIf MainArray(X) = 1 Then
                        PictureBox.ImageLocation = "C:\Reaction\Images\2.jpg"
                        MainArray(X) = 2
                        Num = Num + 1
                        PictureBox.Visible = True
                    Else
                    End If
                Case Is = 3
                    If MainArray(X) = 0 Then
                        PictureBox.ImageLocation = "C:\Reaction\Images\3.jpg"
                        MainArray(X) = 1
                        PictureBox.Visible = True
                    ElseIf MainArray(X) = 1 Then
                        PictureBox.ImageLocation = "C:\Reaction\Images\3.jpg"
                        MainArray(X) = 2
                        Num = Num + 1
                        PictureBox.Visible = True
                    Else
                    End If
...
End Function


    Private Function CalcTime() As Action
        Times(I) = Timer_Start - Timer_End
        I = I + 1   'Records 20 times
    End Function


    Private Sub Form_Main_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

        'Keypress Q, A, or Z if the picture is seen for the first time'
        'Otherwise one accuracy point is deducted'
        If e.KeyChar = "Q" Or "A" Or "Z" Or "q" Or "a" Or "z" Then
            If PictureBox.Visible = True Then
                If MainArray(X) = 1 Then
                    Timer_End = TimeOfDay.Millisecond
                    PictureBox.Image = Nothing
                    PictureBox.Visible = False
                    Accuracy = Accuracy + 1
                    Flag = 1
                Else
                    Timer_End = TimeOfDay.Millisecond
                    PictureBox.Image = Nothing
                    PictureBox.Visible = False
                    Accuracy = Accuracy - 1
                    Flag = 1
                End If
            End If
        End If

        'Keypress for second occurance'
        If e.KeyChar = "P" Or "L" Or "M" Or "p" Or "l" Or "m" Then
            If PictureBox.Visible = True Then
                If MainArray(X) = 2 Then
                    Timer_End = TimeOfDay.Millisecond
                    PictureBox.Image = Nothing
                    PictureBox.Visible = False
                    Accuracy = Accuracy + 1
                    Flag = 1
                Else
                    Timer_End = TimeOfDay.Millisecond
                    PictureBox.Image = Nothing
                    PictureBox.Visible = False
                    Accuracy = Accuracy - 1
                    Flag = 1
                End If
            End If
        End If
    End Sub
End Class

Name: Anonymous 2009-05-21 17:09

Note that there is an End Sub that I just cut out to save space at:

 Private Sub Button_Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Start.Click
        'Images branch'
        If RadioButton_Images.Checked Then
            Images()
        End If

Name: Anonymous 2009-05-21 17:17

NO EXCEPTIONS

Name: Anonymous 2009-05-21 17:20

Read SICP

Name: Anonymous 2009-05-21 17:21

Name: Anonymous 2009-05-21 17:24

>>5
Yep

Name: Anonymous 2009-05-21 17:39

You're using your timer wrong.
gb2/MSDN

Name: Anonymous 2009-05-21 17:42

>>7 here
Use this instead of Timer

Sytem.Threading.Thread.Sleep(milliseconds)

Name: Anonymous 2009-05-21 17:42

>>8
System

Name: Anonymous 2009-05-21 17:47

>>7-9
Thanks for the help, but it still freezes

Name: Anonymous 2009-05-21 18:04

Try using .bmp instead of .jpg

Name: Anonymous 2009-05-21 18:06

>>8,11
Try not helping him

Name: Anonymous 2009-05-21 18:10

>>12
Are there any other /prog/ boards?
Specifically ones that help with code?

Name: Anonymous 2009-05-21 18:12

>>13
Yes, /pr/ on 7chan.
And millions of ``visual basic'' invisionboard-phpbb-etc forums.

Name: Anonymous 2009-05-21 18:14

>>13
stackoverflow.com
programming.reddit.com
prog.on.nimp.org

Name: Anonymous 2009-05-21 19:11

>>15
The last one saved me many times.

Name: Anonymous 2009-05-21 20:39

/prog/ cannot solve the halting problem.

Name: Anonymous 2009-05-21 20:42

>>17
every program you ever write will halt.

Name: Anonymous 2009-05-21 22:21

>>18
That doesn't solve the halting problem, that is, it does not provide a decision procedure for determining whether a given program halts on a particular input.

Name: Anonymous 2009-05-21 23:36

>>19
All programs halt eventually, whether due to successful completion, user interrupt, or system failure.

Name: Anonymous 2009-05-21 23:48

>>20
that solves the halting problem for all programs except one: the universe

Name: Anonymous 2009-05-22 2:43

(defvar *background-image-path* "/mnt/share/b/")
(defun select-random-background-image ()
  "Select a random image"
  (let ((file-list (directory (concatenate 'string *background-image-path* "*.jpg")))
        (*random-state* (make-random-state t)))
    (namestring (nth (random (length file-list)) file-list))))

(run-shell-command (concatenate 'string "display -window root " (select-random-background-image)))

Name: Anonymous 2009-05-22 3:04

>>20
Your decision procedure for the halting problem reads as follows:
return true;
Via direct proof I will demonstrate that this procedure is not sound.
Consider, the following:
while(1);
It can be seen this program does not halt- not only from intuition but from the the fact there is no exit point for it. Your decision procedure however, when run run on this program, asserts that it does halt, creating a contradiction with the supposed soundness of your decision procedure. Q.E.D

Name: Anonymous 2009-05-22 3:38

>>23
Eventually I will end that process and the program will halt.

Q E YOUR D

Name: Anonymous 2009-05-22 3:40

>>24
How do you end a program that has no exit point? And how can you in any way modify the state of the program while it is running?

Name: Anonymous 2009-05-22 4:33

>>23
I don‘t know any language in which ''while(1);´´ is a program at all.  You dare to reason about whether a thing stops, when in truth it does not even start.

Name: Anonymous 2009-05-22 4:53

>>26
perl

Name: Anonymous 2009-05-22 5:45

>>27
$ perl -e'while(1);'
syntax error at -e line 1, near ");"
Execution of -e aborted due to compilation errors.

Name: Anonymous 2009-05-22 6:22

>>26-28
It's valid JavaScript. It stops when Firefox has determined it is not going to stop.

Name: Anonymous 2009-05-22 6:27

>>29
when Firefox has determined it is not going to stop.
You mean when firefox has made a premature guess that it won't stop because it has repeated the same peice of code repeatedly.

Name: Anonymous 2009-05-22 6:33

>>30
Branch prediction.

Name: Anonymous 2009-05-22 7:57

>>31
software
branch prediction

IHBT

Name: Anonymous 2009-05-22 8:21

>>30
It also works when it has repeated the same ``peice''[sic] of code non-repeatedly.

Name: Anonymous 2009-05-22 9:13

Actually Firefox just displays some obnoxious dialog when its 10-second watchdog timer expires while executing javascript. Also, until it does, the UI blocks. Amazing thechnological design, truly the architecture of a genius.

Exercise:Design a testcase that makes the browser unusable while preventing the dialog from showing. You can use multiple tabs/windows to aid you.

Name: Anonymous 2009-05-22 9:23

Name: Anonymous 2009-05-22 10:19

Holy shit OP is this the first time you've ever used VB?
Your trying to program sequentially, but VB is event-based.

Try this instead:
You'll have at least these variables...
Dim X As Integer
'Changed by Rand() Function, determines which image is displayed
Dim Game_Bool As Boolean
'Determines whether game is being played or not
Dim Time_Start As Double
'time(ms) when image is visible
Dim Time_End As Double
'time when user presses key
Dim TimesArray(20) As Integer
'Holds 20 calculated times


Then...
1. Load up 10 PictureBoxes (or an array of them, doesn't matter)
2. Have each one be represented by a number, kind of like what you have there
3. When the user presses the Start button, the ONLY thing it does is make the start button disappear, then selects a random number X from 1-10, and sets a boolean value Game_Bool = True
4. In each of the picture boxes, have their event set up to when Game_Bool = True, And ImageArray(X) = True, their event will run, PictureBox(X).Visible = True, and record the time.
5. When the user presses the key, it will set PictureBox(X).Visible = False, record the time, select a new random number X, and a 3 second delay.


When displaying the image you can even just use one picture box and do,
PictureBox.Image = Image.FromFile(FilePath & "\" & X & "\.jpg")
PictureBox.Visible = True

Just two lines replaces that huge Select Case statement.


That's just a general idea to get you started. You're obviously thinking way too hard, when VB is such an easy language.


tl;dr: Start your program over from scratch, with an event-based mindset.
That Do While (Flag = 0) Loop you have there won't work in VB!

Name: Anonymous 2009-05-22 17:01

>>34
http://waro.su/s.html

this code, in it's current form, has worked exactly the same way since firefox 0.8, and was reported as a bug in firefox 5 years ago. it still hasn't been fixed.

Name: Anonymous 2009-05-22 17:06

>>37
It used to be possible just by nesting hundreds of <marquee>s. That was funny.

Name: Anonymous 2009-05-22 20:41

>>35
software
branch prediction

Read it again.

Don't change these.
Name: Email:
Entire Thread Thread List