July 06, 2020, 06:22:29 pm
News: IF YOU ARE A MEMBER FROM THE ORIGINAL SITE AND CAN'T LOGIN. POST IN THE FEEDBACK FORUM (AS GUEST) AND AN ADMIN WILL ASSIST YOU TO ACCESS THE SITE!
Pages: [1]   Go Down
Author Topic: Lost Topic Title  (Read 1584 times)
Pc_Madness
Ancient Poster
*

Stars: +0/-0
Offline Offline

Posts: 5349



WWW
« on: June 23, 2003, 10:42:31 am »

Code:
'Part of the random function...

Do While tempint = IntCurrindex
Randomize
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

tempint = Int(((.lstPlay.ListCount - 1) - 0 + 1) * Rnd + 0)
Loop

does that look right?

If I call it the first time, it generates a number, but on the second run, either it, or some other part of my prog changes it back 2 zero. dunno
« Last Edit: June 24, 2003, 08:29:11 am by Pc_Madness » Logged


amitabh
Old Timer
*

Stars: +0/-0
Offline Offline

Posts: 2764


WWW
« Reply #1 on: June 23, 2003, 12:15:57 pm »

Looks okay to me.
BTW, is the "." before "lstPlay" needed?
Logged

007shahid
Monster Poster
*

Stars: +0/-0
Offline Offline

Posts: 1254



WWW
« Reply #2 on: June 23, 2003, 12:16:11 pm »

Quote
Code:
'Part of the random function...

Do While tempint = IntCurrindex
Randomize
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

tempint = Int(((.lstPlay.ListCount - 1) - 0 + 1) * Rnd + 0)
Loop

does that look right?

If I call it the first time, it generates a number, but on the second run, either it, or some other part of my prog changes it back 2 zero. dunno
Can you post the entire subroutine or the project.
BTW...
Code:
tempint = Int(((.lstPlay.ListCount - 1) - 0 + 1) * Rnd + 0)

Also equals...
Code:
tempint = Int(.lstPlay.ListCount  * Rnd)

And also, your Rnd() might itself be returning '0'.will get 0.
Logged


007shahid
Monster Poster
*

Stars: +0/-0
Offline Offline

Posts: 1254



WWW
« Reply #3 on: June 23, 2003, 12:20:01 pm »

Quote
Looks okay to me.
BTW, is the "." before "lstPlay" needed?
Maybe, he has it inside a With-End statement.
Logged


amitabh
Old Timer
*

Stars: +0/-0
Offline Offline

Posts: 2764


WWW
« Reply #4 on: June 23, 2003, 12:25:04 pm »

"lstPlay"looks like  the name of List Box, that's why I am a little puzzled.
Logged

007shahid
Monster Poster
*

Stars: +0/-0
Offline Offline

Posts: 1254



WWW
« Reply #5 on: June 23, 2003, 12:29:44 pm »

Quote
"lstPlay"looks like  the name of List Box, that's why I am a little puzzled.
He could be initializing another form from the main form. He could also be pulling our leg. (Notice the way the code is written).
Whatever it is, we'll come to know when he replies smile
Logged


manavo
Sr. Member
*

Stars: +0/-0
Offline Offline

Posts: 480



WWW
« Reply #6 on: June 23, 2003, 01:20:04 pm »

Have you declared the variable?
Logged

I come here once a month on average. Should I come here more often?

rjlohan
Founders
*

Stars: +0/-0
Offline Offline

Posts: 2355



WWW
« Reply #7 on: June 23, 2003, 11:30:28 pm »

Quote
Code:
'Part of the random function...

Do While tempint = IntCurrindex
Randomize
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

tempint = Int(((.lstPlay.ListCount - 1) - 0 + 1) * Rnd + 0)
Loop

does that look right?

If I call it the first time, it generates a number, but on the second run, either it, or some other part of my prog changes it back 2 zero. dunno
ll tell you the answer only if you promise to never again to add or subtract zero from anything...   blink
Logged

---------------------------------------
-RJ Lohan
Ryan.J.Lohan@student.uts.edu.au
---------------------------------------
"Second?!? That's just a fancy word for 'loser'!!"
---------------------------------------

Pc_Madness
Ancient Poster
*

Stars: +0/-0
Offline Offline

Posts: 5349



WWW
« Reply #8 on: June 24, 2003, 05:34:31 am »

Quote
Quote
Code:
'Part of the random function...

Do While tempint = IntCurrindex
Randomize
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

tempint = Int(((.lstPlay.ListCount - 1) - 0 + 1) * Rnd + 0)
Loop

does that look right?

If I call it the first time, it generates a number, but on the second run, either it, or some other part of my prog changes it back 2 zero. dunno
ll tell you the answer only if you promise to never again to add or subtract zero from anything...   blink
laugh1

Yeah, I've had a heap of trouble with it in the past, so I've just used that 2 check if its working right. Another Tounge


Yeah, lstPlay is obviously a listbox, on a seperate form, and since I'm using it quite a few times, I'm doing an With - End

Its a few mini functions in one. Another Tounge

Code:
Public Function DecideNextSong(Optional BW As Boolean)
With frmPlayer
Dim i As Integer
'CHECK IF THERES ONLY ONE ITEM IN THE LIST
If Repeat = True And .lstPlay.ListCount = 1 Then
IntCurrindex = 0
Exit Function
ElseIf Repeat = False And .lstPlay.ListCount = 1 Then
IntCurrindex = -1
Exit Function
End If

'RANDOM METHOD
If Random = True Then
Dim tempint As Integer
If BW = False Then    

Do While tempint = IntCurrindex
Randomize
tempint = Int(((.lstPlay.ListCount - 1) - 0 + 1) * Rnd + 0)
Loop
IntCurrindex = tempint

For i = UBound(RndTracker) To 1 Step -1
RndTracker(i) = RndTracker(i - 1)
Next i

RndTracker(0) = tempint

Else      'Code for moving backwards through arrays...


For i = 1 To UBound(RndTracker)
  RndTracker(i - 1) = RndTracker(i)
Next i
RndTracker(UBound(RndTracker)) = 0

IntCurrindex = RndTracker(0)


Exit Function
End If
'THIS IS IF RANDOM IS FALSE
ElseIf Random = False Then             ' non Random system...

If .lstPlay.ListCount = 1 Then 'Only one item in listcount
If Repeat = True Then

IntCurrindex = 0
End If

ElseIf IntCurrindex <= .lstPlay.ListCount - 1 Then
If BW = True Then
If IntCurrindex = 0 Then
IntCurrindex = .lstPlay.ListCount - 1
Else
IntCurrindex = IntCurrindex - 1
End If
ElseIf BW = False Then
If IntCurrindex = .lstPlay.ListCount - 1 Then
If Repeat = True Then
IntCurrindex = 0
Else
Finished = True
Exit Function
End If
Else
IntCurrindex = IntCurrindex + 1
End If

End If
End If
End If
Finished = False
End With
End Function
Logged


rjlohan
Founders
*

Stars: +0/-0
Offline Offline

Posts: 2355



WWW
« Reply #9 on: June 24, 2003, 05:39:06 am »

I'm also not helping until you format that code! Tongue
Logged

---------------------------------------
-RJ Lohan
Ryan.J.Lohan@student.uts.edu.au
---------------------------------------
"Second?!? That's just a fancy word for 'loser'!!"
---------------------------------------

007shahid
Monster Poster
*

Stars: +0/-0
Offline Offline

Posts: 1254



WWW
« Reply #10 on: June 24, 2003, 06:30:41 am »

Quote
I'm also not helping until you format that code! Tongue
But I will smile. And this better be the last time. Next time you should format the code.
The problem is in your 'Do-While-Loop' loop. Every time vb comes to this statement, tempint is always '0' and hence can never not equal IntCurrindex. Hence, the second time onwards, tempint will always be zero, as the Rnd() statement is not executed. You can check for not being duplicate by using a 'Do-Loop-While' loop. I have rewritten a part of the subroutine for you. Just replace it in the appropriate place. It should work perfect.
Code:
'RANDOM METHOD
Randomize

If Random = True Then
    Dim tempint As Integer
    If BW = False Then
        Do
            tempint = Int(lstPlay.ListCount * Rnd)
        Loop While (tempint = IntCurrindex)
Logged


Pc_Madness
Ancient Poster
*

Stars: +0/-0
Offline Offline

Posts: 5349



WWW
« Reply #11 on: June 24, 2003, 08:06:58 am »

doh

Sweet, thanks Shahid.  Remind me to give you a tick, when certain people get round 2 it. Wink

RJ - Make me a little indenter thingy and then I'll post formatted code, I don't have any problems with reading it like that. Wink
Logged


rjlohan
Founders
*

Stars: +0/-0
Offline Offline

Posts: 2355



WWW
« Reply #12 on: June 24, 2003, 11:58:53 am »

PC - I'm not making you anything. Another Tounge
If you get no answers though, it won't bother me. Wink
Logged

---------------------------------------
-RJ Lohan
Ryan.J.Lohan@student.uts.edu.au
---------------------------------------
"Second?!? That's just a fancy word for 'loser'!!"
---------------------------------------

Pc_Madness
Ancient Poster
*

Stars: +0/-0
Offline Offline

Posts: 5349



WWW
« Reply #13 on: June 24, 2003, 12:01:46 pm »

It won't bother me either. Wink Means I answer everything myself. Tongue
Logged


007shahid
Monster Poster
*

Stars: +0/-0
Offline Offline

Posts: 1254



WWW
« Reply #14 on: June 24, 2003, 03:05:36 pm »

No problem Wink. But, better use formatting next time, all it takes is a little push of the 'Tab' key!
Logged


Pages: [1]   Go Up
Print
 
Jump to: