Results 1 to 10 of 10

Thread: Psuedocode leading to VB6 *Help needed*

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    5

    Question Psuedocode leading to VB6 *Help needed*

    Ok im pretty lost here about what im supposed to do. I have been given a task for school.

    I need to assign 25 locations on a 15x15 2d array randomly. For these locations i would simply use value of 1, and the other locations a value of 0.
    My first task is to write this in pseudocode, but this leads on to writing it in VB6 so i hoped this forum would be a good place to start for help. Any and all help would be appreciated. Thanks a bundle.

    heres a kindof example of what i think i should be doing (mightn be right though, and its in javascript)
    Randomise Array in Javascript

    If you need me to rephrase or nething just ask and tell me which part and ill try.

    ps. sorry if its in the wrong section, i had a look through all of em, and this looked to be the most correct one


    edit

    im slowly figuring out the fake code stuff. im kinda lost though
    wat ive figured is


    'fill with 0's
    until Y = 15 ( (until X = 15 ( array ( X ) = 0 ) X + 1 repeat )( array( Y ) = 0 ) y + 1 repeat )


    For Count 1 to 25
    'grid location
    $randomX = randomnumber() * 15
    $randomY = randomnumber() * 15

    IF array( $randomX,$randomY ) = 1
    Generate new random grid location
    Else array( $randomX,$randomY) = 1

    would that fill my 2d array with randomly placed 1's?
    Last edited by -=J_D=-; Dec 13th, 2006 at 06:26 PM. Reason: adding more info

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Psuedocode leading to VB6 *Help needed*

    You could shorten it a bit
    VB Code:
    1. For Count 1 to 25
    2. 'grid location
    3.   do
    4.      randomX = randomnumber() * 15
    5.      randomY = randomnumber() * 15
    6.   until array(randomX,randomY) = 0
    7.   array(randomX,randomY) = 1
    8. 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

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    5

    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.

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Psuedocode leading to VB6 *Help needed*

    Quote 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)

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    5

    Re: Psuedocode leading to VB6 *Help needed*

    Quote 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??

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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.

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    5

    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:
    1. Option Explicit
    2.  
    3.  
    4. Function Random(Lowerbound As Long, Upperbound As Long)
    5. Randomize
    6. Random = Int(Rnd * Upperbound) + Lowerbound
    7. End Function
    8.  
    9.  
    10. Private Sub Command1_Click()
    11. Dim randomX As Integer
    12. Dim randomY As Integer
    13. Dim count As Integer
    14.  
    15.  
    16. For count = 1 To 25
    17. 'grid location
    18.   Do
    19.     randomX = Random(1, 15)
    20.     randomY = Random(1, 15)
    21.   Loop Until tombset(randomX, randomY) = 0
    22.   tombset(randomX, randomY) = 1
    23. Next count
    24.  
    25. End Sub

    and the module

    VB Code:
    1. Public tombset(15, 15) As Integer
    2. Public Random As Integer
    Last edited by -=J_D=-; Dec 15th, 2006 at 05:29 AM. Reason: slight change/s HEAPS lol

  8. #8
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Psuedocode leading to VB6 *Help needed*

    you could use something like this to display the result:
    VB Code:
    1. Private Sub Command2_Click()
    2.     Dim N As Long, I As Long
    3.     For N = LBound(tombset, 1) To UBound(tombset, 1)
    4.         For I = LBound(tombset, 2) To UBound(tombset, 2)
    5.             Debug.Print tombset(I, N);
    6.         Next I
    7.         Debug.Print
    8.     Next N
    9. 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:
    1. Private Function Random(Lowerbound As Long, Upperbound As Long)[b] As Long[/b]
    2.     Random = Int(Rnd * Upperbound) + Lowerbound
    3. 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.

  9. #9

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    5

    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?

  10. #10
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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
  •  



Click Here to Expand Forum to Full Width