Count Specific Column Name - vb.net-2010

I just want to know why vb not execute the October month data? Here was my code.
For col As Integer = 4 To ldtData.Columns.Count - 1
If ldtData.Columns(col).ColumnName.Substring(0, 1) = "1"
Then cnt1 = cnt1 + 1
ElseIf ldtData.Columns(col).ColumnName.Substring(0, 1) = "2"
Then cnt2 = cnt2 + 1
ElseIf ldtData.Columns(col).ColumnName.Substring(0, 1) = "3"
Then cnt3 = cnt3 + 1
ElseIf ldtData.Columns(col).ColumnName.Substring(0, 1) = "4"
Then cnt4 = cnt4 + 1
ElseIf ldtData.Columns(col).ColumnName.Substring(0, 1) = "5"
Then cnt5 = cnt5 + 1
ElseIf ldtData.Columns(col).ColumnName.Substring(0, 1) = "6"
Then cnt6 = cnt6 + 1
ElseIf ldtData.Columns(col).ColumnName.Substring(0, 1) = "7"
Then cnt7 = cnt7 + 1
ElseIf ldtData.Columns(col).ColumnName.Substring(0, 1) = "8"
Then cnt8 = cnt8 + 1
ElseIf ldtData.Columns(col).ColumnName.Substring(0, 1) = "9"
Then cnt9 = cnt9 + 1
ElseIf ldtData.Columns(col).ColumnName.Substring(0, 2) = "10"
Then cnt10 = cnt10 + 1
ElseIf ldtData.Columns(col).ColumnName.Substring(0, 2) = "11"
Then cnt11 = cnt11 + 1
ElseIf ldtData.Columns(col).ColumnName.Substring(0, 2) = "12"
Then cnt12 = cnt12 + 1
End If
Next
For month 1 until 9 will count for how many data based on individual month, but for month 10, 11, 12 . it will execute as cnt1. Why?

Problem solved by adding - in every expected output after substring method.
If ldtData.Columns(col).ColumnName.Substring(0, 1) = "1-"
.
.
.
ElseIf ldtData.Columns(col).ColumnName.Substring(0, 1) = "10-"

Related

How to reduce case in VB Net?

Can this code be somewhat shorter? values change from 10 in 10 cases to +1, as follows as follows. For each textbox, I have these 80 cases, and I have a total of 30 textboxes and the code is too long. Once again I have to repeat the code, because aryText = TextNSt1.Text.Split ("," c) - up to aryText = TextNSt30.Text.Split ("," c) - so 30 times you code this, and I do not really like it, comma, the code is too long. The code changes with +1 in the following cases from Case 1 to 10, Cases 11-20, Cases 21-30, Cases 31-40, Cases 41-50, Cases 51-60, Cases 61-70, 71- 80...
Dim i As Integer
Dim aryText() As String
'SPLIT THE TEXT INTO AN ARRAY'
aryText = TextNSt2.Text.Split(","c)
For i = 0 To UBound(aryText)
Select Case aryText(i)
Case "1"
LbNxSt1.Text = Val(LbNxSt1.Text) + 1
txtS10.Text = Val(txtS10.Text) + 1
txtDrawB1.Text = Val(txtDrawB1.Text) + 1
Case "2"
LbNxSt2.Text = Val(LbNxSt2.Text) + 1
txtS10.Text = Val(txtS10.Text) + 2
txtDrawB1.Text = Val(txtDrawB1.Text) + 1
Case "3"
LbNxSt3.Text = Val(LbNxSt3.Text) + 1
txtS10.Text = Val(txtS10.Text) + 3
txtDrawB1.Text = Val(txtDrawB1.Text) + 1
Case "4"
LbNxSt4.Text = Val(LbNxSt4.Text) + 1
txtS10.Text = Val(txtS10.Text) + 4
txtDrawB1.Text = Val(txtDrawB1.Text) + 1
Case "5"
LbNxSt5.Text = Val(LbNxSt5.Text) + 1
txtS10.Text = Val(txtS10.Text) + 5
txtDrawB1.Text = Val(txtDrawB1.Text) + 1
Case "6"
LbNxSt6.Text = Val(LbNxSt6.Text) + 1
txtS10.Text = Val(txtS10.Text) + 6
txtDrawB1.Text = Val(txtDrawB1.Text) + 1
Case "7"
LbNxSt7.Text = Val(LbNxSt7.Text) + 1
txtS10.Text = Val(txtS10.Text) + 7
txtDrawB1.Text = Val(txtDrawB1.Text) + 1
Case "8"
LbNxSt8.Text = Val(LbNxSt8.Text) + 1
txtS10.Text = Val(txtS10.Text) + 8
txtDrawB1.Text = Val(txtDrawB1.Text) + 1
Case "9"
LbNxSt9.Text = Val(LbNxSt9.Text) + 1
txtS10.Text = Val(txtS10.Text) + 9
txtDrawB1.Text = Val(txtDrawB1.Text) + 1
Case "10"
LbNxSt10.Text = Val(LbNxSt10.Text) + 1
txtS10.Text = Val(txtS10.Text) + 10
txtDrawB1.Text = Val(txtDrawB1.Text) + 1
Case "11"
LbNxSt11.Text = Val(LbNxSt11.Text) + 1
txtS20.Text = Val(txtS20.Text) + 1
txtDrawB2.Text = Val(txtDrawB2.Text) + 1
Case "12"
LbNxSt12.Text = Val(LbNxSt12.Text) + 1
txtS20.Text = Val(txtS20.Text) + 2
txtDrawB2.Text = Val(txtDrawB2.Text) + 1
Case "13"
LbNxSt13.Text = Val(LbNxSt13.Text) + 1
txtS20.Text = Val(txtS20.Text) + 3
txtDrawB2.Text = Val(txtDrawB2.Text) + 1
Case "14"
LbNxSt14.Text = Val(LbNxSt14.Text) + 1
txtS20.Text = Val(txtS20.Text) + 4
txtDrawB2.Text = Val(txtDrawB2.Text) + 1
Case "15"
LbNxSt15.Text = Val(LbNxSt15.Text) + 1
txtS20.Text = Val(txtS20.Text) + 5
txtDrawB2.Text = Val(txtDrawB2.Text) + 1
Case "16"
LbNxSt16.Text = Val(LbNxSt16.Text) + 1
txtS20.Text = Val(txtS20.Text) + 6
txtDrawB2.Text = Val(txtDrawB2.Text) + 1
Case "17"
LbNxSt17.Text = Val(LbNxSt17.Text) + 1
txtS20.Text = Val(txtS20.Text) + 7
txtDrawB2.Text = Val(txtDrawB2.Text) + 1
Case "18"
LbNxSt18.Text = Val(LbNxSt18.Text) + 1
txtS20.Text = Val(txtS20.Text) + 8
txtDrawB2.Text = Val(txtDrawB2.Text) + 1
Case "19"
LbNxSt19.Text = Val(LbNxSt19.Text) + 1
txtS20.Text = Val(txtS20.Text) + 9
txtDrawB2.Text = Val(txtDrawB2.Text) + 1
Case "20"
LbNxSt20.Text = Val(LbNxSt20.Text) + 1
txtS20.Text = Val(txtS20.Text) + 10
txtDrawB2.Text = Val(txtDrawB2.Text) + 1
Case "21"
LbNxSt21.Text = Val(LbNxSt21.Text) + 1
txtS30.Text = Val(txtS30.Text) + 1
txtDrawB3.Text = Val(txtDrawB3.Text) + 1
Case "22"
LbNxSt22.Text = Val(LbNxSt22.Text) + 1
txtS30.Text = Val(txtS30.Text) + 2
txtDrawB3.Text = Val(txtDrawB3.Text) + 1
Case "23"
LbNxSt23.Text = Val(LbNxSt23.Text) + 1
txtS30.Text = Val(txtS30.Text) + 3
txtDrawB3.Text = Val(txtDrawB3.Text) + 1
Case "24"
LbNxSt24.Text = Val(LbNxSt24.Text) + 1
txtS30.Text = Val(txtS30.Text) + 4
txtDrawB3.Text = Val(txtDrawB3.Text) + 1
Case "25"
LbNxSt25.Text = Val(LbNxSt25.Text) + 1
txtS30.Text = Val(txtS30.Text) + 5
txtDrawB3.Text = Val(txtDrawB3.Text) + 1
Case "26"
LbNxSt26.Text = Val(LbNxSt26.Text) + 1
txtS30.Text = Val(txtS30.Text) + 6
txtDrawB3.Text = Val(txtDrawB3.Text) + 1
Case "27"
LbNxSt27.Text = Val(LbNxSt27.Text) + 1
txtS30.Text = Val(txtS30.Text) + 7
txtDrawB3.Text = Val(txtDrawB3.Text) + 1
Case "28"
LbNxSt28.Text = Val(LbNxSt28.Text) + 1
txtS30.Text = Val(txtS30.Text) + 8
txtDrawB3.Text = Val(txtDrawB3.Text) + 1
Case "29"
LbNxSt29.Text = Val(LbNxSt29.Text) + 1
txtS30.Text = Val(txtS30.Text) + 9
txtDrawB3.Text = Val(txtDrawB3.Text) + 1
Case "30"
LbNxSt30.Text = Val(LbNxSt30.Text) + 1
txtS30.Text = Val(txtS30.Text) + 10
txtDrawB3.Text = Val(txtDrawB3.Text) + 1
Case "31"
LbNxSt31.Text = Val(LbNxSt31.Text) + 1
txtS40.Text = Val(txtS40.Text) + 1
txtDrawB4.Text = Val(txtDrawB4.Text) + 1
Case "32"
LbNxSt32.Text = Val(LbNxSt32.Text) + 1
txtS40.Text = Val(txtS40.Text) + 2
txtDrawB4.Text = Val(txtDrawB4.Text) + 1
Case "33"
LbNxSt33.Text = Val(LbNxSt33.Text) + 1
txtS40.Text = Val(txtS40.Text) + 3
txtDrawB4.Text = Val(txtDrawB4.Text) + 1
Case "34"
LbNxSt34.Text = Val(LbNxSt34.Text) + 1
txtS40.Text = Val(txtS40.Text) + 4
txtDrawB4.Text = Val(txtDrawB4.Text) + 1
Case "35"
LbNxSt35.Text = Val(LbNxSt35.Text) + 1
txtS40.Text = Val(txtS40.Text) + 5
txtDrawB4.Text = Val(txtDrawB4.Text) + 1
Case "36"
LbNxSt36.Text = Val(LbNxSt36.Text) + 1
txtS40.Text = Val(txtS40.Text) + 6
txtDrawB4.Text = Val(txtDrawB4.Text) + 1
Case "37"
LbNxSt37.Text = Val(LbNxSt37.Text) + 1
txtS40.Text = Val(txtS40.Text) + 7
txtDrawB4.Text = Val(txtDrawB4.Text) + 1
Case "38"
LbNxSt38.Text = Val(LbNxSt38.Text) + 1
txtS40.Text = Val(txtS40.Text) + 8
txtDrawB4.Text = Val(txtDrawB4.Text) + 1
Case "39"
LbNxSt39.Text = Val(LbNxSt39.Text) + 1
txtS40.Text = Val(txtS40.Text) + 9
txtDrawB4.Text = Val(txtDrawB4.Text) + 1
Case "40"
LbNxSt40.Text = Val(LbNxSt40.Text) + 1
txtS40.Text = Val(txtS40.Text) + 10
txtDrawB4.Text = Val(txtDrawB4.Text) + 1
Case "41"
LbNxSt41.Text = Val(LbNxSt41.Text) + 1
txtS50.Text = Val(txtS50.Text) + 1
txtDrawB5.Text = Val(txtDrawB5.Text) + 1
Case "42"
LbNxSt42.Text = Val(LbNxSt42.Text) + 1
txtS50.Text = Val(txtS50.Text) + 2
txtDrawB5.Text = Val(txtDrawB5.Text) + 1
Case "43"
LbNxSt43.Text = Val(LbNxSt43.Text) + 1
txtS50.Text = Val(txtS50.Text) + 3
txtDrawB5.Text = Val(txtDrawB5.Text) + 1
Case "44"
LbNxSt44.Text = Val(LbNxSt44.Text) + 1
txtS50.Text = Val(txtS50.Text) + 4
txtDrawB5.Text = Val(txtDrawB5.Text) + 1
Case "45"
LbNxSt45.Text = Val(LbNxSt45.Text) + 1
txtS50.Text = Val(txtS50.Text) + 5
txtDrawB5.Text = Val(txtDrawB5.Text) + 1
Case "46"
LbNxSt46.Text = Val(LbNxSt46.Text) + 1
txtS50.Text = Val(txtS50.Text) + 6
txtDrawB5.Text = Val(txtDrawB5.Text) + 1
Case "47"
LbNxSt47.Text = Val(LbNxSt47.Text) + 1
txtS50.Text = Val(txtS50.Text) + 7
txtDrawB5.Text = Val(txtDrawB5.Text) + 1
Case "48"
LbNxSt48.Text = Val(LbNxSt48.Text) + 1
txtS50.Text = Val(txtS50.Text) + 8
txtDrawB5.Text = Val(txtDrawB5.Text) + 1
Case "49"
LbNxSt49.Text = Val(LbNxSt49.Text) + 1
txtS50.Text = Val(txtS50.Text) + 9
txtDrawB5.Text = Val(txtDrawB5.Text) + 1
Case "50"
LbNxSt50.Text = Val(LbNxSt50.Text) + 1
txtS50.Text = Val(txtS50.Text) + 10
txtDrawB5.Text = Val(txtDrawB5.Text) + 1
If you can work out the relationship between the "number" and the control, you can get the control like this:
For ary = 1 To 30
Dim aryText = Me.Controls("TextNSt" & ary).Text.Split({","c})
For i = 0 To aryText.Length - 1
Dim s = aryText(i)
Dim n = CInt(s)
Dim LbNxStNum = n Mod 10
If LbNxStNum = 0 Then LbNxStNum = 10
Dim LbNxSt = Me.Controls("LbNxSt" & LbNxStNum)
LbNxSt.Text = (CInt(LbNxSt.Text) + 1).ToString()
Dim txtSNum = (Math.Floor(n / 10) + 1) * 10
Dim txtS = Me.Controls("txtS" & txtSNum)
txtS.Text = (CInt(txtS.Text) + LbNxStNum).ToString()
Dim txtDrawBNum = Math.Ceiling(n / 10)
Dim txtDrawB = Me.Controls("txtDrawB" & txtDrawBNum)
txtDrawB.Text = (CInt(txtDrawB.Text) + 1).ToString()
Next
Next
I may have off-by-one errors in there, so you may need to make adjustments.
If Me is not the container, change it to use the appropriate Panel/whatever container.

assign 2D array to another 2D array

I am working in this project where I have to compare the value of an array with itself so I have used 2 2D arrays having the same size and values where I used one for comparing while making changes to the other the problem is that when I make changes to one the other also changes.
is there any way I can assign the value of any 2D arrays without having them changing together.
what I have used is the simple vb.net assignment:
x=y and it works fine only for that one issue.
I haven't completed the code yet that's what I have for now.
xgame = game
For i As Integer = 0 To n - 1
For j As Integer = 0 To n - 1
If (j = 0 And i = 0) Then
If xgame(i, j + 1) = "1" Then
count = count + 1
End If
If xgame(i + 1, j) = "1" Then
count = count + 1
End If
If xgame(i + 1, j + 1) = "1" Then
count = count + 1
End If
If count <= 1 Then
game(i, j) = "-"
End If
ElseIf (i = 0 And ((j > 0) Or (j < n - 1))) Then
count = 0
If xgame(i, j - 1) = "1" Then
count = count + 1
End If
If xgame(i, j + 1) = "1" Then
count = count + 1
End If
If xgame(i + 1, j - 1) = "1" Then
count = count + 1
End If
If xgame(i + 1, j) = "1" Then
count = count + 1
End If
If xgame(i + 1, j + 1) = "1" Then
count = count + 1
End If
If (count < 2 Or count > 3) Then
game(i, j) = "-"
ElseIf (count = 3) Then
game(i, j) = "1"
End If
ElseIf (i = 0 And j = n - 1) Then
End If
Next
Next

can someone help me to include aces into my blackjack program

I have been trying to create a simple blackjack game where the user picks cards and decides whether to hit or stick and if their cards go above 21 they lose. however i do not know how to add in aces so that the program will choose whether the ace will be a 1 or an 11.
please help
this is my code
Module Module1
Sub Main()
Dim cards(4, 13) As Integer
Dim value As Integer
Dim value2 As Integer
Dim royal As String
Dim suit As String
Dim card1 As Integer
Dim card2 As Integer
Dim card3 As Integer
Dim card4 As Integer
Dim card5 As Integer
Dim card6 As Integer
Dim card7 As Integer
Dim answer As String
Dim total As Integer
Randomize()
value = (3 * Rnd()) + 1
value2 = (11 * Rnd()) + 1
'suits: 1= hearts
'2= diamonds
'3=spades
'4=clubs
cards(1, 1) = 2
cards(2, 1) = 2
cards(3, 1) = 2
cards(4, 1) = 2
cards(1, 2) = 3
cards(2, 2) = 3
cards(3, 2) = 3
cards(4, 2) = 3
cards(1, 3) = 4
cards(2, 3) = 4
cards(3, 3) = 4
cards(4, 3) = 4
cards(1, 4) = 5
cards(2, 4) = 5
cards(3, 4) = 5
cards(4, 4) = 5
cards(1, 5) = 6
cards(2, 5) = 6
cards(3, 5) = 6
cards(4, 5) = 6
cards(1, 6) = 7
cards(2, 6) = 7
cards(3, 6) = 7
cards(4, 6) = 7
cards(1, 7) = 8
cards(2, 7) = 8
cards(3, 7) = 8
cards(4, 7) = 8
cards(1, 8) = 9
cards(2, 8) = 9
cards(3, 8) = 9
cards(4, 8) = 9
cards(1, 9) = 10
cards(2, 9) = 10
cards(3, 9) = 10
cards(4, 9) = 10
'jacks
cards(1, 10) = 10
cards(2, 10) = 10
cards(3, 10) = 10
cards(4, 10) = 10
'queens
cards(1, 11) = 10
cards(2, 11) = 10
cards(3, 11) = 10
cards(4, 11) = 10
'kings
cards(1, 12) = 10
cards(2, 12) = 10
cards(3, 12) = 10
cards(4, 12) = 10
If value2 = 1 Then
royal = "2"
ElseIf value2 = 2 Then
royal = "3"
ElseIf value2 = 3 Then
royal = "4"
ElseIf value2 = 4 Then
royal = "5"
ElseIf value2 = 5 Then
royal = "6"
ElseIf value2 = 6 Then
royal = "7"
ElseIf value2 = 7 Then
royal = "8"
ElseIf value2 = 8 Then
royal = "9"
ElseIf value2 = 9 Then
royal = "10"
ElseIf value2 = 10 Then
royal = "jack"
ElseIf value2 = 11 Then
royal = "queen"
ElseIf value2 = 12 Then
royal = "king"
End If
If value = 1 Then
suit = "hearts"
ElseIf value = 2 Then
suit = "diamonds"
ElseIf value = 3 Then
suit = "spades"
ElseIf value = 4 Then
suit = "clubs"
End If
Console.WriteLine("your first card is the {0} of {1}", royal, suit)
card1 = cards(value, value2)
value = (3 * Rnd()) + 1
value2 = (11 * Rnd()) + 1
If value2 = 1 Then
royal = "2"
ElseIf value2 = 2 Then
royal = "3"
ElseIf value2 = 3 Then
royal = "4"
ElseIf value2 = 4 Then
royal = "5"
ElseIf value2 = 5 Then
royal = "6"
ElseIf value2 = 6 Then
royal = "7"
ElseIf value2 = 7 Then
royal = "8"
ElseIf value2 = 8 Then
royal = "9"
ElseIf value2 = 9 Then
royal = "10"
ElseIf value2 = 10 Then
royal = "jack"
ElseIf value2 = 11 Then
royal = "queen"
ElseIf value2 = 12 Then
royal = "king"
End If
If value = 1 Then
suit = "hearts"
ElseIf value = 2 Then
suit = "diamonds"
ElseIf value = 3 Then
suit = "spades"
ElseIf value = 4 Then
suit = "clubs"
End If
Console.WriteLine("your second card is the {0} of {1}", royal, suit)
card2 = cards(value, value2)
Console.ReadKey()
total = card1 + card2
If total > 21 Then
Console.WriteLine("You lose")
Console.ReadLine()
Else
Console.WriteLine("Do you want to hit or stick?")
answer = Console.ReadLine
If answer = "hit" Then
value = (3 * Rnd()) + 1
value2 = (11 * Rnd()) + 1
If value2 = 1 Then
royal = "2"
ElseIf value2 = 2 Then
royal = "3"
ElseIf value2 = 3 Then
royal = "4"
ElseIf value2 = 4 Then
royal = "5"
ElseIf value2 = 5 Then
royal = "6"
ElseIf value2 = 6 Then
royal = "7"
ElseIf value2 = 7 Then
royal = "8"
ElseIf value2 = 8 Then
royal = "9"
ElseIf value2 = 9 Then
royal = "10"
ElseIf value2 = 10 Then
royal = "jack"
ElseIf value2 = 11 Then
royal = "queen"
ElseIf value2 = 12 Then
royal = "king"
End If
If value = 1 Then
suit = "hearts"
ElseIf value = 2 Then
suit = "diamonds"
ElseIf value = 3 Then
suit = "spades"
ElseIf value = 4 Then
suit = "clubs"
End If
Console.WriteLine("your card is the {0} of {1}", royal, suit)
card3 = cards(value, value2)
Console.ReadKey()
total = card1 + card2 + card3
If total > 21 Then
Console.WriteLine("You lose")
Console.ReadLine()
Else
Console.WriteLine("Do you want to hit or stick?")
answer = Console.ReadLine
If answer = "hit" Then
value = (3 * Rnd()) + 1
value2 = (11 * Rnd()) + 1
If value2 = 1 Then
royal = "2"
ElseIf value2 = 2 Then
royal = "3"
ElseIf value2 = 3 Then
royal = "4"
ElseIf value2 = 4 Then
royal = "5"
ElseIf value2 = 5 Then
royal = "6"
ElseIf value2 = 6 Then
royal = "7"
ElseIf value2 = 7 Then
royal = "8"
ElseIf value2 = 8 Then
royal = "9"
ElseIf value2 = 9 Then
royal = "10"
ElseIf value2 = 10 Then
royal = "jack"
ElseIf value2 = 11 Then
royal = "queen"
ElseIf value2 = 12 Then
royal = "king"
End If
If value = 1 Then
suit = "hearts"
ElseIf value = 2 Then
suit = "diamonds"
ElseIf value = 3 Then
suit = "spades"
ElseIf value = 4 Then
suit = "clubs"
End If
Console.WriteLine("your card is the {0} of {1}", royal, suit)
card4 = cards(value, value2)
Console.ReadKey()
total = card1 + card2 + card3 + card4
If total > 21 Then
Console.WriteLine("You lose")
Console.ReadLine()
Else
Console.WriteLine("Do you want to hit or stick?")
answer = Console.ReadLine
If answer = "hit" Then
value = (3 * Rnd()) + 1
value2 = (11 * Rnd()) + 1
If value2 = 1 Then
royal = "2"
ElseIf value2 = 2 Then
royal = "3"
ElseIf value2 = 3 Then
royal = "4"
ElseIf value2 = 4 Then
royal = "5"
ElseIf value2 = 5 Then
royal = "6"
ElseIf value2 = 6 Then
royal = "7"
ElseIf value2 = 7 Then
royal = "8"
ElseIf value2 = 8 Then
royal = "9"
ElseIf value2 = 9 Then
royal = "10"
ElseIf value2 = 10 Then
royal = "jack"
ElseIf value2 = 11 Then
royal = "queen"
ElseIf value2 = 12 Then
royal = "king"
End If
If value = 1 Then
suit = "hearts"
ElseIf value = 2 Then
suit = "diamonds"
ElseIf value = 3 Then
suit = "spades"
ElseIf value = 4 Then
suit = "clubs"
End If
Console.WriteLine("your card is the {0} of {1}", royal, suit)
card5 = cards(value, value2)
Console.ReadKey()
total = card1 + card2 + card3 + card4 + card5
If total > 21 Then
Console.WriteLine("You lose")
Console.ReadLine()
Else
Console.WriteLine("Do you want to hit or stick?")
answer = Console.ReadLine
If answer = "hit" Then
value = (3 * Rnd()) + 1
value2 = (11 * Rnd()) + 1
If value2 = 1 Then
royal = "2"
ElseIf value2 = 2 Then
royal = "3"
ElseIf value2 = 3 Then
royal = "4"
ElseIf value2 = 4 Then
royal = "5"
ElseIf value2 = 5 Then
royal = "6"
ElseIf value2 = 6 Then
royal = "7"
ElseIf value2 = 7 Then
royal = "8"
ElseIf value2 = 8 Then
royal = "9"
ElseIf value2 = 9 Then
royal = "10"
ElseIf value2 = 10 Then
royal = "jack"
ElseIf value2 = 11 Then
royal = "queen"
ElseIf value2 = 12 Then
royal = "king"
End If
If value = 1 Then
suit = "hearts"
ElseIf value = 2 Then
suit = "diamonds"
ElseIf value = 3 Then
suit = "spades"
ElseIf value = 4 Then
suit = "clubs"
End If
Console.WriteLine("your card is the {0} of {1}", royal, suit)
card6 = cards(value, value2)
Console.ReadKey()
total = card1 + card2 + card3 + card4 + card5 + card6
If total > 21 Then
Console.WriteLine("You lose")
Console.ReadLine()
Else
Console.WriteLine("Do you want to hit or stick?")
answer = Console.ReadLine
If answer = "hit" Then
value = (3 * Rnd()) + 1
value2 = (11 * Rnd()) + 1
If value2 = 1 Then
royal = "2"
ElseIf value2 = 2 Then
royal = "3"
ElseIf value2 = 3 Then
royal = "4"
ElseIf value2 = 4 Then
royal = "5"
ElseIf value2 = 5 Then
royal = "6"
ElseIf value2 = 6 Then
royal = "7"
ElseIf value2 = 7 Then
royal = "8"
ElseIf value2 = 8 Then
royal = "9"
ElseIf value2 = 9 Then
royal = "10"
ElseIf value2 = 10 Then
royal = "jack"
ElseIf value2 = 11 Then
royal = "queen"
ElseIf value2 = 12 Then
royal = "king"
End If
If value = 1 Then
suit = "hearts"
ElseIf value = 2 Then
suit = "diamonds"
ElseIf value = 3 Then
suit = "spades"
ElseIf value = 4 Then
suit = "clubs"
End If
Console.WriteLine("your card is the {0} of {1}", royal, suit)
card7 = cards(value, value2)
Console.ReadKey()
total = card1 + card2 + card3 + card4 + card5 + card6 + card7
ElseIf answer = "stick" Then
Console.WriteLine("your final score is {0}", total)
Console.ReadLine()
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End Sub
End Module
Use a rule like: Aces are worth 11, unless the total exceeds 21, then they are worth 1. You have to recalculate the total for each ace in the hand until the total is less then or equal to 21. This might not be a truly optimal strategy, but good enough for learning how to code.
The thing to remember is that THERE IS NO "CHOICE" to count an ace as 1 or 11. It is strictly determined by the hand. Count all aces as 1. Then, if the hand contains one or more aces, and totals less than 12, add 10. That's it. Only one ace can ever be counted as 11, and only when it MUST be.
The really tricky part of programming blackjack is to remember that you need to keep track of the hand total and an extra bit of info to indicate if the total is "soft" or not (if you added the 10 above, it's soft).

Change specific row and column in Datagridview

I want to change specific row and column in Datagridview.
when I enter specific data in column x it will return any specific value in column Y. Otherwise data in column x will return value 7777 in column Y
But when I run this code, there were nothing change in column Y :
Private Sub Table1DataGridView_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Table1DataGridView.CellEndEdit
'For e.ColumnIndex + 1
If e.ColumnIndex = 2 Then
If Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 5
ElseIf Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 7 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 7
ElseIf Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 1 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 6
'1
ElseIf Val(Table1DataGridView.Rows(1).Cells(2).Value) = 1.5 Then
Table1DataGridView.Rows(1).Cells(e.ColumnIndex + 1).Value = 7.326
'2
ElseIf Val(Table1DataGridView.Rows(2).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(2).Cells(e.ColumnIndex + 1).Value = 6.374
'3
ElseIf Val(Table1DataGridView.Rows(3).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(3).Cells(e.ColumnIndex + 1).Value = 4.702
'4
ElseIf Val(Table1DataGridView.Rows(4).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(4).Cells(e.ColumnIndex + 1).Value = 1.321
'5
ElseIf Val(Table1DataGridView.Rows(5).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(5).Cells(e.ColumnIndex + 1).Value = 0.035
'6
ElseIf Val(Table1DataGridView.Rows(6).Cells(2).Value) = 4 Then
Table1DataGridView.Rows(6).Cells(e.ColumnIndex + 1).Value = 0.205
'7
ElseIf Val(Table1DataGridView.Rows(7).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(7).Cells(e.ColumnIndex + 1).Value = 4.969
'8
ElseIf Val(Table1DataGridView.Rows(16).Cells(2).Value) = 4 Then
Table1DataGridView.Rows(16).Cells(e.ColumnIndex + 1).Value = 1.588
'9
ElseIf Val(Table1DataGridView.Rows(17).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(17).Cells(e.ColumnIndex + 1).Value = 4.696
'10
ElseIf Val(Table1DataGridView.Rows(18).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(18).Cells(e.ColumnIndex + 1).Value = 0.866
'11
ElseIf Val(Table1DataGridView.Rows(19).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(19).Cells(e.ColumnIndex + 1).Value = 1.881
'12
ElseIf Val(Table1DataGridView.Rows(20).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(20).Cells(e.ColumnIndex + 1).Value = 4.702
'13
ElseIf Val(Table1DataGridView.Rows(21).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(21).Cells(e.ColumnIndex + 1).Value = 6.515
'14
ElseIf Val(Table1DataGridView.Rows(22).Cells(2).Value) = 1.5 Then
Table1DataGridView.Rows(22).Cells(e.ColumnIndex + 1).Value = 6.92671744
Else
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 7777
End If
End If
End Sub
Then, I try to change this code, but return some same value at column Y :
Private Sub Table1DataGridView_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Table1DataGridView.CellEndEdit
'For e.ColumnIndex + 1
If e.ColumnIndex = 2 Then
If Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 5
ElseIf Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 7 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 7
ElseIf Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 1 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 6
'1
ElseIf Val(Table1DataGridView.Rows(1).Cells(2).Value) = 1.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 7.326
'2
ElseIf Val(Table1DataGridView.Rows(2).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 6.374
'3
ElseIf Val(Table1DataGridView.Rows(3).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 4.702
'4
ElseIf Val(Table1DataGridView.Rows(4).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 1.321
'5
ElseIf Val(Table1DataGridView.Rows(5).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 0.035
'6
ElseIf Val(Table1DataGridView.Rows(6).Cells(2).Value) = 4 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 0.205
'7
ElseIf Val(Table1DataGridView.Rows(7).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 4.969
'8
ElseIf Val(Table1DataGridView.Rows(16).Cells(2).Value) = 4 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 1.588
'9
ElseIf Val(Table1DataGridView.Rows(17).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 4.696
'10
ElseIf Val(Table1DataGridView.Rows(18).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 0.866
'11
ElseIf Val(Table1DataGridView.Rows(19).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 1.881
'12
ElseIf Val(Table1DataGridView.Rows(20).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 4.702
'13
ElseIf Val(Table1DataGridView.Rows(21).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 6.515
'14
ElseIf Val(Table1DataGridView.Rows(22).Cells(2).Value) = 1.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 6.92671744
Else
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 7777
End If
End If
End Sub
Thanks for the help!
If the DataGridView is databound, you need modify the databound object not the grid directly. You can access that object through the DataBoundItem property:
Dim obj As MyObject = Table1DataGridView.CurrentRow.DataBoundItem
obj.MyProperty = newValue
just set MyObject and MyProperty as appropriate

Making automated ID in VBA

I am new in and is trying to give an automated ID in which i used the following code:
y = 0
If txtdsgnation = "Plumbing" Then
x = "P"
Do Until Cells(i, 3) = ""
If Cells(i, 3) = "Plumbing" Then
y = y + 1
End If
i = i + 1
Loop
End If
If txtdsgnation = "Electricity" Then
x = "E"
Do Until Cells(i, 3) = ""
If Cells(i, 3) = "Electricity" Then
y = y + 1
End If
i = i + 1
Loop
End If
If txtdsgnation = "Fittings" Then
x = "F"
Do Until Cells(i, 3) = ""
If Cells(i, 3) = "Fittings" Then
y = y + 1
End If
i = i + 1
Loop
End If
If txtdsgnation = "Lift maintenance" Then
x = "L"
Do Until Cells(i, 3) = ""
If Cells(i, 3) = "Lift maintenance" Then
y = y + 1
End If
i = i + 1
Loop
End If
z = 100 + y
txtID = x + "-" + z
The thing i am trying to do is that if i add a new employee, for example a plumber and I already have 2 plumbers txtID will automatically become "P-102"
Thanks in advance
In the loop, the y is always getting initialized with 0. So, y has no chance to become more than 1. Please try to put the y out of the loop.