In the player vs computer tic tac toe game I've been working on there are 2 boolean arrays (one for the computer and one for the player) that track which cells have been taken. When all other moves have been exhausted I would like the computer to play a random cell. To do this I am trying to gather the indexes of all False values from the 2 arrays and add them to another dynamic integer array. The computer will then choose randomly from the new array. The two Boolean arrays are plyrTaken and cmptrTaken. The dynamic array is occupied.
Here I declared the arrays: Public Class Form1 Private occupied() As Integer Private plyrTaken(8) As Boolean Private plyrPairs(14) As Boolean
Here I got the dynamic array ready for use: Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load ReDim occupied(0)
And here is the code I have attempted: For index As Integer = 0 To 8 If plyrTaken(index) = False And cmptrTaken(index) = False Then ReDim Preserve occupied(UBound(occupied) + 1) [Code] .....
In the last block of code I was just trying to print the contents of the array to a list box so I could see if it was working. Obviously, it's not. When one position is occupied the list box shows the occupied cell index with a Zero. This really shouldn't be there as I want only taken cell indexes to be sent to array and list box. When a second position is occupied 7 zeros are added to the list box. Kinda shows promise as 9 total cells - 2 is 7 but there should be index numbers other than zero to represent the cells that have been occupied.
Also, the indexes shouldn't keep adding on to the dynamic array I need a way to clear the array and resize it back to 0. I tried adding Redim occupied(0) to the top of the code but that didn't seem to work.
I'm working on a program that calculates 2 things. First I need to fill a 5 x 5 array with random #'s from 1 - 10 and Determine the average of each row, each column and the two diagonals, and the second calculation is Fill a 100 element array with random numbers from 1 - 100 and determine the standard deviation and mean of the random numbers in the array.
Public Sub RandomNumbers() Dim s(4) As String Dim RandomNumber As Byte
I don't know if you can tell what I am trying to do here, so I will try to explain. I what to create for random numbers and place them into for different text boxes. I also would like to do this with combo boxes and their selected indexes. So if the combo box has 10 items in it; the new selected index would be the random number generated above.
Below you will find a code sample that I have dummied up to try and demonstrate the issue I am having. However, this is just a dummied up piece of code. The actual program has noting to do with STUDENTS or TEACHERS. Basically, the problem I'm having is trying to have a CLASS within another CLASS each of which contain ARRAYS that need to be dynamic in size. The sample has a CLASS called STUDENTS that can have in theory many students, the number of which are unknown to the CLASS. I need to be able to add STUDENTS to the ARRAY programmatically.
The CLASSROOM Class should also be an Array since each TEACHER will have MANY Students. There will be only 1 Teacher for a given classroom but the SCHOOL will have MANY CLASSROOMS. Again, I need to programmatically add Teachers and Students without having predefined Array sizes. The code I have listed below will NOT work but it demonstrates what I am trying to achieve. I want to be able to reference the CLASS by using something like this ...
I feel like I should be able to use ARRAYLIST in both classes but haven't been able to get it to work. I've tried DIM'ing as ARRAY and can't get that to work either.If I can get ARRAYLIST to work then I shouldn't need to worry about expanding the array via UBOUND (if it's even possible).The REAL question is "How do I have a CLASS within a CLASS, each of which has ARRAYS that need to be dynamic in nature so they can be expanded as needed? The size of the array cannot be determined ahead of time".
REMEMBER . . . the actual program has nothing to do with Students and Teachers. This was just my way of demonstrating the issue using an analogy that I thought everyone could understand. The actual Class is much more involved.I have purposely hardcoded some values just to make the sample easier to work with. This is NOT how I normally program but is just here to hopefully make things a little more clear.
Here is the sample code . . . '*********************************************************************************** '*********************************************************************************** '***********************************************************************************
'Here is the code that is in the form - This obviously doesn't work
Private Sub TeacherTestDemo() Dim iTeacherIndex As Byte Dim iStudentIndex As Byte
The class Random is out right defective. It always produces the same random numbers in the same sequence. Things I have tried so far is every kind of seed you can think of as well as Randomize. The result is that I always get the same random numbers in exactly the same sequence.
So how would I use .next (random numbers) to randomly select something from a list of numbers but it can't repeat the number?I could do:
dim num as integer dim r as new random num = r.next(1,5) if num = 1 then elseif num = 2 then etc.
That wouldn't work because it would repeat.If I donwload someone's game can I disect it in VS? :0 I tried going to open project, then I went to the folder and clicked open. It brought me inside of the folder so I tried to open the game but there is no form1 there. It says the games name then .exe in the explorer-like thing in the top right?Also, how would I have a value or something in a label and access it from a button.
Example:This is in a label.
Dim number as Integer number = 0
Then in the button do
Label.number = 0
How would I do something like that? I want to use that a lot as I did in a different language.
The program must generate 6 unique random numbers but when I click display numbers sometimes it gives me 6 unique numbers and sometimes I get duplicate numbers. I will add the code I have so far.
Public Class frmMain
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
I don't take programming lessons at school or anything, and I'm starting to (try to) teach myself about random things.Currently I'm making an app that has 3 functions:
-Random Integer (1 to 100) -Random Answer (Yes or No, similar to a coin flip) -Random Dice Roll (1 to 6)
How would I go about doing this?At the moment all I know about random numbers etc. is that I will need to do something along the lines of Dim dice As New Random or something like that, but, like I mentioned, I have no idea.I am well aware of the DIC rules that you won't write the code for me/do my "homework(?)" for me, and that's not what I'm asking.
Basically, I want to divide two numbers together and they should be 2 random numbers from 1-12 (I have done that part) but, the answer should be a whole number (i.e. Integer, so no decimal points etc) So, I did the following:
' Initialize the random-number generator. Randomize() ' Generate random value between 1 and 12. Dim value5 As Integer = CInt(Int((12 * Rnd()) + 1))
[code]....
but the problem here is that the program crashes after only a few clicks on the button. So I guess the question is: How can I make the program generate two numbers (from 1-12) that when divided become a whole number?(Is there any code that may tell the random generator that I want the numbers to be even?-so all even numbers from 1-12?)
I'm trying to create a dynamic jagged array. That is, one that i can increase the size of at runtime. Maybe its easier if I show you. I have a folder containing a varied number of files. What I want to do is set up a jagged array, with the file contents as the second array. So kind of like this:
However, it throws a System.NullReferenceExeption when I try that. In addition, I don't understand jagged arrays all that well....Here is my code (that doesn't work). The jagged array must be accessible by other methods.
A project requires to allocate a varying number of byte arrays (buffers).
It would be ideal if the following definition would be possible:
Dim ArrayOfBuffers() as buffer(10000) as Byte
The byte arrays must be ordered sequentially because they have to be written to a file by efficient procedures destinationFile.Write(ArrayOfBuffer(3),1000,1000)
The number of buffers will change during program execution sometimes. Therefore it would be nice to be able to do a ReDim on the data structure when needed.
I have an assignment that requires me to create 5 different arrays: nouns, adjectives, verbs, prepositions, and articles. From those 5 different arrays, it has to display 10 different random sentences in the listbox named lstRandomSentences. The sentences have to be in the following order:
<article> space <adjective> space <noun> space <verb> space <preposition> space <article> space <adjective> space <noun>. Each of those arrays have to be randomly chosen in the list box and that's what I am having trouble outputting randomly.
I guess I'm the newbie. I've just started trying to learn Visual basic 2008 express edition. I'm an old cobol mainframer and I'm having a hard time understanding this language. My project is to read a log file looking for claim numbers and I need to check that each claim has a start record and an end record. I need to fill up a dynamic array because I don't know how many claims there will be. The array needs to hold a unique claim#, a start claim flag, an end claim flag.
i am in the process of learning myself VB.net (2010 dotnet 4 )And am a litte confused in whats the best way to program what can be called an array.i want to have an array that looks like this,
{{"aap", 1}, {"noot", 2}, {"mies", 3, "boom"}, {"vuur", 4, 7}} now i tried to declare
I'm trying to create a program that produces random sentences as output. With five arrays of strings, one each for nouns, adjectives, verbs, prepositions, and articles. Each array should hold several words for that part of speech. Like, the Articles array could hold the strings "the" and "a"; the Nouns array could hold "Martian", "baby", "skunk","computer" and "mosquito"; the Prepositions array could hold "around", "through", "under", "over", and "by"; and so on.
It's supposed to generate sentences by randomly choosing eight words (randomly generating eight array indices) from these arrays, always constructing sentences by using the parts of speech in the following order: article, adjective, noun, verb, preposition, article, adjective, noun. Also, the code should be properly modularized so that the code to generate each part of speech is not repeated.
I have to make a program that uses 2 arrays, one with the states name and one with the capitals names. I have to make it to where it randomly selects a state and asks you what the capital is, and gives you 4 choices in the 4 radio buttons provided. My problem is getting one of the randomly selected answer choices to be the Correct answer.
Here is my code so far: Public Class USCapitals ' Declare module level variables. [Code] .....
I have learnt how to create a basic random word generator. I now want to take this further but I would like to know if what I am thinking of is possible. I am in the process of wanting to create a random name/word generator which reads/loads an array from a text file. think this part I will be Ok with as there are some vids and tutorials about. However, I wish for the text file to have multiple arrays and then dependant on the day and time of the day, only a string from the current time array is loaded. Does that make sense and is it possible? I am happy to spend time learning how to do this but only if it is possible.
i want to know how to generate 7 "differents" random numbers.
I need to use a tab() with 7 entries and verify(with a loop?) if the generated number is or not present in the the table, if not then increment a counter by 1 and add the number in the table and increment the table position by 1 for the next randomized number.
Im not sure how to do the verification, so far all i have is a function i made for the random number between min and max:
Private Function randGen(ByVal min As Integer, ByVal max As Integer) Dim random As New Random() Dim i As Integer
I want to get random numbers between 0 to 100..But i do not want the random number to be repeated.
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim objRand As New Random objRand.Next(0, 100) End Sub
Suppose first time random numb generated is 10..Next time if same random number is generated,den i want to get the other random number..I want to get all the numbers b/w 1 to 100..but only one time
I want to get random numbers between 0 to 100..But i do not want the random number to be repeated.
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim objRand As New Random objRand.Next(0, 100) End Sub
Suppose first time random numb generated is 10..Next time if same random number is generated,den i want to get the other random number. I want to get all the numbers b/w 1 to 100..but only one time
I'm working on a program and in it I need to store all combination's of the numbers 1,2,3,4. I would like each combination to be it's own array, and instead of creating 24 different arrays (there are 24 different combinations 1,2,3 and 4 can be arranged) I was wondering if it's possible to create a nested array like so:
That way, I'd be able to reference index 2 of the above array and have the array [1,3,4,2] returned.I looked into multidimensional arrays, but this would require me calling each index of the row and column.I also looked into making a Structure in which there was an array that could hold 4 numbers, but wasn't sure if going that method would be practical or not.
i am trying to create a messagebox which brings up four random percentages which add unto 100%, i can create the messagebox with[code]messagebox.show ("") {icode]
I am writing an application that needs several random numbers. Each time I use the Rnd() function, do I need to precede it with the Randomize() initializer?Or can I just use Randomize() once at the beginning of the code?Examples: Do I need to do it this way?
'm attempting a program and need to generate 10 random numbers between 1 and 52. However all the numbers must be different. I'm trying this in a For Loop. I'm not terribly amazing at this so all I have so far is:
Dim B, I, J, max, min, card() As Interger max = 52 min = 1 Randomise()
[Code].....
What am I doing wrong and what is the ultimately simple solution I know the internet can provide for me?
This code is in VB6.0I have 28 numbers in sequence (eg 1-28), they are randomly generated and displayed in a label. I dont want a duplicate number displayed in the label. Pls how do I do this. Below is how I generate numbers at random. Now I want to make sure there is no duplicate number displayed in the label.[code]
i have a few questions about generating random numbers:1) is it possible for the programme to generate a random number that it has previously generated (i.e could it produce the same number more than once?)2) can you specify what numbers to generate? e.g only whole numbers up to 1000?
I have a problem regarding the generation of random numbers in vb.net..I have code like this!!it generates the random number but both the numbers are same for my program the should not be same!![code]