Victory Road Archive

You are viewing an archive of Victory Road.

Victory Road closed on January 8, 2018. Thank you for making us a part of your lives since 2006! Please read this thread for details if you missed it.

Technology → Need some VB help (numbers, lists, random thingy, eliminating variables)

Page 1 of 1

1. GenericGirlName said on December 28, 2009, 06:48:01 PM (-08:00)

Cyndaquil
28 posts

; - ; Visual Basic is so easy . . until I want to do things that become complicated.

So I'm probably missing some very easy method to what I want to do, but I just dont see it. I'm using VisualBasic2008, and I want to do a program w/ a memory game. So my idea is;

Buttons on the interface. Then the first button is clicked (say btn1A) the number or image below is shown (or rather the button becomes invisible). This "image" has a value. Then the user clicks another button and gets a different value. If the two match then both buttons remain invisible and then the user gets "points" added. if they are wrong then the buttons become visible again.

My problem lies in the begining step, randomizing the numbers or values under the buttons. When I start up I want to randomly assign values to each spot, making sure that there will be pairs. So I would;

1A = Random number from 1 - 10 (There are 20 tiles, 10 pairs)
1B = Random number from 1 - 10 (not including 1A.)

There is my problem! I can generate the random numbers --

Code:
                Dim RanMem As Random
                num = RanMem.Next(1, 11)
                Cards(i) = num
(This is in a loop)

-- But I have no idea how to "eliminate" a number from the set without making a loop that would check the random number after it is generated and force the program to make a new random number.

Any suggestions? D:

2. Cat333Pokémon said on December 28, 2009, 06:58:13 PM (-08:00)

Administrator
10,307 posts

Are you using an array?

3. GenericGirlName said on January 3, 2010, 08:51:35 PM (-08:00)

Cyndaquil
28 posts

((woah, I swore I replied to this when you commented o-o))

Yes I'm using an array for the values of each card, but not for the random numbers.

4. Cat333Pokémon said on January 4, 2010, 09:20:05 PM (-08:00)

Administrator
10,307 posts

Could you provide some more of the code?

5. GenericGirlName said on January 5, 2010, 07:01:54 PM (-08:00)

Cyndaquil
28 posts

Code:
Public Class frmMainGUI
    Dim Cards(19) As Integer
    Dim num As Integer
'I planned on having the GUI ask what you want to play and if you choose to play memory then the panel containing memory will be displayed.
    Private Sub PanelMemory_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PanelMemory.VisibleChanged
'Just to be sure that numbers are only generated when the user can see the panel. 
        If PanelMemory.Visible = True Then
'Loop for the 20 squares (5 x 4)
            For i As Integer = 0 To 19
                Dim RanMem As Random
                num = RanMem.Next(1, 11)
                Cards(i) = num
            Next
        End If
    End Sub
End Class
That's all I wrote so far because I got stumped. I'm also not using this as my term project anymore, but I still want to make it.

So I planned on having this code generate random number from 1 - 10 twice, but now I realize that I'd need to have it do that three times maybe? That might be excessive but I want to randomly choose the tiles to pair instead of having all the tiles on the top be one set of pairs and all the tiles on the bottom be another. I don't know if that is clear.

6. Cat333Pokémon said on January 10, 2010, 08:22:25 PM (-08:00)

Administrator
10,307 posts

I must apologize. I have been out of the progamming loop for a month now (only making tiny changes to stuff like site code). As I will be forced to resume programming (for class), I'll be able to help you in a couple days when I'm thinking along that track.

Sorry. But if you are lucky enough to remind me 5 minutes after I finish my CS homework, I'd have a much easier time.

7. §ethi Xzon said on January 12, 2010, 04:15:15 PM (-08:00)

Floatzel
150 posts

If you're using the .NET framework, make the array stuff in C#.

8. KingOfKYA said on January 28, 2010, 01:43:14 AM (-08:00)

Volcarona
523 posts

I don't know how to explain this in VB but try to translate my python to vb

Quote:
//first save possable valurs to list/array
items = [0,1,2,3,4,5,6,7,8,9]

//returns one item from list and removes it from list
val1 = items.pop(random(9))

val2 = items.pop(random(8 ))

val3 = items.pop(random(7))

//var1-3 are what you app needs

9. Cat333Pokémon said on March 7, 2010, 10:40:57 PM (-08:00)

Administrator
10,307 posts

Okay, I apologize for being quite late at this. Do you still need help?

Page 1 of 1

User List - Contact - Privacy Statement - Lycanroc.Net