Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > help needed with loop


Reply
 
Thread Tools Display Modes
  #1  
Old 12-05-2003, 05:57 AM
necro necro is offline
Freshman
 
Join Date: Nov 2002
Posts: 45
Default help needed with loop


hi, i have a problem with a loop that i created. This loop presents 45 images in order (which were picked and stored in an array at the form load event), the images are presented one after the other in sequence and this sequence is repeated until 18 mouse clicks have been made.

however, i want to add something to this, out of the 45 images i want to of them to be repeated in succession (randomly) i.e. instead of images going 1,2,3,4,5,6,7....45 i want them to go, randomly, e.g. 1,2,3,4,4,5,6,7,8,9,10,10.....45. How could I go about modifying my preogram to do this? Would be where the images are chosen (this loop):

Private Sub Select_Body()

Dim iCurrentStimulus As Integer
Dim TrialTypeChecker(1 To 45) As Integer
Dim iPickStim As Integer


Do
iPickStim = iPickStim + 1

Do
iCurrentStimulus = Int((45 - 1 + 1) * Rnd + 1)
Loop Until TrialTypeChecker(iCurrentStimulus) = 0 'loop until there are 20 cases filled in the checker array

TrialTypeChecker(iCurrentStimulus) = 1

iBody(iPickStim) = iCurrentStimulus

Loop Until iPickStim = 45

End Sub


or in the main loop that shows the image, and how would i go about this (main loop below

Private Sub Run_Body()

Dim iRunLoop45 As Integer
Dim bMouseCountComplete As Boolean
Dim iElapsedTime As Integer

bMouseCountComplete = False
iMouseCount = 0

iRunLoop45 = 0


Do
iRunLoop45 = iRunLoop45 + 1

For iRunLoop45 = 1 To 45

'start timer
hrt_timer_start iFlowTimer


picture1.Picture = LoadPicture(sDirBody & Body(iBody(iRunLoop45)))

Do
iElapsedTime = hrt_timer_current(iFlowTimer)
If iMouseCount >= 18 Then
bMouseCountComplete = True
Exit Do
ElseIf iElapsedTime >= iTimeFixation Then
Exit Do
End If
Loop

If bMouseCountComplete Then
'stop everything here
Exit Sub
End If
hrt_timer_stop iFlowTimer
hrt_timer_reset iFlowTimer

PictureFixation.Visible = False
picture1.Visible = True
DoEvents

hrt_timer_start iFlowTimer

Do

iElapsedTime = hrt_timer_current(iFlowTimer)
If iMouseCount >= 18 Then
bMouseCountComplete = True
Exit Do
ElseIf iElapsedTime >= iTimeImage Then
Exit Do
End If
Loop

If bMouseCountComplete Then
'stop everything here
Exit Sub
End If
hrt_timer_stop iFlowTimer
hrt_timer_reset iFlowTimer

picture1.Visible = False
PictureFixation.Visible = True
DoEvents

Next iRunLoop45

Loop Until iRunLoop45 = 1


End Sub


Any help would be great (and sorry for the last post concerning this which was really confusing, this is a much clearer version of what i meant....i hope

thank you

andy
__________________
i am a newbie, so you may have to speak slowly:)
Reply With Quote
  #2  
Old 12-05-2003, 06:58 AM
Scotor's Avatar
Scotor Scotor is offline
Freshman
 
Join Date: Nov 2003
Location: Ansbach, Germany
Posts: 36
Default

Can you perhaps Upload your program
Reply With Quote
  #3  
Old 12-05-2003, 12:38 PM
necro necro is offline
Freshman
 
Join Date: Nov 2002
Posts: 45
Default

Quote:
Originally Posted by Scotor
Can you perhaps Upload your program



i will try and zip it all up

thanks

andy
__________________
i am a newbie, so you may have to speak slowly:)
Reply With Quote
  #4  
Old 12-05-2003, 12:44 PM
Cert Cert is offline
Contributor
 
Join Date: Aug 2002
Posts: 515
Default

However you are presenting the images (I didnt look at your code), if you want to pick a random image to display then just generate a random number between 0 or 1 and the highest number that you have..

So it would be something like

Code:
Randomize The_Image_To_Display = (Rnd * the_Highest_Image_Number)
Reply With Quote
  #5  
Old 12-05-2003, 12:48 PM
Thanatos's Avatar
Thanatos Thanatos is offline
Contributor
 
Join Date: Jul 2002
Location: New Paltz, NY
Posts: 447
Default

one thing you can try is making a random number generator say from 1 to 5. Then in the section of code that actually displays the picture loop this many times. This way you should have the succession you are looking and the random repeatability. You should get something like this:
1,1,2,3,3,3,4,4,5,6,7,7,7,8,8,8,8,8,9,9,10,10,10...etc
__________________
Fir Na Tine
Reply With Quote
  #6  
Old 12-05-2003, 01:40 PM
necro necro is offline
Freshman
 
Join Date: Nov 2002
Posts: 45
Default

Quote:
Originally Posted by Scotor
Can you perhaps Upload your program



i have zipped it up
__________________
i am a newbie, so you may have to speak slowly:)
Reply With Quote
  #7  
Old 12-05-2003, 05:13 PM
necro necro is offline
Freshman
 
Join Date: Nov 2002
Posts: 45
Default

Quote:
Originally Posted by Scotor
Can you perhaps Upload your program


this should be it
Attached Files
File Type: zip eba.zip (1.65 MB, 13 views)
__________________
i am a newbie, so you may have to speak slowly:)
Reply With Quote
  #8  
Old 12-06-2003, 04:02 AM
Scotor's Avatar
Scotor Scotor is offline
Freshman
 
Join Date: Nov 2003
Location: Ansbach, Germany
Posts: 36
Default

Hmm, I can't find an "WINHRT32.DLL" so the programm doesn't run
I appendet a programm that counts up a variable (v) to 45. The timer randomizes a variable (i) to 1 or 2. If i = 1 the variable v gets increased, else it repeats his old value, so you can get a series like "1,1,2,2,2,3,4,5,5..."
I hope it helps..
Attached Files
File Type: zip ticker.zip (1.5 KB, 7 views)
Reply With Quote
  #9  
Old 12-06-2003, 04:54 AM
necro necro is offline
Freshman
 
Join Date: Nov 2002
Posts: 45
Default

Quote:
Originally Posted by Scotor
Hmm, I can't find an "WINHRT32.DLL" so the programm doesn't run
I appendet a programm that counts up a variable (v) to 45. The timer randomizes a variable (i) to 1 or 2. If i = 1 the variable v gets increased, else it repeats his old value, so you can get a series like "1,1,2,2,2,3,4,5,5..."
I hope it helps..



thanks i will give it a go i take it i can make i = 1 to 5 or something to decrease the probability of a repeated stim...also attatched is the the winhrt.dll file (ihad to put it in a zip to attatch it) just put it in your windows folder

thanks

andy
Attached Files
File Type: zip winhrt.zip (37.6 KB, 27 views)
__________________
i am a newbie, so you may have to speak slowly:)
Reply With Quote
  #10  
Old 12-06-2003, 05:25 AM
necro necro is offline
Freshman
 
Join Date: Nov 2002
Posts: 45
Default

Quote:
Originally Posted by Scotor
Can you perhaps Upload your program


looks cool but can i specify something in it so it only repeats the number twice and that only 2 repitions of a number happen out of 45 images?

thanks for your help

andy
__________________
i am a newbie, so you may have to speak slowly:)
Reply With Quote
  #11  
Old 12-06-2003, 05:37 AM
Drunen Drunen is offline
Newcomer
 
Join Date: Jul 2003
Location: London
Posts: 8
Default

if you are wanting to display all 45 images and only have say 5 images display twice, then decide before looping through the array which 5 images will repeat, i.e. create an array of five elements and fill it with randomly generated numbers from 1-45. then when you are looping through your 45 images, check the elements of the second array against your index and if you have a match, repeat the picture.

1. create array1 of 5 random numbers 1-45
2. loop through 45 images using index
3. while looping, check index against array1 elements for match
4. if match found, repeat image.
5. make sure that you do not get into endless loop by removing array1 element matched.

make sense?
Reply With Quote
  #12  
Old 12-07-2003, 04:08 PM
necro necro is offline
Freshman
 
Join Date: Nov 2002
Posts: 45
Default

Quote:
Originally Posted by Drunen
if you are wanting to display all 45 images and only have say 5 images display twice, then decide before looping through the array which 5 images will repeat, i.e. create an array of five elements and fill it with randomly generated numbers from 1-45. then when you are looping through your 45 images, check the elements of the second array against your index and if you have a match, repeat the picture.

1. create array1 of 5 random numbers 1-45
2. loop through 45 images using index
3. while looping, check index against array1 elements for match
4. if match found, repeat image.
5. make sure that you do not get into endless loop by removing array1 element matched.

make sense?



i understand in principle it makes perfect sense but i am not sure how to impliment this, could you give me an example please?

thanks

andy
__________________
i am a newbie, so you may have to speak slowly:)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Standards and Practices loquin Tutors' Corner 10 07-28-2006 01:16 PM
simple loop needed johnjuan Excel 2 09-20-2003 01:16 PM
vc++6: any1 know how to use threads eg _beginthread(), _endthread() funcs clockworkorange Miscellaneous Languages 2 06-09-2003 10:20 PM
error trapping of a do while loop...help needed SBGeol General 1 05-18-2003 03:54 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->