How to make a "key generator" knowing the formula - vb.net

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

Related

bounding data to mschart so i can return non-data point-values

I'm trying to build a chart composed of up-to-100% stacked columns, each with 4 series and, once built, upon hovering upon the series, return all bound data (in this case, user names)
I'm very close to what i want, but the tooltip is showing only the sums, which is expected, but i dont know how to proceed. If there's another way that passes over the hover, like clicking and, in the click, I recognize the series and all those that are there, that would help immensely too
What I Have right now
What I Want
After looking it up, i built the chart this way:
(right now its a code nightmare, but i will methodify everything properly later)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim sql As New SqlCommand(my query, my connector)
connect()
Dim rs = sql.ExecuteReader
Dim dtTest1 As DataTable = New DataTable
If rs.Read Then
dtTest1.Load(rs)
End If
disconnect()
Dim arrayTempoCallback(dtTest1.Rows.Count) As Double
Dim arrayTempoInaptidao(dtTest1.Rows.Count) As Double
Dim arrayTempoParabens(dtTest1.Rows.Count) As Double
Dim arrayTempoRecusa(dtTest1.Rows.Count) As Double
Dim arrayTempoSemDados(dtTest1.Rows.Count) As Double
For Each item In dtTest1.Rows
arrayTempoCallback(dtTest1.Rows.IndexOf(item)) = item("TEMPO_CALLBACK")
arrayTempoInaptidao(dtTest1.Rows.IndexOf(item)) = item("TEMPO_INAPTIDAO")
arrayTempoParabens(dtTest1.Rows.IndexOf(item)) = item("TEMPO_PARABENS")
arrayTempoRecusa(dtTest1.Rows.IndexOf(item)) = item("TEMPO_RECUSA")
arrayTempoSemDados(dtTest1.Rows.IndexOf(item)) = item("TEMPO_SEMDADOS")
Next
Dim QuartisCallBack = Quartiles(arrayTempoCallback)
Dim QuartisTempoInaptidao = Quartiles(arrayTempoInaptidao)
Dim QuartisTempoParabens = Quartiles(arrayTempoParabens)
Dim QuartisTempoRecusa = Quartiles(arrayTempoRecusa)
Dim QuartisTempoSemDados = Quartiles(arrayTempoSemDados)
Dim tabelafinal As New DataTable
tabelafinal.Columns.Add("VALORES", GetType(String))
tabelafinal.Columns.Add("COLUNA", GetType(String))
tabelafinal.Columns.Add("COR", GetType(String))
Dim somaS As Integer = 0
Dim somaH As Integer = 0
Dim somaC As Integer = 0
Dim somaD As Integer = 0
For Each linha In dtTest1.Rows
If linha("TEMPO_INAPTIDAO") < QuartisTempoInaptidao.Item1 Then
somaS += 1
ElseIf linha("TEMPO_INAPTIDAO") >= QuartisTempoInaptidao.Item1 AndAlso linha("TEMPO_INAPTIDAO") < QuartisTempoInaptidao.Item2 Then
somaH += 1
ElseIf linha("TEMPO_INAPTIDAO") >= QuartisTempoInaptidao.Item2 AndAlso linha("TEMPO_INAPTIDAO") < QuartisTempoInaptidao.Item3 Then
somaC += 1
ElseIf linha("TEMPO_INAPTIDAO") >= QuartisTempoInaptidao.Item3 Then
somaD += 1
End If
Next
tabelafinal.Rows.Add(somaS, "TM_INAP", "D")
tabelafinal.Rows.Add(somaH, "TM_INAP", "C")
tabelafinal.Rows.Add(somaC, "TM_INAP", "H")
tabelafinal.Rows.Add(somaD, "TM_INAP", "S")
somaC = somaD = somaH = somaS = 0
For Each linha In dtTest1.Rows
If linha("TEMPO_PARABENS") < QuartisTempoParabens.Item1 Then
somaS += 1
ElseIf linha("TEMPO_PARABENS") >= QuartisTempoParabens.Item1 AndAlso linha("TEMPO_PARABENS") < QuartisTempoParabens.Item2 Then
somaH += 1
ElseIf linha("TEMPO_PARABENS") >= QuartisTempoParabens.Item2 AndAlso linha("TEMPO_PARABENS") < QuartisTempoParabens.Item3 Then
somaC += 1
ElseIf linha("TEMPO_PARABENS") >= QuartisTempoParabens.Item3 Then
somaD += 1
End If
Next
tabelafinal.Rows.Add(somaS, "TM_PARABENS", "S")
tabelafinal.Rows.Add(somaH, "TM_PARABENS", "H")
tabelafinal.Rows.Add(somaC, "TM_PARABENS", "C")
tabelafinal.Rows.Add(somaD, "TM_PARABENS", "D")
somaC = somaD = somaH = somaS = 0
For Each linha In dtTest1.Rows
If linha("TEMPO_RECUSA") < QuartisTempoRecusa.Item1 Then
somaS += 1
ElseIf linha("TEMPO_RECUSA") >= QuartisTempoRecusa.Item1 AndAlso linha("TEMPO_PARABENS") < QuartisTempoRecusa.Item2 Then
somaH += 1
ElseIf linha("TEMPO_RECUSA") >= QuartisTempoRecusa.Item2 AndAlso linha("TEMPO_PARABENS") < QuartisTempoRecusa.Item3 Then
somaC += 1
ElseIf linha("TEMPO_RECUSA") >= QuartisTempoRecusa.Item3 Then
somaD += 1
End If
Next
tabelafinal.Rows.Add(somaS, "TM_RECUSA", "S")
tabelafinal.Rows.Add(somaH, "TM_RECUSA", "H")
tabelafinal.Rows.Add(somaC, "TM_RECUSA", "C")
tabelafinal.Rows.Add(somaD, "TM_RECUSA", "D")
somaC = somaD = somaH = somaS = 0
For Each linha In dtTest1.Rows
If linha("TEMPO_SEMDADOS") < QuartisTempoSemDados.Item1 Then
somaS += 1
ElseIf linha("TEMPO_SEMDADOS") >= QuartisTempoSemDados.Item1 AndAlso linha("TEMPO_PARABENS") < QuartisTempoSemDados.Item2 Then
somaH += 1
ElseIf linha("TEMPO_SEMDADOS") >= QuartisTempoSemDados.Item2 AndAlso linha("TEMPO_PARABENS") < QuartisTempoSemDados.Item3 Then
somaC += 1
ElseIf linha("TEMPO_SEMDADOS") >= QuartisTempoSemDados.Item3 Then
somaD += 1
End If
Next
Dim somaFinalSemDadosS As Integer = If(somaS < 0, 0, somaS)
Dim somaFinalSemDadosH As Integer = If(somaH < 0, 0, somaH)
Dim somaFinalSemDadosC As Integer = If(somaC < 0, 0, somaC)
Dim somaFinalSemDadosD As Integer = If(somaD < 0, 0, somaD)
tabelafinal.Rows.Add(somaFinalSemDadosS, "TM_SEMDADOS", "S")
tabelafinal.Rows.Add(somaFinalSemDadosH, "TM_SEMDADOS", "H")
tabelafinal.Rows.Add(somaFinalSemDadosC, "TM_SEMDADOS", "C")
tabelafinal.Rows.Add(somaFinalSemDadosD, "TM_SEMDADOS", "D")
somaC = somaD = somaH = somaS = 0
For Each linha In dtTest1.Rows
If linha("TEMPO_CALLBACK") < QuartisCallBack.Item1 Then
somaS += 1
ElseIf linha("TEMPO_CALLBACK") >= QuartisCallBack.Item1 AndAlso linha("TEMPO_PARABENS") < QuartisCallBack.Item2 Then
somaH += 1
ElseIf linha("TEMPO_CALLBACK") >= QuartisCallBack.Item2 AndAlso linha("TEMPO_PARABENS") < QuartisCallBack.Item3 Then
somaC += 1
ElseIf linha("TEMPO_CALLBACK") >= QuartisCallBack.Item3 Then
somaD += 1
End If
Next
Dim somaFinalCallBackS As Integer = If(somaS < 0, 0, somaS)
Dim somaFinalCallBackH As Integer = If(somaH < 0, 0, somaH)
Dim somaFinalCallBackC As Integer = If(somaC < 0, 0, somaC)
Dim somaFinalCallBackD As Integer = If(somaD < 0, 0, somaD)
tabelafinal.Rows.Add(somaFinalCallBackS, "TEMPO_CALLBACK", "S")
tabelafinal.Rows.Add(somaFinalCallBackH, "TEMPO_CALLBACK", "H")
tabelafinal.Rows.Add(somaFinalCallBackC, "TEMPO_CALLBACK", "C")
tabelafinal.Rows.Add(somaFinalCallBackD, "TEMPO_CALLBACK", "D")
Dim dv As DataView = New DataView(tabelafinal)
Chart1.AlignDataPointsByAxisLabel()
Chart1.DataBindCrossTable(dv, "COR", "COLUNA", "VALORES", "")
For Each cs As Series In Chart1.Series
cs.ChartType = SeriesChartType.StackedColumn100
cs.ToolTip = "Pessoas = #VALY"
Next
End Sub
Friend Function Quartiles(ByVal afVal As Double()) As Tuple(Of Double, Double, Double)
Dim iSize As Integer = afVal.Length
System.Array.Sort(afVal)
Dim iMid As Integer = iSize / 2
Dim fQ1 As Double = 0
Dim fQ2 As Double = 0
Dim fQ3 As Double = 0
If iSize Mod 2 = 0 Then
fQ2 = (afVal(iMid - 1) + afVal(iMid)) / 2
Dim iMidMid As Integer = iMid / 2
If iMid Mod 2 = 0 Then
fQ1 = (afVal(iMidMid - 1) + afVal(iMidMid)) / 2
fQ3 = (afVal(iMid + iMidMid - 1) + afVal(iMid + iMidMid)) / 2
Else
fQ1 = afVal(iMidMid)
fQ3 = afVal(iMidMid + iMid)
End If
ElseIf iSize = 1 Then
fQ1 = afVal(0)
fQ2 = afVal(0)
fQ3 = afVal(0)
Else
fQ2 = afVal(iMid)
If (iSize - 1) Mod 4 = 0 Then
Dim n As Integer = (iSize - 1) / 4
fQ1 = (afVal(n - 1) * 0.25) + (afVal(n) * 0.75)
fQ3 = (afVal(3 * n) * 0.75) + (afVal(3 * n + 1) * 0.25)
ElseIf (iSize - 3) Mod 4 = 0 Then
Dim n As Integer = (iSize - 3) / 4
fQ1 = (afVal(n) * 0.75) + (afVal(n + 1) * 0.25)
fQ3 = (afVal(3 * n + 1) * 0.25) + (afVal(3 * n + 2) * 0.75)
End If
End If
Return New Tuple(Of Double, Double, Double)(fQ1, fQ2, fQ3)
End Function
End Class
If I understand correctly, you are trying to show a tooltip (when hovering the cursor over one colored 'block' in the chart) that shows information about the data that makes up the point.
The problem is that each 'block' is only a single X and Y value. For example: The DataPoint behind the tooltip that shows 'Pessoas = 392' is actually just a simple DataPoint (Series-S X=5 Y=392) with no additional information.
To show a tooltip the way you want each one will have to be pre-set, like this:
point.ToolTip = "User1 in the series\nUser2 in the series\n..."

VB.net Problem with If-statement not being run when the statement is true

With the following global variables:
Dim SpilleBræt(8, 8) As PictureBox
Dim Position(8, 8) As String
Dim MarkeretFelt(8, 8) As String
Dim FeltFarve As String
Dim x As Integer
Dim y As Integer
Dim AktivMarkering As Boolean = 0
Dim SpilleBrik As String
And this code:
Private Sub PictureBox_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim FeltValg As PictureBox = CType(sender, PictureBox)
If AktivMarkering = 1 Then
x = Mid(sender.name, sender.name.Length - 1, 1)
y = Mid(sender.name, sender.name.Length, 1)
Select Case Position(y, x)
Case "LightTileMarked"
Me.SpilleBræt(y, x).BackgroundImage = My.Resources.ResourceManager.GetObject(SpilleBrik & "LightTile")
Case "DarkTileMarked"
Me.SpilleBræt(y, x).BackgroundImage = My.Resources.ResourceManager.GetObject(SpilleBrik & "DarkTile")
Case Else
'fjerner markerede
Select Case Position(y, x)
Case "BlackTower", "WhiteTower"
MsgBox("Tårn")
Case "BlackHorse", "WhiteHorse"
MsgBox("Hest")
Case "BlackBishop", "WhiteBishop"
MsgBox("Løber")
Case "WhiteKing", "BlackKing"
MsgBox("Konge")
Case "WhiteQueen", "BlackQueen"
MsgBox("Dronning")
Case "WhitePawn", "BlackPawn"
For k As Integer = y To 1 Step -1
If Position(k, x) = "" Then
If (k + x) Mod 2 = 1 Then
FeltFarve = "DarkTile"
Else
FeltFarve = "LightTile"
End If
Me.SpilleBræt(x, k).BackgroundImage = My.Resources.ResourceManager.GetObject(FeltFarve)
ElseIf Position(k, x) = "WhitePawn" Or Position(k, x) = "BlackPawn" Then
'background død brik
Else
k = 1
End If
Next
End Select
End Select
Else
'indsætter markering
'x,y i picturebox'ens navn fx ->(SpilBrik44) hvor x=4 og y=4
x = Mid(sender.name, sender.name.Length - 1, 1)
y = Mid(sender.name, sender.name.Length, 1)
Select Case Position(y, x)
Case "BlackTower", "WhiteTower"
MsgBox("Tårn")
Case "BlackHorse", "WhiteHorse"
MsgBox("Hest")
Case "BlackBishop", "WhiteBishop"
MsgBox("Løber")
Case "WhiteKing", "BlackKing"
MsgBox("Konge")
Case "WhiteQueen", "BlackQueen"
MsgBox("Dronning")
Case "WhitePawn", "BlackPawn"
For k As Integer = y To 1 Step -1
If Position(k, x) = "" Then
If (k + x) Mod 2 = 1 Then
FeltFarve = "DarkTileMarked"
Else
FeltFarve = "LightTileMarked"
End If
Me.SpilleBræt(x, k).BackgroundImage = My.Resources.ResourceManager.GetObject(FeltFarve)
MarkeretFelt(x, k) = FeltFarve
AktivMarkering = 1
ElseIf Position(k, x) = "WhitePawn" Or Position(k, x) = "BlackPawn" Then
'background død brik
Else
k = 1
End If
Next
End Select
End If
End Sub
I have a problem with the first If statement aktivmarkering=1, goes directly to the 'Else' even though if statements is true.
First time code is run, aktivmarkering is = 0, and therefore it obviously goes to 'Else', but after that one has ben run AktivMarkering is = 1, and first if should be executed. I don't see why not - anyone whos able to help?
Thanks.

Snakes and ladders Vb.net [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Form 2 is to enter ladder base and its off set value and for snakes where the snake head is and skakes off set value.
Not able to figure out why its not working . When the values are entered to show simulation it show's up error sandl is private and the other one is the validation one .
Public Class Form2
Dim sandl(99) As Integer
Dim snakeshead As TextBox()
Dim snakesoffset As TextBox()
Dim ladderfoot As TextBox()
Dim ladderoffset As TextBox()
Dim rnd As Random = New Random
Sub initialise()
For i = 0 To 99
sandl(i) = 0 ' reset data
Next
End Sub
Sub snake()
snakeshead = {txthead1, txthead2, txthead3, txthead4, txthead5, txthead6, txthead7, txthead8, txthead9, txthead10}
snakesoffset = {txtoffset1, txtoffset2, txtoffset3, txtoffset4, txtoffset5, txtoffset6, txtoffset7, txtoffset8, txtoffset9, txtoffset10}
' SnakeHead(i).Text = (i + 81).ToString
' SnakeOffset(i).Text = "10" '(i + 10).ToString
For i As Integer = 0 To 9
While True
Dim base = rnd.Next(90) + 11
If sandl(base - 1) <> 0 Then
Continue While
End If
Dim offset = rnd.Next(20) + 10
If base - offset < 1 Then
Continue While
End If
snakeshead(i).Text = base.ToString
snakesoffset(i).Text = offset.ToString
sandl(base - 1) = -offset
Exit While
End While
Next
End Sub
Sub ladders()
ladderfoot = {txtladder1, txtladder2, txtladder3, txtladder4, txtladder5, txtladder6, txtladder7, txtladder8, txtladder9, txtladder10}
ladderoffset = {txtladderoffset1, txtladderoffset2, txtladderoffset3, txtladderoffset4, txtladderoffset5, txtladderoffset6, txtladderoffset7, txtladderoffset8, txtladderoffset9, txtladderoffset10}
'For i As Integer = 0 To 9
' LadderFoot(i).Text = (i + 11).ToString
' LadderOffset(i).Text = "10"
For i As Integer = 0 To 99
sandl(i) = 0 'reset data
Next
For i As Integer = 0 To 9
While True
Dim base = rnd.Next(90) + 1
If sandl(base - 1) <> 0 Then
Continue While
End If
Dim offset = rnd.Next(20) + 10
If base + offset > 100 Then
Continue While
End If
ladderfoot(i).Text = base.ToString
ladderoffset(i).Text = offset.ToString
sandl(base - 1) = offset
Exit While
End While
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For i As Integer = 0 To 99
sandl(i) = 0 'reset data
Next
Dim valid = Validate(ladderfoot, ladderoffset, +1, "Ladder")
If (valid) Then
valid = Validate(snakeshead, snakesoffset, -1, "Snake")
End If
If (valid) Then
'Form3 = New Form3
Form3.ShowDialog()
End If
End Sub
Private Function Validate(tbBase() As TextBox, tbOffset() As TextBox, delta As Integer, s As String) As Boolean
For i As Integer = 0 To 9
Dim base As Integer
If ((Not Integer.TryParse(tbBase(i).Text.Trim(), base)) OrElse (base < 1) OrElse (base > 100) OrElse (sandl(base - 1) <> 0)) Then
MessageBox.Show(s & (i + 1).ToString() & " base is invalid.")
tbBase(i).Select()
tbBase(i).SelectAll()
Return False
End If
base -= 1 'zero based
Dim offset As Integer
If ((Not Integer.TryParse(tbOffset(i).Text.Trim(), offset)) OrElse (offset < 10) OrElse (offset > 30) OrElse (base + offset * delta < 0) OrElse (base + offset * delta >= 100)) Then
MessageBox.Show(s & (i + 1).ToString() & " offset is invalid.")
tbOffset(i).Select()
tbOffset(i).SelectAll()
Return False
End If
sandl(base) = offset * delta 'write offset
Next
Return True
End Function
End Class
Public Class Form3
Enum EState
Dice
Move
Slide
Wait
Win
End Enum
Dim Fnt = New Font("Arial", 16)
Dim FntBig = New Font("Arial", 256)
Dim Frame As Integer = -1 'counter
Dim State = EState.Dice
Dim Rnd As Random = New Random
Dim Dice As Integer
Dim Pos As Point = New Point(32, 640 + 32)
Dim CurrentIndex As Integer = -1
Dim NextIndex As Integer
Dim TargetIndex As Integer
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dice = 0
Frame = -1
State = EState.Dice
Pos = New Point(32, 640 + 32)
CurrentIndex = -1
End Sub
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
DrawBackground(e.Graphics)
Frame += 1
Dim oldState = State
Select Case State
Case EState.Dice
If Frame = 0 Then
Dice = Rnd.Next(6) + 1 'roll dice
TargetIndex = CurrentIndex + Dice
NextIndex = CurrentIndex
ElseIf Frame >= 63 Then
If CurrentIndex + Dice < 100 Then
State = EState.Move 'valid dice
Else
State = EState.Wait 'invalid dice
End If
Dice = 0
End If
Case EState.Move
If Frame Mod 64 = 0 Then
CurrentIndex = NextIndex
If CurrentIndex = TargetIndex Then
If CurrentIndex < 99 Then 'not win
If Form2.sandl(CurrentIndex) <> 0 Then
State = EState.Slide 'snake or ladder
Else
State = EState.Dice 'empty tile
End If
TargetIndex = CurrentIndex + Form2.sandl(CurrentIndex)
Else
State = EState.Win 'win
End If
Else
NextIndex = CurrentIndex + 1 'move
End If
Else
Dim c = GetCoordinate(CurrentIndex)
Dim n = GetCoordinate(NextIndex)
Dim dx = (n.X - c.X)
Dim dy = (n.Y - c.Y)
Pos.X = c.X * 64 + (dx * (Frame Mod 64)) + 32
Pos.Y = c.Y * 64 + (dy * (Frame Mod 64)) + 32
End If
Case EState.Slide
If Frame >= 63 Then
CurrentIndex = TargetIndex
If CurrentIndex < 99 Then
State = EState.Dice 'not win
Else
State = EState.Win 'win
End If
Else
Dim c = GetCoordinate(CurrentIndex)
Dim n = GetCoordinate(TargetIndex)
Dim dx = (n.X - c.X)
Dim dy = (n.Y - c.Y)
Pos.X = c.X * 64 + (dx * (Frame Mod 64)) + 32
Pos.Y = c.Y * 64 + (dy * (Frame Mod 64)) + 32
End If
Case EState.Wait
If Frame >= 63 Then
State = EState.Dice
End If
End Select
e.Graphics.FillEllipse(Brushes.Blue, Pos.X - 16, Pos.Y - 16, 32, 32) 'draw player
If Dice > 0 Then
Dim size = e.Graphics.MeasureString(Dice.ToString, FntBig)
e.Graphics.DrawString(Dice.ToString, FntBig, Brushes.Black, 320 - size.Width / 2, 320 - size.Height / 2) 'print dice
End If
If State <> oldState Then
Frame = -1 'reset counter
End If
If State <> EState.Win Then
PictureBox1.Invalidate() 'schedule next paint
End If
End Sub
Private Sub DrawBackground(g As Graphics)
For y As Integer = 0 To 9
For x As Integer = 0 To 9
If (((x + y) Mod 2) = 0) Then
g.FillRectangle(Brushes.LightGray, x * 64, y * 64, 64, 64) 'dark rectangle
End If
Dim z = (9 - y) * 10 + x + 1
If y Mod 2 = 0 Then
z = (9 - y) * 10 + (9 - x) + 1
End If
g.DrawString(z.ToString, Fnt, Brushes.Black, x * 64, y * 64) 'number
Next
Next
For i As Integer = 0 To 99
If Form2.sandl(i) <> 0 Then
Dim base = GetCoordinate(i)
Dim offset = GetCoordinate(i + Form2.sandl(i))
If Form2.sandl(i) > 0 Then 'ladder
Dim delta = Math.Abs(base.X - offset.X) + 4
g.DrawLine(Pens.Green, base.X * 64 + 32 - delta, base.Y * 64 + 32, offset.X * 64 + 32 - delta, offset.Y * 64 + 32) 'left part
g.DrawLine(Pens.Green, base.X * 64 + 32 + delta, base.Y * 64 + 32, offset.X * 64 + 32 + delta, offset.Y * 64 + 32) 'right part
Else 'snake
g.DrawLine(Pens.Red, base.X * 64 + 32, base.Y * 64 + 32, offset.X * 64 + 32, offset.Y * 64 + 32) 'red line
End If
End If
Next
End Sub
Private Function GetCoordinate(i As Integer) As Point
Dim result As Point
result.Y = 9 - (i \ 10)
result.X = i Mod 10
If result.Y Mod 2 = 0 Then
result.X = 9 - result.X
End If
Return result
End Function
End Class
In Form2, change your declaration from
Dim sandl(99) As Integer
to
Public sandl(99) As Integer
This would allow Form3 to access your integer array
Rename your Validate method to something else, like ValidateTextBoxes, or if you intend to overload the base.Validate, then declare as
Private Overloads Function Validate

project euler problem17 vb code bug

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.
my answer is coming 21148. i cant find the mistake here is my code in vb
the answer should be 21124
Dim length As UInt32 = 11
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For i = 1 To 999
If i / 10 < 1 Then
single_digit(i)
ElseIf i / 10 = 1 Then
ten()
ElseIf i / 10 > 1 And i / 10 < 2 Then
ele_twe_thi(i)
ElseIf i / 10 >= 2 And i / 10 < 10 Then
multiple_10(Math.Floor(i / 10) * 10)
single_digit(i Mod 10)
ElseIf i = 100 Then
single_digit(i / 100)
length += 7
ElseIf i Mod 100 >= 11 And i Mod 100 <= 19 Then
length += 10
single_digit(Math.Floor(i / 100))
ele_twe_thi(i Mod 100)
ElseIf i Mod 100 = 10 Then
length += 3
single_digit(Math.Floor(i / 100))
length += 10
Else
length += 10
single_digit(Math.Floor(i / 100))
multiple_10(Math.Floor((i Mod 100) / 10) * 10)
single_digit(i Mod 10)
End If
Next
MsgBox(length)
End Sub
Private Sub single_digit(num)
If num = 1 Then
length = length + 3
ElseIf num = 2 Then
length = length + 3
ElseIf num = 3 Then
length = length + 5
ElseIf num = 4 Then
length = length + 4
ElseIf num = 5 Then
length = length + 4
ElseIf num = 6 Then
length = length + 3
ElseIf num = 7 Then
length = length + 5
ElseIf num = 8 Then
length = length + 5
ElseIf num = 9 Then
length = length + 4
End If
End Sub
Private Sub ele_twe_thi(num)
If num = 11 Or num = 12 Then
length = length + 6
ElseIf num = 13 Or num = 14 Or num = 18 Or num = 19 Then
length = length + 8
ElseIf num = 17 Then
length = length + 9
ElseIf num = 15 Or num = 16 Then
length = length + 7
End If
End Sub
Private Sub multiple_10(num)
If num = 20 Then
length = length + 6
ElseIf num = 30 Then
length = length + 6
ElseIf num = 40 Then
length = length + 5
ElseIf num = 50 Then
length = length + 5
ElseIf num = 60 Then
length = length + 5
ElseIf num = 70 Then
length = length + 7
ElseIf num = 80 Then
length = length + 6
ElseIf num = 90 Then
length = length + 6
End If
End Sub
Private Sub ten()
length = length + 3
End Sub
every time the program reaches 100, 200, 300 etc. is it adding an "and" unnecessarily?

Pascal's Triangle - VB.NET

I've already created a program that will display x number of rows and repeat that :
i.e.
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
Now I want to make Pascal's Triangle
Maybe something like this:
Dim arr As Integer(,) = New Integer(7, 7) {}
For i As Integer = 0 To 7
For k As Integer = 7 To i + 1 Step -1
'print spaces
Console.Write(" ")
Next
For j As Integer = 0 To i - 1
If j = 0 OrElse i = j Then
arr(i, j) = 1
Else
arr(i, j) = arr(i - 1, j) + arr(i - 1, j - 1)
End If
Console.Write(arr(i, j) & " ")
Next
Console.WriteLine()
Next
Console-output:
Another approach, only keeps previous and current iterations in memory:
Dim oldList As New List(Of Integer)({0, 1})
For line = 1 To 7
Dim newList As New List(Of Integer)
For i = 1 To oldList.Count - 1
newList.Add(oldList(i - 1) + oldList(i))
Next
Debug.Print(String.Join(" ", newList))
oldList.Clear()
oldList.Add(0)
oldList.AddRange(newList)
oldList.Add(0)
Next
to do that using a windows form, you would need a textbox,multi-line textbox and a button on the design interface
here is the code you need to generate it
Imports System.Numerics 'this allows you to use big integer
Public Class pascal_triangle
Private Function factorial(ByVal k As Integer) As BigInteger
'big integer allows your proram compute for inputs of more than 22
If k = 0 Or k = 1 Then
Return 1
Else
Return k * factorial(k - 1)
End If
End Function
Private Sub BtnGen_Click(sender As Object, e As EventArgs) Handles BtnGen.Click
Dim nCr As Double
Dim i, j, k As Integer
Dim output As String
output = ""
j = Val(TxtColumn.Text)
For k = 0 To j
For i = 0 To k
Dim fact, fact1, fact2 As BigInteger
fact = factorial(k)
fact1 = factorial(k - i)
fact2 = factorial(i)
nCr = fact / (fact1 * fact2)
TxtOutput.Text += Str(nCr) & output
Next
TxtOutput.Text += vbCrLf
Next
End Sub
Private Sub pascal_triangle_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class