FormalAbility1
New Member
- Joined
- Nov 21, 2018
- Messages
- 2
I have written some VBA code that randomly generates a 1 or 0 depending on a probability. It then stores these into an array, which is defined by the the number of data points I have (rows) and by the number of iterations the user wants to run through (columns).I have transposed the data into excel and it looks as I'd expect, e.g.1 0 11 1 11 0 10 0 1 0 0 11 1 01 0 1Unfortunately I am not too familiar with VBA so I am struggling with the next part; I would like to now consider one column (iteration) and find if there are 3 consecutive zeros. If there are, I would like to create a new array that inputs a 1 when there are 3 consecutive zeros found, and a 0 otherwise. So the above example would look like0 1 0This would allow me to do some analysis on the number of 1's to 0's etc.My code so far is shown belowPrivate Sub CommandButton1_Click()Dim Time As DoubleDim arr As VariantDim PD As DoubleDim PD1 As DoubleDim NoOfPoints As IntegerDim y As IntegerDim i, x, k, m, f As Integer'-----------RPM = RPMInputTextboxPD = PDInputTextboxTime = TimeInputTextboxi = iterInputTextboxk = 1m = 1PD1 = PDNoOfPoints = Int(Time * (RPM / 60))ReDim arr(1 To i, 1 To NoOfPoints)For k = 1 To i 'Iteration loop For m = 1 To NoOfPoints 'Track Points Loop x = Rnd() If x > PD1 Then y = 0 Else: y = 1 End If arr(k, m) = y Next mNext kActiveSheet.Range("A1:CV8").Value = WorksheetFunction.Transpose(arr)End Sub