Victory Road  

Go Back   Victory Road > General > Technology
FAQ Community Today's Posts Search

Notices

 
 
Search this Thread
  #1  
Old December 28, 2009, 05:48:01 PM
GenericGirlName GenericGirlName is offline
Cyndaquil
 
Join Date: Aug 2009
Posts: 28
Smile Need some VB help (numbers, lists, random thingy, eliminating variables)

; - ; 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  
Old December 28, 2009, 05:58:13 PM
Cat333Pokémon's Avatar
Cat333Pokémon Cat333Pokémon is offline
Administrator

 
Join Date: Nov 2006
Location: Nevada
Posts: 10,303
Default

Are you using an array?
  #3  
Old January 3, 2010, 07:51:35 PM
GenericGirlName GenericGirlName is offline
Cyndaquil
 
Join Date: Aug 2009
Posts: 28
Default

((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  
Old January 4, 2010, 08:20:05 PM
Cat333Pokémon's Avatar
Cat333Pokémon Cat333Pokémon is offline
Administrator

 
Join Date: Nov 2006
Location: Nevada
Posts: 10,303
Default

Could you provide some more of the code?
  #5  
Old January 5, 2010, 06:01:54 PM
GenericGirlName GenericGirlName is offline
Cyndaquil
 
Join Date: Aug 2009
Posts: 28
Default

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  
Old January 10, 2010, 07:22:25 PM
Cat333Pokémon's Avatar
Cat333Pokémon Cat333Pokémon is offline
Administrator

 
Join Date: Nov 2006
Location: Nevada
Posts: 10,303
Default

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  
Old January 12, 2010, 03:15:15 PM
§ethi Xzon §ethi Xzon is offline
Floatzel
 
Join Date: Nov 2008
Posts: 150
Default

If you're using the .NET framework, make the array stuff in C#.
  #8  
Old January 28, 2010, 12:43:14 AM
KingOfKYA's Avatar
KingOfKYA KingOfKYA is offline
Volcarona
 
Join Date: Sep 2008
Location: On The PC
Posts: 523
Default

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

Last edited by KingOfKYA; January 28, 2010 at 12:44:13 AM.
  #9  
Old March 7, 2010, 09:40:57 PM
Cat333Pokémon's Avatar
Cat333Pokémon Cat333Pokémon is offline
Administrator

 
Join Date: Nov 2006
Location: Nevada
Posts: 10,303
Default

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

Forum Jump


All times are GMT -8.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Victory Road ©2006 - 2024, Scott Cat333Pokémon Cheney
Theme by A'bom and Cat333Pokémon