In my program I have an array that contains the results of the rolls of a die. The user input how many times they wanted it rolled. I need to search through that array to find how many times a certain number shows up (also one that the user chose) to find it’s probability.
So I’d like a loop (or something else, but a loops is the only thing I can think of) to be able to loop through the array and keep track of how many times it shows up. I was going to use UBound and LBound, but because I’m finding the probability in a different procedure it won’t work.
Here’s what I have
Public Class Form1
Dim intTosses As Integer
Dim ResultTosses() As Integer
Dim intFindProb As Integer ‘This is the number that the user wants to see the probability for
Private Sub txtNumTosses_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNumTosses.TextChanged
Dim intcounter As Integer
Dim intResult As Integer
intTosses = Val(txtNumTosses.Text)
ReDim ResultTosses(intTosses)
For intcounter = 1 To intTosses
intResult = Int(6 * Rnd(1) + 1)
ResultTosses(intcounter) = intResult
Next
lblProbability.Text = ResultTosses(intTosses)
End Sub
Private Sub txtNumProbability_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNumProbability.TextChanged
Dim intpcounter As Integer
intFindProb = (Val(txtNumProbability.Text)
‘****Here is where I need to find out how many of intFindProb are in my ResultTosses Array****
If
Next
End Sub
End Class
If you could give a different example or just explain it that would be good, as it is something I need to pass in so I would like to put it together myself (we are allowed to ask for help, but the teacher is always busy), but I’m fairly lost so I’ll take what I can get.
The following code will allow the user to enter the number of rolls for one die that he wants to place in an array; and the two search numbers he desires to see howmany times they appear in the array. The number of occurrances for the two search numbers will appear in labels 1 and 2. You can use these 2 numbers for any purpose.
There is a button, 3 text boxes and 2 labels on my form.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim HowMany As Integer
Dim Array(500) As Integer
Dim MaxIndex As Integer
Dim SearchNum1 As Integer = Val(TextBox2.Text)
Dim SearchNum2 As Integer = Val(TextBox3.Text)
Dim SearchNum1Cnt, SearchNum2Cnt As Integer
If IsNumeric(TextBox1.Text) Then
HowMany = Val(TextBox1.Text)
MaxIndex = HowMany – 1
End If
Dim Rnd As New Random
For i = 0 To MaxIndex
Array(i) = Rnd.Next(1, 7)
Next
For i = 0 To MaxIndex
‘MsgBox(i & " " & Array(i) & " " & SearchNum1)
If Array(i) = SearchNum1 Then
SearchNum1Cnt += 1
End If
If Val(Array(i)) = SearchNum2 Then
SearchNum2Cnt += 1
End If
Next
Label1.Text = SearchNum1Cnt
Label2.Text = SearchNum2Cnt
End Sub
End Class
Niveau débutant: Ce tutoriel explique comment créer une macro simple. D’autres vidéos sur agi67.fr.
http://www.contextures.com/xladvfilter01.html
Curso de Excel 2003 – Aprenda nesta video aula a finalidade das macros e a como criar uma macro e a defini-la em um botão de Comando. Para Adquirir o Nosso DVD de Excel é so entrar em contato pelo e-mail: classeatreinamentos@yahoo.com.br ou pelo msn: classeatreinamento@hotmail.com . Para conhecer nosso catalogo de produtos e poder fazer compras pela internet, acesse a nossa loja virtual www.CLASSEACURSOS.com.br
Esta es una plantilla creada en Excel, para buscar y filtrar rápidamente listados creados en una hoja de Excel. Funciona ingresando las palabra o palabras de búsqueda, la macro hace dos tareas busca y filtra con un clic. Si desea hacer tu propio proyecto basado en esta plantilla usa la funcion Cells.Find y Selection.AutoFilter.
www.jeffersoncosta.com.br
How to open up a saveas dialog box
Excel If Function in VBA code. This VBA Function does exactly what the Excel If Function does.