I am trying to build a 15 number shuffle game in VB.
Later on, I will have to submit the 15 pieces to a full image.
At the mintime, I tries to build it with numbers. it was all working fine until I got this messege:
Conversion from string "" to type 'Double' is not valid.
I got it in line:
If butt2.Content = "" Then
here is my code:
<pre lang="vb">Class MainWindow
Private Sub btn1_Click(sender As Object, e As RoutedEventArgs) Handles btn1.Click
'2,4
checkBtn(btn1, btn4)
checkBtn(btn1, btn2)
chechSolved()
End Sub
Private Sub btn2_Click(sender As Object, e As RoutedEventArgs) Handles btn2.Click
'1,3,5
checkBtn(btn2, btn1)
checkBtn(btn2, btn3)
checkBtn(btn2, btn5)
chechSolved()
End Sub
Private Sub btn3_Click(sender As Object, e As RoutedEventArgs) Handles btn3.Click
'2,6
checkBtn(btn3, btn2)
checkBtn(btn3, btn6)
chechSolved()
End Sub
Private Sub btn4_Click(sender As Object, e As RoutedEventArgs) Handles btn4.Click
'1,5,7
checkBtn(btn4, btn1)
checkBtn(btn4, btn5)
checkBtn(btn4, btn7)
chechSolved()
End Sub
Private Sub btn5_Click(sender As Object, e As RoutedEventArgs) Handles btn5.Click
'2,4,6,8
checkBtn(btn5, btn2)
checkBtn(btn5, btn4)
checkBtn(btn5, btn6)
checkBtn(btn5, btn8)
chechSolved()
End Sub
Private Sub btn6_Click(sender As Object, e As RoutedEventArgs) Handles btn6.Click
'3,5,9
checkBtn(btn6, btn3)
checkBtn(btn6, btn5)
checkBtn(btn6, btn9)
chechSolved()
End Sub
Private Sub btn7_Click(sender As Object, e As RoutedEventArgs) Handles btn7.Click
'4,8
checkBtn(btn7, btn4)
checkBtn(btn7, btn8)
chechSolved()
End Sub
Private Sub btn8_Click(sender As Object, e As RoutedEventArgs) Handles btn8.Click
'5,7,9
checkBtn(btn8, btn5)
checkBtn(btn8, btn7)
checkBtn(btn8, btn9)
chechSolved()
End Sub
Private Sub btn9_Click(sender As Object, e As RoutedEventArgs) Handles btn9.Click
'6,8
checkBtn(btn9, btn6)
checkBtn(btn9, btn8)
chechSolved()
End Sub
Sub checkBtn(ByVal butt1 As Button, ByVal butt2 As Button)
If butt2.Content = "" Then
butt2.Content = butt1.Content
butt1.Content = ""
End If
End Sub
Sub chechSolved()
If btn1.Content = "1" And btn2.Content = "2" And btn3.Content = "3" And btn4.Content = "4" And btn5.Content = "5" And btn6.Content = "6" And btn7.Content = "7" And btn8.Content = "8" And btn9.Content = "" Then
MsgBox("הצלחת")
End If
End Sub
Sub shuffle()
Dim a(8), i, j, RN As Integer
Dim flag As Boolean
flag = False
i = 1
a(j) = 1
Do While i <= 8
Randomize()
RN = CInt(Int((8 * 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 + 1
End If
Loop
btn1.Content = a(1)
btn2.Content = a(2)
btn3.Content = a(3)
btn4.Content = a(4)
btn5.Content = a(5)
btn6.Content = a(6)
btn7.Content = a(7)
btn8.Content = a(8)
btn9.Content = ""
End Sub
Private Sub btnSH_Click(sender As Object, e As RoutedEventArgs) Handles btnSH.Click
shuffle()
End Sub
End Class</pre>
it would help a lot if you look at it.
The compiler might be having a problem comparing the string to the btn.Content because you set the Content to an Integer type (btn1.Content = a(1))
Related
I already succeeded in made local database using datatable and it was displayed in datagridview. But I want to copy the values to array so I can process it in other code.
For example
coba(0,0) = data in datagridviewResources column 0 row 0
coba(0,1) = data in datagridviewresources column 0 row 1
But I got the error :
Index was out of range. Must be non-negative and less than the size of the collection.
My code:
Dim table As New DataTable("Table")
Dim index As Integer
Dim coba(100, 100) As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
table.Columns.Add("ID", Type.GetType("System.Int32"))
table.Columns.Add("Filename", Type.GetType("System.String"))
table.Columns.Add("Column", Type.GetType("System.Int32"))
datagridviewResources.DataSource = table
End Sub
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
Dim newDataRow As DataGridViewRow
newDataRow = datagridviewResources.Rows(index)
newDataRow.Cells(0).Value = txtID.Text
newDataRow.Cells(1).Value = txtFilename.Text
newDataRow.Cells(2).Value = txtColumn.Text
End Sub
Private Sub datagridviewResources_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles datagridviewResources.CellClick
index = e.RowIndex
Dim selectedRow As DataGridViewRow
selectedRow = datagridviewResources.Rows(index)
txtID.Text = selectedRow.Cells(0).Value.ToString()
txtFilename.Text = selectedRow.Cells(1).Value.ToString()
txtColumn.Text = selectedRow.Cells(2).Value.ToString()
End Sub
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
datagridviewResources.Rows.RemoveAt(index)
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
table.Rows.Add(txtID.Text, txtFilename.Text, txtColumn.Text)
datagridviewResources.DataSource = table
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click, datagridviewResources.SelectionChanged
For i = 0 To table.Rows.Count
For j = 0 To table.Columns.Count
coba(i,j) = datagridviewResources.Rows(i).Cells(j).Value.ToString())
Next
Next
End Sub
I'm building a program that using a service based database.
My first problem:
I want that when somebody clicks on one of the colors it will store a String in the database like "color_red"
Second problem:
I want that each radio button will store a different integer
Database Schema:
Relevant code:
Public Class Form2
Private Sub TableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TableBindingNavigatorSaveItem.Click
Me.Validate()
Me.TableBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Database1)
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Database1.Table' table. You can move, or remove it, as needed.
Me.TableTableAdapter.Fill(Me.Database1.Table)
End Sub
Private Sub TableDataGridView_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)
End Sub
Private Sub TableBindingNavigator_RefreshItems(sender As Object, e As EventArgs) Handles TableBindingNavigator.RefreshItems
End Sub
Private Sub Nb_typeRadioButton_CheckedChanged(sender As Object, e As EventArgs) Handles Nb_typeRadioButton.CheckedChanged
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
PictureBox1.BorderStyle = BorderStyle.Fixed3D
PictureBox2.BorderStyle = BorderStyle.FixedSingle
PictureBox3.BorderStyle = BorderStyle.FixedSingle
PictureBox4.BorderStyle = BorderStyle.FixedSingle
PictureBox5.BorderStyle = BorderStyle.FixedSingle
End Sub
Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
PictureBox1.BorderStyle = BorderStyle.FixedSingle
PictureBox2.BorderStyle = BorderStyle.Fixed3D
PictureBox3.BorderStyle = BorderStyle.FixedSingle
PictureBox4.BorderStyle = BorderStyle.FixedSingle
PictureBox5.BorderStyle = BorderStyle.FixedSingle
End Sub
Private Sub PictureBox3_Click(sender As Object, e As EventArgs) Handles PictureBox3.Click
PictureBox1.BorderStyle = BorderStyle.FixedSingle
PictureBox2.BorderStyle = BorderStyle.FixedSingle
PictureBox3.BorderStyle = BorderStyle.Fixed3D
PictureBox4.BorderStyle = BorderStyle.FixedSingle
PictureBox5.BorderStyle = BorderStyle.FixedSingle
End Sub
Private Sub PictureBox4_Click(sender As Object, e As EventArgs) Handles PictureBox4.Click
PictureBox1.BorderStyle = BorderStyle.FixedSingle
PictureBox2.BorderStyle = BorderStyle.FixedSingle
PictureBox3.BorderStyle = BorderStyle.FixedSingle
PictureBox4.BorderStyle = BorderStyle.Fixed3D
PictureBox5.BorderStyle = BorderStyle.FixedSingle
End Sub
Private Sub PictureBox5_Click(sender As Object, e As EventArgs) Handles PictureBox5.Click
PictureBox1.BorderStyle = BorderStyle.FixedSingle
PictureBox2.BorderStyle = BorderStyle.FixedSingle
PictureBox3.BorderStyle = BorderStyle.FixedSingle
PictureBox4.BorderStyle = BorderStyle.FixedSingle
PictureBox5.BorderStyle = BorderStyle.Fixed3D
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Me.Validate()
Me.TableBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Database1)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try
Dim db As New Database1TableAdapters.TableTableAdapter
Dim dbimg As String = db.GetData.Rows(0).Item(1)
PictureBox1.Image = My.Resources.ResourceManager.GetObject(dbimg)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class
I will update my answer as soon as you provide more quality information.
For now here is what I understood you want to do:
In Button.Click event you should write:
If Me.Radiobutton1.Checked = True than
Value = 1 '' For Example
Else
Value = 2 '' For Example
End If
Or you can do it like this:
If Me.Radiobutton1.Checked = True than
Value = 1
ElseIf Me.Radiobutton2.Checked = True than
Value = 2
End if
This is about giving values according to checked RadioButton.
And about marked PictureBox I would just add to Button.Click event:
If Me.PictureBox1.BorderStyle = BorderStyle.Fixed3D Then
StringValue = 1
ElseIf Me.PictureBox2.BorderStyle = BorderStyle.Fixed3D Then
StringValue = 2
ElseIf Me.PictureBox3.BorderStyle = BorderStyle.Fixed3D Then
StringValue = 3
ElseIf Me.PictureBox4.BorderStyle = BorderStyle.Fixed3D Then
StringValue = 4
ElseIf Me.PictureBox5.BorderStyle = BorderStyle.Fixed3D Then
StringValue = 5
End If
i need to build a 15 picture puzzle and i don't know how to add an image to a button in a way that the image will fill all of the space of the button. or i should do it diffrently?? here is a link of what i need to build:
sahek.co.il/content/full_screen.php?url=http://www.sahek.co.il/…
at the moment all i have is a game with numbers:
Class MainWindow
Private Sub btn1_Click(sender As Object, e As RoutedEventArgs) Handles btn1.Click
'2,4
checkBtn(btn1, btn4)
checkBtn(btn1, btn2)
chechSolved()
End Sub
Private Sub btn2_Click(sender As Object, e As RoutedEventArgs) Handles btn2.Click
'1,3,5
checkBtn(btn2, btn1)
checkBtn(btn2, btn3)
checkBtn(btn2, btn5)
chechSolved()
End Sub
Private Sub btn3_Click(sender As Object, e As RoutedEventArgs) Handles btn3.Click
'2,6
checkBtn(btn3, btn2)
checkBtn(btn3, btn6)
chechSolved()
End Sub
Private Sub btn4_Click(sender As Object, e As RoutedEventArgs) Handles btn4.Click
'1,5,7
checkBtn(btn4, btn1)
checkBtn(btn4, btn5)
checkBtn(btn4, btn7)
chechSolved()
End Sub
Private Sub btn5_Click(sender As Object, e As RoutedEventArgs) Handles btn5.Click
'2,4,6,8
checkBtn(btn5, btn2)
checkBtn(btn5, btn4)
checkBtn(btn5, btn6)
checkBtn(btn5, btn8)
chechSolved()
End Sub
Private Sub btn6_Click(sender As Object, e As RoutedEventArgs) Handles btn6.Click
'3,5,9
checkBtn(btn6, btn3)
checkBtn(btn6, btn5)
checkBtn(btn6, btn9)
chechSolved()
End Sub
Private Sub btn7_Click(sender As Object, e As RoutedEventArgs) Handles btn7.Click
'4,8
checkBtn(btn7, btn4)
checkBtn(btn7, btn8)
chechSolved()
End Sub
Private Sub btn8_Click(sender As Object, e As RoutedEventArgs) Handles btn8.Click
'5,7,9
checkBtn(btn8, btn5)
checkBtn(btn8, btn7)
checkBtn(btn8, btn9)
chechSolved()
End Sub
Private Sub btn9_Click(sender As Object, e As RoutedEventArgs) Handles btn9.Click
'6,8
checkBtn(btn9, btn6)
checkBtn(btn9, btn8)
chechSolved()
End Sub
Sub checkBtn(ByRef butt1 As Button, ByRef butt2 As Button)
If butt2.Content = "" Then
butt2.Content = butt1.Content
butt1.Content = ""
End If
End Sub
Sub chechSolved()
If btn1.Content = "1" And btn2.Content = "2" And btn3.Content = "3" And btn4.Content = "4" And btn5.Content = "5" And btn6.Content = "6" And btn7.Content = "7" And btn8.Content = "8" And btn9.Content = "" Then
MsgBox("הצלחת")
End If
End Sub
Sub shuffle()
Dim a(8) As String
Dim i, j, RN As Integer
Dim flag As Boolean
flag = False
i = 1
a(j) = 1
Do While i <= 8
Randomize()
RN = CInt(Int((8 * 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 + 1
End If
Loop
btn1.Content = a(1)
btn2.Content = a(2)
btn3.Content = a(3)
btn4.Content = a(4)
btn5.Content = a(5)
btn6.Content = a(6)
btn7.Content = a(7)
btn8.Content = a(8)
btn9.Content = ""
End Sub
Private Sub btnSH_Click(sender As Object, e As RoutedEventArgs) Handles btnSH.Click
shuffle()
End Sub
End Class
Try this in your XAML code:
You can also try Stretch="None", "Fill", "Uniform", or "UniformToFil". Here is more information about Imaging Overview
<Button Height="100" Width="25" >
<Button.Background>
<ImageBrush ImageSource="your image source path" Stretch="Fill" TileMode="None" />
</Button.Background>
</Button>
In XAML you can try,
<Button Name="button1" Width="50" Height="30" Click="OnImageButtonClick">
<Image Source="Images/YourImageName.jpg"></Image></Button>
Or,
from code behind try with,
var brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri("Images/Image1.jpg",UriKind.Relative));
button1.Background = brush;
Or,
BitmapImage btm = new BitmapImage(new Uri("/LoadImages;component/Images/test.png", UriKind.Relative));
Image img = new Image();
img.Source = btm;
img.Stretch = Stretch.Fill;
button2.Content = img;
Remember to set your image build action property as content or resource as you wish.But if you set button background from resource image then use above code like..
Uri resourceUri = new Uri("Images/Image1.jpg", UriKind.Relative);
StreamResourceInfo streamInfo = Application.GetResourceStream(resourceUri);
BitmapFrame temp = BitmapFrame.Create(streamInfo.Stream);
var brush = new ImageBrush();
brush.ImageSource = temp;
button1.Background = brush;
And finally another great alternative solution for you..
http://imagebuttonwpf.codeplex.com/
I'm learnning vstudio 2012, I'm trying to make moveable a form with "borderstyle = none" but i can't.
All the info that i found in Google talks about vb4 5 & 6 about this problem, versions too earlier for me and i cannot use they (I don't know how to).
my declaraments is very simple, i only need to make the window moveable by clicking on the app (anywhere on the form):
Public Class Form1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label2.Text = "X: " & MousePosition.X
Label3.Text = "Y: " & MousePosition.Y
End Sub
Sub Form1_KeyPress(ByVal sender As Object, _
ByVal e As KeyPressEventArgs) Handles Me.KeyPress
If e.KeyChar >= ChrW(3) Then
Clipboard.SetDataObject(Label2.Text & " " & Label3.Text)
End If
End Sub
End Class
Any help please? thankyou for read
I've resolved this, thanks.
Private ArrastrarForm As Boolean
Private PosicionMouseHeader As Point
Private tmpPoint As Point
Private Sub Form1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
ArrastrarForm = True
PosicionMouseHeader = e.Location
End If
End Sub
Private Sub Form1_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If ArrastrarForm Then
tmpPoint = Me.Location + e.Location - PosicionMouseHeader
Me.Location = tmpPoint
End If
End Sub
Private Sub Form1_MouseUp(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
If e.Button = Windows.Forms.MouseButtons.Left Then
ArrastrarForm = False
End If
End Sub
bye!
The following is the code which I am using for creating a two dimensional array
Public Class frmGrades
Private Score As Dictionary(Of String, String) = New Dictionary(Of String, String)
Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdApply.Click
Static intNumber As Integer
ReDim Preserve Score(1, intNumber)
Score(0, intNumber) = txtStudent.Text
Score(1, intNumber) = txtGrade.Text
hsbStudent.Maximum = intNumber
hsbStudent.Value = intNumber
intNumber = intNumber + 1
txtGrade.Clear()
txtStudent.Clear()
txtStudent.Focus()
End Sub
Private Sub hsbStudent_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles hsbStudent.Scroll
txtStudent.Text = Score(0, hsbStudent.Value)
txtGrade.Text = Score(1, hsbStudent.Value)
End Sub
Private Sub cmdFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFirst.Click
txtStudent.Text = Score(0, hsbStudent.Minimum)
txtGrade.Text = Score(1, hsbStudent.Minimum)
End Sub
Private Sub cmdLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLast.Click
txtStudent.Text = Score(0, hsbStudent.Maximum)
txtGrade.Text = Score(1, hsbStudent.Maximum)
End Sub
**Private Sub CmdEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdEdit.Click
If Score.ContainsKey(txtStudent.Text) Then
Score.Item(txtStudent.Text) = txtGrade.Text
Else
Score.Add(txtStudent.Text, txtGrade.Text)
End If
End Sub
End Class**
Now I would like to edit the grade text box which should also change the grade in the array. Any idea on how could this be done.
UPDATE:
OK, I see the code has a little more now and the problem is more clear as well as the need for a different approach. I rewrote your code. See if this works for you:
Public Class frmGrades
Public Class StudentGrade
Public Name As String
Public Grade As String
End Class
Private Score As List(Of StudentGrade) = New List(Of StudentGrade)
Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdApply.Click
AddStudent()
End Sub
Private Sub hsbStudent_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles hsbStudent.Scroll
Update(hsbStudent.Value - 1) 'lists are zero-based
End Sub
Private Sub cmdFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFirst.Click
Update(0)
End Sub
Private Sub cmdLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLast.Click
Update(hsbStudent.Maximum - 1)
End Sub
Private Sub AddStudent()
Dim nm As New StudentGrade
nm.Name = txtStudent.Text
nm.Grade = txtGrade.Text
Score.Add(nm)
hsbStudent.Minimum = 1
hsbStudent.Maximum = Score.Count
hsbStudent.Value = Score.Count
txtGrade.Clear()
txtStudent.Clear()
txtStudent.Focus()
End Sub
Private Sub Update(i As Integer)
txtStudent.Text = Score(i).Name
txtGrade.Text = Score(i).Grade
End Sub
Private Sub CmdEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdEdit.Click
Dim index As Integer = -1, cnt As Integer = 0
For Each nm As StudentGrade In Score
If nm.Name.ToLower = txtStudent.Text.ToLower Then
index = cnt
Exit For
End If
cnt += 1
Next
If index = -1 Then
AddStudent()
Else
Score(index).Name = txtStudent.Text
Score(index).Grade = txtGrade.Text
hsbStudent.Value = index + 1
End If
End Sub
End Class
With this code you can expand the class StudentGrade to contain whatever you need to store. The list, contrary to dictionary, allow you to use index values as well.