|
-
Dec 13th, 2006, 04:44 AM
#1
Thread Starter
New Member
-
Dec 14th, 2006, 12:48 PM
#2
Re: Psuedocode leading to VB6 *Help needed*
You could shorten it a bit
VB Code:
For Count 1 to 25
'grid location
do
randomX = randomnumber() * 15
randomY = randomnumber() * 15
until array(randomX,randomY) = 0
array(randomX,randomY) = 1
next Count
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Dec 15th, 2006, 02:28 AM
#3
Thread Starter
New Member
Re: Psuedocode leading to VB6 *Help needed*
thnx heaps. That was the tricky part, now to find a way to sensibly code that in vb6.
edit
*any help would be awesome*
Last edited by -=J_D=-; Dec 15th, 2006 at 03:07 AM.
-
Dec 15th, 2006, 03:16 AM
#4
Re: Psuedocode leading to VB6 *Help needed*
 Originally Posted by -=J_D=-
thnx heaps. That was the tricky part, now to find a way to sensibly code that in vb6.
Al42 pretty much did. (you also don't need to fill the array with 0, if you use a numeric type - a byte in this case presumably)
-
Dec 15th, 2006, 03:20 AM
#5
Thread Starter
New Member
Re: Psuedocode leading to VB6 *Help needed*
 Originally Posted by bushmobile
Al42 pretty much did. (you also don't need to fill the array with 0, if you use a numeric type - a byte in this case presumably)
i pretty much have only just started with vb, and i get a syntax error when i put that code in
For Count 1 to 25
&
until array(randomX,randomY) = 0
array(randomX,randomY) = 1
come up in red, which i presume is where the error is??
-
Dec 15th, 2006, 03:35 AM
#6
Re: Psuedocode leading to VB6 *Help needed*
For line needs and "="
Until line needs a "Loop" in front of it (to complete the do loop)
the last line is red because Array is a reserved word, so you have to declared your array as something different.
-
Dec 15th, 2006, 04:30 AM
#7
Thread Starter
New Member
Re: Psuedocode leading to VB6 *Help needed*
ok, im up to here, i think it works. is there some way to view the entire array to see ifit really did what it was supposed to?
this is where im up to with the code now
VB Code:
Option Explicit
Function Random(Lowerbound As Long, Upperbound As Long)
Randomize
Random = Int(Rnd * Upperbound) + Lowerbound
End Function
Private Sub Command1_Click()
Dim randomX As Integer
Dim randomY As Integer
Dim count As Integer
For count = 1 To 25
'grid location
Do
randomX = Random(1, 15)
randomY = Random(1, 15)
Loop Until tombset(randomX, randomY) = 0
tombset(randomX, randomY) = 1
Next count
End Sub
and the module
VB Code:
Public tombset(15, 15) As Integer
Public Random As Integer
Last edited by -=J_D=-; Dec 15th, 2006 at 05:29 AM.
Reason: slight change/s HEAPS lol
-
Dec 15th, 2006, 06:38 AM
#8
Re: Psuedocode leading to VB6 *Help needed*
you could use something like this to display the result:
VB Code:
Private Sub Command2_Click()
Dim N As Long, I As Long
For N = LBound(tombset, 1) To UBound(tombset, 1)
For I = LBound(tombset, 2) To UBound(tombset, 2)
Debug.Print tombset(I, N);
Next I
Debug.Print
Next N
End Sub
a couple of comments on your code:
since arrays are (by default) 0-based, your tombset(15, 15) is actually a 16x16 grid, and as such your random number code won't ever put a 1 in the left hand column.
the function random will return a variable, you don't need the publicly declared random in the module. At the moment your function returns a Variant, but you should strongly type all your functions:
VB Code:
Private Function Random(Lowerbound As Long, Upperbound As Long)[b] As Long[/b]
Random = Int(Rnd * Upperbound) + Lowerbound
End Function
I have also removed the Randomize, it should only be called once as multiple calls can reduce the "randomness". Place it in Form_Load.
-
Dec 15th, 2006, 06:48 AM
#9
Thread Starter
New Member
Re: Psuedocode leading to VB6 *Help needed*
okals, reason i had randomize was that when i was googling as ive been trying my very hardest, people kept saying that it comes up with the same random numbers and stuff, i didnt quite understand and i thought it would be good. but thnx for pointing me right direction.
this subprocedure
Private Sub Command2_Click()
i made a button for it, but i dont get any output from it? should i have a txtbox? listbox?
-
Dec 15th, 2006, 06:51 AM
#10
Re: Psuedocode leading to VB6 *Help needed*
it'll print out to the Immediate Window. Ctrl+G to bring it up, or View -> Immediate Window
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|