Count Analysis Number Step -1 to 0 (1/2, 2/3 and 3/3) - vb.net

how can I make this code work? Let's say we have in Textbox1 - the following: (2,4,6) - the textbox that will be scanned to determine the analysis.
TxtBoxIntDraws.Lines(0) = 3,6,7,9
TxtBoxIntDraws.Lines(1) = 2,6,9,10
TxtBoxIntDraws.Lines(2) = 3,5,7,10
then it will result: >
and if exists count reset to 0, if not exists count +1. the analysis will begin from the last line to the first line. TxtBoxIntDraws.Lines(2) - and finish with TxtBoxIntDraws.Lines(0)
1/3 - 0 (because one value exists 2 or 4 or 6, in TxtBoxIntDraws.Lines(0),
2/3 - 1 (because not not 2/3 - 2,6 or 4,6) and +1 add to value.
3/3 - 3 (because not 3/3 - 2,4,6) and +1 add to value.
so briefly, an analysis, 1/3, 2/3 and 3/3, if the value exists then it will be 0, if the value does not exist, it will be added + 1. It has to start from Step -1 to Line 1. I'm trying to make this code, and I'm not doing worked it.
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim lastDraw1 As Integer = 0 '1/3
Dim lastDraw2 As Integer = 0 '2/3
Dim lastDraw3 As Integer = 0 '3/3
For i As Integer = Step to -1 To TxtBoxIntDraws.Lines.Count - 0
Dim lineVals As String() = TxtBoxIntDraws.Lines(i).Split(",")
Select Case lineVals.Count()
Case 1
lastDraw1 = 0
lastDraw2 += 1
lastDraw3 += 1
TextBox1.Text = lastDraw1
TextBox2.Text = lastDraw2
TextBox3.Text = lastDraw3
Case 2
lastDraw1 = 0
lastDraw2 = 0
lastDraw3 += 1
TextBox1.Text = lastDraw1
TextBox2.Text = lastDraw2
TextBox3.Text = lastDraw3
Case 3
lastDraw1 = 0
lastDraw2 = 0
lastDraw3 = 0
TextBox1.Text = lastDraw1
TextBox2.Text = lastDraw2
TextBox3.Text = lastDraw3
Case Else
'This should probably also be handled
End Select
Next
End Sub

Not sure what you are doing but to fix the For...Next
Dim StartIndex = TxtBoxIntDraws.Lines.Length - 1
For i = StartIndex To 0 Step -1
'Your code here
Next

Related

VB.NET Count bits, 1's are counted as 1, Zero's are counted together in a sequence between 1's

Looking to count bits in a sequence.
1's are counted as 1, Zero's are counted together in a sequence between 1's
If you look at this picture
The output should be 2,1,5,1,1,3,2,1
Here is my code it works on 80% of numbers sometimes it messes up.
dim bitmask() as byte
redim bitmask(15)
bitmask(0) = 0
bitmask(1) = 0
bitmask(2) = 1
bitmask(3) = 0
bitmask(4) = 0
bitmask(5) = 0
bitmask(6) = 0
bitmask(7) = 0
bitmask(8) = 1
bitmask(9) = 1
bitmask(10) = 0
bitmask(11) = 0
bitmask(12) = 0
bitmask(13) = 1
bitmask(14) = 0
bitmask(15) = 1
Public Function GetBitCount() As Byte()
Dim count As Byte = 0
Dim bitcounts As New List(Of Byte)
Dim indexOfNext As Integer = 0
Dim totalCounted As Integer = 0
While True
indexOfNext = Array.IndexOf(bitmask, CByte(1), indexOfNext + 1)
If indexOfNext > 0 Then
If indexOfNext - totalCounted = 1 Then
bitcounts.Add(2)
bitcounts.Add(1)
ElseIf indexOfNext - totalCounted > 0 Then
bitcounts.Add(IIf(totalCounted > 0, indexOfNext - totalCounted, indexOfNext))
ElseIf indexOfNext - totalCounted > 1 Then
bitcounts.Add(2)
bitcounts.Add(1)
Else
bitcounts.Add(1)
bitcounts.Add(1)
End If
If totalCounted = 0 Then bitcounts.Add(1)
totalCounted = indexOfNext + 1
Else
Exit While
End If
End While
If totalCounted - 1 > 2 AndAlso totalCounted - 1 < bitmask.Length - 1 Then
bitcounts.Add(1)
bitcounts.Add((bitmask.Length - 1) - (totalCounted - 1))
ElseIf totalCounted - 1 <= 2 AndAlso totalCounted - 1 < bitmask.Length - 1 Then
bitcounts.Add((bitmask.Length - 1) - (totalCounted - 1))
Else
bitcounts.Add(1)
End If
If count > 0 Then bitcounts.Add(count)
Return bitcounts.ToArray()
End Function
Solution
Public Function GetBitCount() As Byte()
Dim i As Integer = 0
Dim count As Byte = 0
Dim bitcounts As New List(Of Byte)
For i = 0 To bitmask.Length - 1
If bitmask(i) = 1 Then
bitcounts.Add(count)
count = 0
End If
count += 1
Next
If count > 0 Then bitcounts.Add(count)
Return bitcounts.ToArray()
End Function

Count lines not 0 found Textboxes

I want to calculate the amount in a multiline Textbox where the value 0 is not found.
If TxtListScanValue.Text = ("2") Then
TxtDrawR2.Text &= Environment.NewLine & lastDraw2
Dim ListScan = TxtNumberListScan.Lines.ToList.Select(Function(o, i) New With {.scan = o, .Index = i})
Dim DrawR2 = TxtDrawR2.Lines.ToList.Select(Function(o, i) New With {.draw = o, .Index = i})
Dim list2 = From a In ListScan From b In DrawR2 Where a.Index = b.Index Select LstScan = a.scan, DrwR2 = ("00" & b.draw).Substring(("00" & b.draw).Length - 2) Order By DrwR2 Descending
TxtListScanTxt.Text = String.Join(vbCrLf, list2)
End If
If TxtdrawR5 =
2
4
0
0
1
3
5
In output I want to display: 5 because:
I want to calculate the count lines where the value 0 is not found. Count lines no have 0 value :D (2+4+1+3+5 = 5) (5 lines no have 0 value).
You create function like this:
'For Counting
Private Function CountNonZero(ByVal TheCtrl As TextBox) As Integer
Dim myCnt As Integer = 0
For Each Content In TheCtrl.Lines
Dim ContentVal As Integer = 0
Integer.TryParse(Content, ContentVal)
If ContentVal <> 0 Then myCnt += 1
Next
Return myCnt
End Function
'For Counting
Private Function SummingNonZero(ByVal TheCtrl As TextBox) As Integer
Dim mySum As Integer = 0
For Each Content In TheCtrl.Lines
Dim ContentVal As Integer = 0
Integer.TryParse(Content, ContentVal)
If ContentVal <> 0 Then mySum += ContentVal
Next
Return mySum
End Function
And you can count or sum now:
dim TxtdrawR5Count as integer = CountNonZero(TxtdrawR5)
dim TxtdrawR5Sum as integer = SummingNonZero(TxtdrawR5)

Case Count 0 Digit in VB.Net

Why Don't work Case 0 in my code? In this example, if there is nothing in that line (nothing), it should be +1, but it shows me the result 0.
Dim StartIndex = TextBoz1.Lines.Length - 1
For i = StartIndex To 0 Step -1
Dim lineVals As String() = TextBoz1.Lines(i).Split(",")
Select Case lineVals.Count()
Case 0
lastDraw1 += 1
lastDraw2 += 1
lastDraw3 += 1
Case 1
lastDraw1 = 0
lastDraw2 += 1
lastDraw3 += 1
Case 2
lastDraw1 = 0
lastDraw2 = 0
lastDraw3 += 1
Case 3
lastDraw1 = 0
lastDraw2 = 0
lastDraw3 = 0
End Select
Next
TextBox8.Text = lastDraw1
TextBox9.Text = lastDraw2
TextBox10.Text = lastDraw3
End Sub
It does not equal to zero. Try a small sample.
Dim s As String = ""
Dim v As String() = s.Split(","c)
Console.WriteLine(v.Count) ' Display 1
In your case, you would need to check if the string is empty first.
If String.IsNullOrEmpty(TextBoz1.Lines(i)) Then
lastDraw1 += 1
lastDraw2 += 1
lastDraw3 += 1
Else
Dim lineVals As String() = TextBoz1.Lines(i).Split(",")
Select Case lineVals.Count()
Case 1
lastDraw1 = 0
lastDraw2 += 1
lastDraw3 += 1
Case 2
lastDraw1 = 0
lastDraw2 = 0
lastDraw3 += 1
Case 3
lastDraw1 = 0
lastDraw2 = 0
lastDraw3 = 0
End Select
End If

How to make a "key generator" knowing the formula

I have the formula to check 9 integers,
First digit(d1) must be: 1, 2, 5, 6, 8 or 9
Last digit(d9) must be: 0 or 9
9xd1+8xd2+7xd3+6xd4+5xd5+4xd6+3xd7+2xd8+d9 mod 11 = 0
I can "validate" the key, but how can I generate more of this, knowing the conditions for it to be right?
How can I generate 9 different integers from 0 to 9 and check them under this formula?
Thanks for helping!
Generate the first 7 digits randomly, calculating the formula for those digits.
Set the 9th digit's value to 9, and add it to the formula.
Calculate a value for the 8th digit based on the mod of the result of the formula that causes the result of the formula to be mod 11 = 0.
For the exception case where attempting to do this causes mod 11 = 9, set the 9th digit to 0.
Implementation:
Private randGen As New Random()
Function GenNum() As Integer
Dim digits(0 To 8) As Integer
GenNum = 0
Dim checkSum As Integer
digits(0) = randGen.Next(6) + 1
If digits(0) >= 3 Then digits(0) += 2
If digits(0) >= 7 Then digits(0) += 1
checkSum += digits(0) * 9
For d As Integer = 1 To 6
digits(d) = randGen.Next(10)
checkSum += digits(d) * (9 - d)
Next
digits(8) = 9
checkSum += digits(8)
If (checkSum Mod 11) Mod 2 = 1 Then
digits(7) = (11 - (checkSum Mod 11)) \ 2
Else
digits(7) = ((12 - (checkSum Mod 11)) \ 2 + 4) Mod 10
End If
checkSum += digits(7) * 2
If checkSum Mod 11 = 9 Then digits(8) = 0
Dim pow10 As Integer = 1
For d As Integer = 8 To 0 Step -1
GenNum += pow10 * digits(d)
pow10 *= 10
Next
End Function
I can help you to generate integers from 0 to 9.
here is how your form should look like:
and here is the code:
Public Class Form1
Dim NumRandom As Random = New Random
Dim X, Y, Z As Integer
Private Sub GenerateBUT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GenerateBUT.Click
Dim a(9), i, j, RN As Integer
Dim flag As Boolean
flag = False
i = 1
a(j) = 1
Do While i <= 9
Randomize()
RN = CInt(Int(9 * Rnd()) + 1)
For j = 1 To i
If (a(j)) = RN Then
flag = True
Exit For
End If
Next
If flag = True Then
flag = False
Else
a(i) = RN
i = i + 1S
End If
Loop
Label1.Text = a(1)
Label2.Text = a(2)
Label3.Text = a(3)
Label4.Text = a(4)
Label5.Text = a(5)
Label6.Text = a(6)
Label7.Text = a(7)
Label8.Text = a(8)
Label9.Text = a(9)
Z = Label4.Text
Y = Label5.Text
X = Z + Y
X = X - Label3.Text
If X > 1 And X < 10 Then
X = NumRandom.Next(1, 7)
If X = 1 Then
Label1.Text = "0"
ElseIf X = 2 Then
Label2.Text = "0"
ElseIf X = 3 Then
Label3.Text = "0"
ElseIf X = 4 Then
Label4.Text = "0"
ElseIf X = 5 Then
Label5.Text = "0"
ElseIf X = 6 Then
Label6.Text = "0"
ElseIf X = 7 Then
Label7.Text = "0"
End If
End If
End Sub
End Class

InvalidArgument=Value of '2' is not valid for 'index'

Dim group11_0_count = 0
Dim group11_1_count = 0
Dim group11_2_count = 0
Dim m As Integer = 0
Dim n As Integer = 0
Dim increment2 As Integer
For m = 0 To machings2.Items.Count - 1
For n = 0 To 3
If machings2.Items(m).ToString.Chars(n) = "1" Then
increment2 = increment2 + 1
End If
Next
If (increment2 = 0) Then
group11_0_count = group11_0_count + 1
group11_1_0.Items.Add(machings2.Items(m))
End If
If (increment2 = 1) Then
group11_1_count = group1_1_count + 1
group11_1_1.Items.Add(machings2.Items(m))
End If
If (increment2 = 2) Then
group11_2_count = group1_2_count + 1
group11_1_2.Items.Add(machings2.Items(m))
End If
increment2 = 0
Next
If (group11_0_count > 0 AndAlso group11_1_count > 0) Then
Dim result = ""
Dim index As Integer = 0
Dim gg As Integer = 0
Dim hh As Integer = 0
Dim i As Integer = 0
For hh = 0 To group11_1_count - 1
For gg = 0 To group11_0_count - 1
result = ""
index = 0
For i = 0 To 3
If group11_1_0.Items(gg).ToString.Chars(i) <> group11_1_1.Items(hh).ToString.Chars(i) Then
result &= "-"
index = index + 1
Else
result &= group11_1_0.Items(gg).ToString.Chars(i)
End If
Next
If (index = 1) Then
machings3.Items.Add(result)
End If
Next
Next
End If
I am comparing the items of two combobox items like that
combobox1 items
0000
combobox items
0001
0010
the result will be like that in machings3 combobox
000-
00-0
Here the differnce between two items indicated by - sign
But i am getting InvalidArgument=Value of '2' is not valid for 'index'.
I Can't make sense out of your source and where the IndexOutOfRangeException occurs. But you know that you need 3 Items in a Combobox to access Item with Index 2?! Every collection starts with 0.