My If Else Statement VB.Net's weird behavior - vb.net

I have this program that when I typed the same text on the form and to the other form will add one (+1) to the label of my last form..There were no errors but when I wrote the correct answers on the textboxes it just gave me a number 1 instead of 10. Please help me guys. Thanks in advance :)
here is my code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm4 = New Form4()
frm1 = New Form1()
Dim Textbox1 As New TextBox
Dim Label3 As New Label
If Textbox1.Text = frm1.TextBox2.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox2.Text = frm1.TextBox4.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox3.Text = frm1.TextBox6.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox4.Text = frm1.TextBox8.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox5.Text = frm1.TextBox10.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox6.Text = frm1.TextBox12.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox7.Text = frm1.TextBox14.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox8.Text = frm1.TextBox16.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox9.Text = frm1.TextBox18.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox10.Text = frm1.TextBox20.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
End If
End If
End If
End If
End If
End If
End If
End If
End If
frm4.Show()
Else
frm4.Label3.Text = frm4.Label3.Text
frm4.Show()
End If
End Sub
Form 2 codes:
Public Class Form2
Private frm1 As Form1 ' remove the new here because it creates a new instance of Form1'
Private frm3 As Form3
Public lbl As New Label ' not needed?'
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Controls.Add(lbl)
End Sub
Public Sub New(ByVal callerInstance As Form1)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm1 = callerInstance
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Dim Label21 As Label = New Label ' this label is not needed'
' Dim Textbox1 As TextBox = New TextBox ' this textbox is not needed'
' Create a new instance of Form3, do not use the automatic Form3 instance
' automatically created by VB.NET
frm3 = New Form3()
' now you are referring to the caller instance of Form1 '
' where there is the textbox filled with your text '
frm3.Label21.Text = frm1.TextBox1.Text
frm3.Label22.Text = frm1.TextBox3.Text
frm3.Label23.Text = frm1.TextBox5.Text
frm3.Label24.Text = frm1.TextBox7.Text
frm3.Label25.Text = frm1.TextBox9.Text
frm3.Label26.Text = frm1.TextBox11.Text
frm3.Label27.Text = frm1.TextBox13.Text
frm3.Label28.Text = frm1.TextBox15.Text
frm3.Label29.Text = frm1.TextBox17.Text
frm3.Label30.Text = frm1.TextBox19.Text
frm3.Show()
End Sub
End Class
Form1 Codes:
Public Class Form1
Private frm2 As Form2
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If frm2 Is Nothing Then
frm2 = New Form2(Me)
AddHandler frm2.FormClosed, AddressOf Me.Form2HasBeenClosed
Dim Label21 As Label = New Label
frm2.Label21.Text = TextBox1.Text
frm2.Label21.ForeColor = Color.Black
Dim Label22 As Label = New Label
frm2.Label22.Text = TextBox2.Text
frm2.Label22.ForeColor = Color.Black
Dim Label23 As Label = New Label
frm2.Label23.Text = TextBox3.Text
frm2.Label23.ForeColor = Color.Black
Dim Label24 As Label = New Label
frm2.Label24.Text = TextBox4.Text
frm2.Label24.ForeColor = Color.Black
Dim Label25 As Label = New Label
frm2.Label25.Text = TextBox5.Text
frm2.Label25.ForeColor = Color.Black
Dim Label26 As Label = New Label
frm2.Label26.Text = TextBox6.Text
frm2.Label26.ForeColor = Color.Black
Dim Label27 As Label = New Label
frm2.Label27.Text = TextBox7.Text
frm2.Label27.ForeColor = Color.Black
Dim Label28 As Label = New Label
frm2.Label28.Text = TextBox8.Text
frm2.Label28.ForeColor = Color.Black
Dim Label29 As Label = New Label
frm2.Label29.Text = TextBox9.Text
frm2.Label29.ForeColor = Color.Black
Dim Label30 As Label = New Label
frm2.Label30.Text = TextBox10.Text
frm2.Label30.ForeColor = Color.Black
Dim Label31 As Label = New Label
frm2.Label31.Text = TextBox11.Text
frm2.Label31.ForeColor = Color.Black
Dim Label32 As Label = New Label
frm2.Label32.Text = TextBox12.Text
frm2.Label32.ForeColor = Color.Black
Dim Label33 As Label = New Label
frm2.Label33.Text = TextBox13.Text
frm2.Label33.ForeColor = Color.Black
Dim Label34 As Label = New Label
frm2.Label34.Text = TextBox14.Text
frm2.Label34.ForeColor = Color.Black
Dim Label35 As Label = New Label
frm2.Label35.Text = TextBox15.Text
frm2.Label35.ForeColor = Color.Black
Dim Label36 As Label = New Label
frm2.Label36.Text = TextBox16.Text
frm2.Label36.ForeColor = Color.Black
Dim Label37 As Label = New Label
frm2.Label37.Text = TextBox17.Text
frm2.Label37.ForeColor = Color.Black
Dim Label38 As Label = New Label
frm2.Label38.Text = TextBox18.Text
frm2.Label38.ForeColor = Color.Black
Dim Label39 As Label = New Label
frm2.Label39.Text = TextBox19.Text
frm2.Label39.ForeColor = Color.Black
Dim Label40 As Label = New Label
frm2.Label40.Text = TextBox20.Text
frm2.Label40.ForeColor = Color.Black
End If
If frm2 IsNot Nothing Then
frm2.Show(Me) 'Show Second Form
Me.Hide()
End If
End Sub
Sub Form2HasBeenClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
frm2 = Nothing
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Form 3 Code:(instance calling to form1)
Public Class Form3
Private frm3 As Form3
Private frm1 As Form1
Private frm4 As Form4
Public Sub New1(ByVal callerInstance As Form1)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm1 = callerInstance
End Sub
End Class

If you want show in label number of right answers then
You need compare all user answers with right answers
And count times when answers are same:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm4 = New Form4()
frm1 = New Form1()
Dim Textbox1 As New TextBox
Dim Label3 As New Label
Dim sameQnt As Int32 = 0
If Textbox1.Text = frm1.TextBox2.Text Then sameQnt += 1
If Textbox2.Text = frm1.TextBox4.Text Then sameQnt += 1
If Textbox3.Text = frm1.TextBox6.Text Then sameQnt += 1
If Textbox4.Text = frm1.TextBox8.Text Then sameQnt += 1
If Textbox5.Text = frm1.TextBox10.Text Then sameQnt += 1
If Textbox6.Text = frm1.TextBox12.Text Then sameQnt += 1
If Textbox7.Text = frm1.TextBox14.Text Then sameQnt += 1
If Textbox8.Text = frm1.TextBox16.Text Then sameQnt += 1
If Textbox9.Text = frm1.TextBox18.Text Then sameQnt += 1
If Textbox10.Text = frm1.TextBox20.Text Then sameQnt += 1
'Print reslut
frm4.Label3.Text = sameQnt.ToString()
frm4.Show()
End Sub

Here is my new answer
Public Class MainForm '<----Your main form class name
Dim frm4 = New Form4()'<----declare it here
Dim frm1 = New Form1()'<----declare it here
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Textbox1 As New TextBox
Dim Label3 As New Label
Dim i As Integer = 0
If Textbox1.Text = frm1.TextBox2.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox2.Text = frm1.TextBox4.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox3.Text = frm1.TextBox6.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox4.Text = frm1.TextBox8.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox5.Text = frm1.TextBox10.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox6.Text = frm1.TextBox12.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox7.Text = frm1.TextBox14.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox8.Text = frm1.TextBox16.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox9.Text = frm1.TextBox18.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox10.Text = frm1.TextBox20.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
frm4.Label3.Text = i.ToString()
frm4.Show()
End Sub
End Class

Related

VB.NET MouseEventArgs for dynamiclly added controls

I'm currently trying to create a tower building tool, this is based on drag and drop functionality. I'm currently ready for the user to build his tower, but now I would also like to add the option that he can adjust his tower. This by dragging the added blocks so they swap position.
I'm currently using the flowlayoutpanel to arrange my added block's (groupboxes). These are newly created after each dragevent based on the input.
Public Class Form1
Private Sub BODY_ADD_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles _
BODY_ADD_CILINDER.MouseMove,
BODY_ADD_CONE_DOWN.MouseMove,
BODY_ADD_CONE_UP.MouseMove,
BODY_ADD_HEAD_DOWN.MouseMove,
BODY_ADD_HEAD_UP.MouseMove
' Initiate dragging.
Me.DoDragDrop(sender, DragDropEffects.Copy)
End Sub
Private Sub BODY_Arrange_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles _
BODY_LAYOUT_PANEL.MouseMove
' Initiate dragging.
Me.DoDragDrop(sender, DragDropEffects.Copy)
End Sub
Private Sub FlowLayoutPanel1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles BODY_LAYOUT_PANEL.DragEnter
' Check the format of the data being dropped.
If (e.Data.GetDataPresent(GetType(PictureBox))) Then
' Display the copy cursor.
e.Effect = DragDropEffects.Copy
Else
' Display the no-drop cursor.
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub BODY_LAYOUT_PANEL_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles BODY_LAYOUT_PANEL.DragDrop
Dim oPB = e.Data.GetData(GetType(PictureBox))
Dim oGB As New GroupBox
oGB.Name = "Test" & GET_BODY_ITEM_NO()
oGB.Visible = True
oGB.Width = 520
oGB.Height = 119
If oPB.name = BODY_ADD_CILINDER.Name Then
oGB.Text = "Cilinder" & GET_CILINDER_ITEM_NO()
BODY_LAYOUT_PANEL.Controls.Add(oGB)
FILL_CILINDER_GROUP_BOX(oGB)
ElseIf oPB.name = BODY_ADD_CONE_DOWN.Name Then
oGB.Text = "Cone down" & GET_BODY_ITEM_NO()
BODY_LAYOUT_PANEL.Controls.Add(oGB)
ElseIf oPB.name = BODY_ADD_CONE_UP.Name Then
oGB.Text = "Cone up" & GET_BODY_ITEM_NO()
BODY_LAYOUT_PANEL.Controls.Add(oGB)
ElseIf oPB.name = BODY_ADD_HEAD_DOWN.Name Then
oGB.Text = "Head down" & GET_HEAD_DOWN_ITEM_NO()
BODY_LAYOUT_PANEL.Controls.Add(oGB)
ElseIf oPB.name = BODY_ADD_HEAD_UP.Name Then
oGB.Text = "Head up" & GET_BODY_ITEM_NO()
BODY_LAYOUT_PANEL.Controls.Add(oGB)
End If
End Sub
Private Sub FILL_CILINDER_GROUP_BOX(ByVal oGB As GroupBox)
Dim oPB As New PictureBox
oPB.Dock = DockStyle.Left
oPB.SizeMode = PictureBoxSizeMode.StretchImage
oPB.Image = My.Resources.ResourceManager.GetObject("Cilinder")
oPB.Name = oGB.Name & "_PictureBox"
oGB.Controls.Add(oPB)
Dim oLBL1 As New Label
oLBL1.Name = oGB.Name & "_LABEL_HOOGTE"
oLBL1.Text = "Hoogte"
oLBL1.Location = New System.Drawing.Point(128, 25)
oLBL1.Width = 42
oGB.Controls.Add(oLBL1)
Dim oLBL2 As New Label
oLBL2.Name = oGB.Name & "_LABEL_DIKTE"
oLBL2.Text = "Dikte"
oLBL2.Location = New System.Drawing.Point(138, 52)
oLBL2.Width = 32
oGB.Controls.Add(oLBL2)
Dim oLBL3 As New Label
oLBL3.Name = oGB.Name & "_LABEL_ORIENTATIE"
oLBL3.Text = "Orientatie LW"
oLBL3.Location = New System.Drawing.Point(311, 25)
oLBL3.Width = 72
oGB.Controls.Add(oLBL3)
Dim oLBL4 As New Label
oLBL4.Name = oGB.Name & "_LABEL_SEGMENTEN"
oLBL4.Text = "Segmenten"
oLBL4.Location = New System.Drawing.Point(322, 52)
oLBL4.Width = 61
oGB.Controls.Add(oLBL4)
Dim oTB1 As New TextBox
oTB1.Name = oGB.Name & "_TB_HOOGTE"
oTB1.Location = New System.Drawing.Point(176, 22)
oGB.Controls.Add(oTB1)
Dim oTB2 As New TextBox
oTB2.Name = oGB.Name & "_TB_DIKTE"
oTB2.Location = New System.Drawing.Point(176, 49)
oGB.Controls.Add(oTB2)
Dim oTB3 As New TextBox
oTB3.Name = oGB.Name & "_TB_ORIENTATIE"
oTB3.Location = New System.Drawing.Point(389, 22)
oGB.Controls.Add(oTB3)
Dim oTB4 As New TextBox
oTB4.Name = oGB.Name & "_TB_SEGMENTEN"
oTB4.Location = New System.Drawing.Point(389, 45)
oGB.Controls.Add(oTB4)
End Sub
Private Function GET_BODY_ITEM_NO()
Return (BODY_LAYOUT_PANEL.Controls.Count)
End Function
Private Function GET_CILINDER_ITEM_NO()
Dim s As String
Dim y As Integer = 1
For i = 0 To BODY_LAYOUT_PANEL.Controls.Count - 1
s = BODY_LAYOUT_PANEL.Controls.Item(i).Text
If s.Contains("Cilinder") Then
y = y + 1
End If
Next
Return (y)
End Function
Private Function GET_HEAD_DOWN_ITEM_NO()
Dim s As String
Dim y As Integer = 1
For i = 0 To BODY_LAYOUT_PANEL.Controls.Count - 1
s = BODY_LAYOUT_PANEL.Controls.Item(i).Text
If s.Contains("Head down") Then
y = y + 1
End If
Next
Return (y)
End Function
End Class
For the rearranging part I would have to create a drag-event for the dynamically added groupboxes. How do you write this? How should I specify what to handle?
So the Question is: How do I hook the mouse-event to the dynamically added group-box control?
Private Sub BODY_REARRANGE_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles
Also if there are any comments on my sample code I could use some pointers!

how to create a vertical marquee in vb.net

i have created a label within a panel and want to move it vertically .
moving horizontally works using:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Start()
If lbl1.Location.X + lbl1.Width < 0 Then
lbl1.Location = New Point(Panel5.Width, lbl1.Location.Y)
Else
lbl1.Location = New Point(lbl1.Location.X - 4, lbl1.Location.Y)
End If
End Sub
as u see in the above code (X) and (Y) is used for left and right drawing point. what is the drawing point for top and bottom
Your Horizontal routine:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If lbl1.Location.X + lbl1.Width < 0 Then
lbl1.Location = New Point(Panel5.Width, lbl1.Location.Y)
Else
lbl1.Location = New Point(lbl1.Location.X - 4, lbl1.Location.Y)
End If
End Sub
Converted to a Vertical routine:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If lbl1.Location.Y + lbl1.Height < 0 Then
lbl1.Location = New Point(lbl1.Location.X, Panel5.Height)
Else
lbl1.Location = New Point(lbl1.Location.X, lbl1.Location.Y - 4)
End If
End Sub
take your idea n modify for my own requirement:
Private isFirstTime As Boolean = True
Public Sub RunningText(ByVal lbl As Label, ByVal pnl As Panel, Optional fromRightBottom As Boolean = True, Optional ByVal isHorizontal As Boolean = True)
If isFirstTime Then
If isHorizontal Then
If fromRightBottom Then
lbl.Location = New Point(pnl.Width, lbl.Location.Y)
Else
lbl.Location = New Point(-1 * lbl.Width, lbl.Location.Y)
End If
Else
If fromRightBottom Then
lbl.Location = New Point(lbl.Location.X, pnl.Height)
Else
lbl.Location = New Point(lbl.Location.X, 0)
End If
End If
isFirstTime = False
End If
If isHorizontal Then
If fromRightBottom Then
If lbl.Location.X + lbl.Width < 0 Then
lbl.Location = New Point(pnl.Width, lbl.Location.Y)
Else
lbl.Location = New Point(lbl.Location.X - 4, lbl.Location.Y)
End If
Else
If lbl.Location.X + pnl.Width > lbl.Width + pnl.Width Then
lbl.Location = New Point(-1 * lbl.Width, lbl.Location.Y)
Else
lbl.Location = New Point(lbl.Location.X + 4, lbl.Location.Y)
End If
End If
Else
If fromRightBottom Then
If lbl.Location.Y + lbl.Height < 0 Then
lbl.Location = New Point(lbl.Location.X, pnl.Height)
Else
lbl.Location = New Point(lbl.Location.X, lbl.Location.Y - 4)
End If
Else
If lbl.Location.Y + lbl.Height > lbl.Height + pnl.Height Then
lbl.Location = New Point(lbl.Location.X, 0)
Else
lbl.Location = New Point(lbl.Location.X, lbl.Location.Y + 4)
End If
End If
End If
End Sub

I want to drag an image between two PictureBox controls while moving the Image with the mouse cursor (chess game vb.net)

I know how to do the first part of my question but it doesn't look good in the game when the piece image just disappear off the original board square and then appear on the target square, so I want the piece to remain visible while moving with the mouse movement between the 64's PictureBox controls that I've made as the board squares. Here's my code:
Imports System.Drawing.Text
Imports System.Drawing.Image
Imports System.Drawing.Drawing2D
Public Class frmMain
Dim MovingFinished As Boolean
Dim BlackPiece(5) As Image
Dim WhitePiece(5) As Image
Dim BaseCorX As Integer
Dim BaseCorY As Integer
Dim TargetCorX As Integer
Dim TargetCorY As Integer
Dim BoardSquare As Integer = 65
Dim PieceImg As Image
Dim PicBox As PictureBox
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
BlackPiece(0) = My.Resources.BP
BlackPiece(1) = My.Resources.BR
BlackPiece(2) = My.Resources.BN
BlackPiece(3) = My.Resources.BB
BlackPiece(4) = My.Resources.BQ
BlackPiece(5) = My.Resources.BK
WhitePiece(0) = My.Resources.WP
WhitePiece(1) = My.Resources.WR
WhitePiece(2) = My.Resources.WN
WhitePiece(3) = My.Resources.WB
WhitePiece(4) = My.Resources.WQ
WhitePiece(5) = My.Resources.WK
a1.Image = WhitePiece(1)
b1.Image = WhitePiece(2)
c1.Image = WhitePiece(3)
d1.Image = WhitePiece(4)
e1.Image = WhitePiece(5)
f1.Image = WhitePiece(3)
g1.Image = WhitePiece(2)
h1.Image = WhitePiece(1)
a2.Image = WhitePiece(0)
b2.Image = WhitePiece(0)
c2.Image = WhitePiece(0)
d2.Image = WhitePiece(0)
e2.Image = WhitePiece(0)
f2.Image = WhitePiece(0)
g2.Image = WhitePiece(0)
h2.Image = WhitePiece(0)
a8.Image = BlackPiece(1)
b8.Image = BlackPiece(2)
c8.Image = BlackPiece(3)
d8.Image = BlackPiece(4)
e8.Image = BlackPiece(5)
f8.Image = BlackPiece(3)
g8.Image = BlackPiece(2)
h8.Image = BlackPiece(1)
a7.Image = BlackPiece(0)
b7.Image = BlackPiece(0)
c7.Image = BlackPiece(0)
d7.Image = BlackPiece(0)
e7.Image = BlackPiece(0)
f7.Image = BlackPiece(0)
g7.Image = BlackPiece(0)
h7.Image = BlackPiece(0)
For Each a As Control In Me.Controls
If TypeOf a Is PictureBox Then
AddHandler a.MouseDown, AddressOf PictureBox_MouseDown
AddHandler a.MouseMove, AddressOf PictureBox_MouseMove
AddHandler a.DragEnter, AddressOf PictureBox_DragEnter
AddHandler a.DragDrop, AddressOf PictureBox_DragDrop
a.AllowDrop = True
End If
Next
End Sub
Private Sub PictureBox_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
Dim a As PictureBox = DirectCast(sender, PictureBox)
PieceImg = a.Image
PicBox = a
BaseCorX = a.Location.X
BaseCorY = a.Location.Y
txt1.Text = BaseCorX
txt2.Text = BaseCorY
If Not a.Image Is Nothing Then
MovingFinished = True
TextBox1.Text = MovingFinished
If a.Image Is BlackPiece(0) Then
End If
Else
MovingFinished = False
TextBox1.Text = MovingFinished
End If
End Sub
Private Sub PictureBox_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
If MovingFinished = True Then
'PicBox.Location = New Point(PicBox.Left - (TargetCorX - e.X), PicBox.Top - (TargetCorY - e.Y))
PicBox.DoDragDrop(PieceImg, DragDropEffects.Move)
TextBox2.Text = "tae0"
End If
MovingFinished = False
End Sub
Private Sub PictureBox_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs)
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
e.Effect = DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub PictureBox_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs)
If Not e.KeyState = 8 Then
Dim a As PictureBox = DirectCast(sender, PictureBox)
TargetCorX = a.Location.X
TargetCorY = a.Location.Y
txt1.Text = TargetCorX
txt2.Text = TargetCorY
If Not a Is PicBox Then
If PieceImg Is BlackPiece(0) Then
TextBox2.Text = "pawnBlackPiece"
If BaseCorY - TargetCorY = -BoardSquare And BaseCorX = TargetCorX Then
If a.Image Is Nothing Then
a.Image = e.Data.GetData(DataFormats.Bitmap)
PicBox.Image = Nothing
Else
TextBox2.Text = "There is a piece there"
End If
ElseIf BaseCorY - TargetCorY = -65 And BaseCorX - TargetCorX = -65 Or BaseCorY - TargetCorY = -65 And TargetCorX - BaseCorX = -65 Then
a.Image = e.Data.GetData(DataFormats.Bitmap)
PicBox.Image = Nothing
TextBox2.Text = "good"
End If
ElseIf PieceImg Is BlackPiece(1) Then
a.Image = e.Data.GetData(DataFormats.Bitmap)
PicBox.Image = Nothing
ElseIf PieceImg Is BlackPiece(2) Then
ElseIf PieceImg Is BlackPiece(3) Then
ElseIf PieceImg Is BlackPiece(4) Then
ElseIf PieceImg Is BlackPiece(5) Then
End If
Else
TextBox2.Text = "DO nothing"
End If
End If
End Sub
End Class

Wrong Result to the last form on label always 0

Hi good day guys i would just like to seek some help regarding my problem here in VB.NET. I have this program that if the text in the textbox is equal to the text in the textbox of the previous form it will add 1 for each correct answer but instead it always shows zero (0) (last form) and not showing the results that I want. Here is my code guys I hope you can help me with this problem thanks in advance.
Imports System.Convert
Imports System.IO
Public Class Form3
Private frm1 As Form1
Private frm4 As Form4
Public Sub New1(ByVal callerInstance As Form1)
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm1 = callerInstance
End Sub
Public Sub New2(ByVal callerInstance As Form4)
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm4 = callerInstance
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm1 As Form1 = Form1
Dim frm4 As Form4 = Form4
frm1 = New Form1
frm4 = New Form4
'program execution proper
Dim lbl3 As Integer = CInt(frm4.Label3.Text)
lbl3 = CInt(frm4.Label3.Text)
Dim Label22 As New Label
If frm1.TextBox2.Text = TextBox1.Text Then
lbl3 = CInt(lbl3) + 0 'if(integer.tryparse, lbl3) then lbl3 += 1
Dim Label24 As New Label
If Not frm1.TextBox4.Text = TextBox2.Text Then
lbl3 = CInt(lbl3) + 0
Dim Label26 As New Label
If Not frm1.TextBox6.Text = TextBox3.Text Then
lbl3 = CInt(lbl3) + 0
Dim Label28 As New Label
If Not frm1.TextBox8.Text = TextBox4.Text Then
lbl3 = CInt(lbl3) + 0
Dim Label30 As New Label
If Not frm1.TextBox10.Text = TextBox5.Text Then
lbl3 = CInt(lbl3) + 0
Dim Label32 As New Label
If Not frm1.TextBox12.Text = TextBox6.Text Then
lbl3 = CInt(lbl3) + 0
Dim Label34 As New Label
If Not frm1.TextBox14.Text = TextBox7.Text Then
lbl3 = CInt(lbl3) + 0
Dim Label36 As New Label
If Not frm1.TextBox16.Text = TextBox8.Text Then
lbl3 = CInt(lbl3) + 0
Dim Label38 As New Label
If Not frm1.TextBox18.Text = TextBox9.Text Then
lbl3 = CInt(lbl3) + 0
Dim Label40 As New Label
If Not frm1.TextBox20.Text = TextBox10.Text Then
lbl3 = CInt(lbl3) + 0 'frm4.Label3.Text = (frm4.Label3.Text) + 1
frm4.Show()
Me.Hide()
Else
lbl3 = CInt(lbl3) + 1
frm4.Show()
Me.Hide()
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
If frm4 IsNot Nothing Then
frm4.Visible = False
frm4.Show(Me) 'Show Second Form
Me.Hide()
End If
End Sub
End Class
The only time you add anything to Lbl3 is:
If Not frm1.TextBox20.Text = TextBox10.Text Then
lbl3 = CInt(lbl3) + 0 'frm4.Label3.Text = (frm4.Label3.Text) + 1
frm4.Show()
Me.Hide()
Else
lbl3 = CInt(lbl3) + 1
frm4.Show()
Me.Hide()
End If
With the nesting you have it is only if all the other If statements = True that you even get to this point.
In addition to this on ALL the other if statement your outcome is either lbl3 = CInt(lbl3) + 0 (if this statement and all previous ones were true) or if any of them are false ALL subsequent ones are irrelevant.
If i understand your intention correctly then what you want is instead of:
If frm1.TextBox2.Text = TextBox1.Text Then
lbl3 = CInt(lbl3) + 0 'if(integer.tryparse, lbl3) then lbl3 += 1
Dim Label24 As New Label
If Not frm1.TextBox4.Text = TextBox2.Text Then
lbl3 = CInt(lbl3) + 0
Try:
If frm1.TextBox2.Text = TextBox1.Text Then lbl3 += 1
If Not frm1.TextBox4.Text = TextBox2.Text Then lbl3 += 1
And so on....
Then to display it you need to update the following code:
If Not frm1.TextBox20.Text = TextBox10.Text Then
lbl3 = CInt(lbl3) + 0 'frm4.Label3.Text = (frm4.Label3.Text) + 1
frm4.Label3.Text = CStr(lbl3)
frm4.Show()
Me.Hide()
Else
lbl3 = CInt(lbl3) + 1
frm4.Label3.Text = CStr(lbl3)
frm4.Show()
Me.Hide()
End If
(this is very similar to one of the answers on one of the other questions hence my comment above)
Add setting code.
frm4.Label3.Text = lbl3.ToString()

VB.Net Cannot grab the values on the first form

I would just like to ask for your help regarding my project as you can see it has a caller instance the other form also has it and it is working (without mathematical operation) but on this form which is form3 which I need a +1 on frm4.label it does not work. (I named it Public Sub New1) Error 1 Too many arguments to 'Public Sub New()(Note: i have another callerinstance on the previous form which is form2 which is named Public SubNew()) and when it run instead of getting the right results the label always shows the text of 0
Please help me thanks in advance happy coding to all :)
Public Class Form3
Private frm3 As Form3
Private frm1 As Form1
Private frm4 As Form4
Public Sub New1(ByVal Name As String, ByVal Bread As String, ByVal Cheese As String, ByVal Condiments As String, ByVal Meat As String, ByVal Cost As Decimal, ByVal Quantity As Decimal, ByVal callerInstance As Form1)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm1 = callerInstance
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm1 = New Form1(Me)
frm4 = New Form4()
If frm4 Is Nothing Then
frm4 = New Form4
AddHandler frm4.FormClosed, AddressOf Me.Form4HasBeenClosed
Dim i As Integer = 0
i = frm4.Label3.Text
If TextBox1.Text = frm1.TextBox2.Text Then
i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
ElseIf TextBox2.Text = frm1.TextBox4.Text Then
i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
ElseIf TextBox3.Text = frm1.TextBox6.Text Then
i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
ElseIf TextBox4.Text = frm1.TextBox8.Text Then
i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
ElseIf TextBox5.Text = frm1.TextBox10.Text Then
i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
ElseIf TextBox6.Text = frm1.TextBox12.Text Then
i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
ElseIf TextBox7.Text = frm1.TextBox14.Text Then
i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
ElseIf TextBox8.Text = frm1.TextBox16.Text Then
i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
ElseIf TextBox9.Text = frm1.TextBox18.Text Then
i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
ElseIf TextBox10.Text = frm1.TextBox20.Text Then
i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
frm4.Label3.Text = i.ToString()
frm4.Show()
Else
i += 0
frm4.Show()
End If
End If
If frm4 IsNot Nothing Then
frm4.Show(Me) 'Show Second Form
Me.Hide()
End If
End Sub
Sub Form4HasBeenClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
frm4 = Nothing
End Sub
End Class
Based on the comments it sounds like the error is on this line
frm1 = new Form1(Me)
If that is the case it means that there is no Sub New method on Form1 which accepts a parameter of type Form3. To fix this you need to add one
Public Class Form1
...
Public Sub New(ByVal frm3 As Form3)
End Sub
End Class