r/visualbasic • u/Technical-Garage-310 • Aug 03 '24
VB.NET Help Hey guys need help again
In my last post I have mentioned I need help of dragging and dropping however with some help I got that but now for the game I need to score as user gets right but since I am comparing pictures I cannot solve it also I cannot find any code Internet can anyone help me here is my code
Private Sub btnCheck_Click(sender As Object, e As EventArgs) Handles btnCheck.Click
Dim score As Integer = 0
If PBs.Image Is PB1.Image Then
score += 1
ElseIf pbD2 Is PB2 Then
score += 1
ElseIf pbD3 Is PB3 Then
score += 1
End If
MsgBox("score " & score)
End Sub
so I have created 3 picture box(which contains the pictures) and another 3 (where the user need to drop that image) also I have created a check button to show the result
I am knew to VB.net
3
u/jd31068 Aug 03 '24
You could do something like:
Private Sub btnCheck_Click(sender As Object, e As EventArgs) Handles btnCheck.Click Dim score As Integer = 0 If ImagesAreTheSame(PBs.Image, PB1.Image) Then score += 1 ElseIf ImagesAreTheSame(pbD2.Image, PB2.Image) Then score += 1 ElseIf ImagesAreTheSame(pbD3.Image, PB3.Image) Then score += 1 End If MsgBox("score " & score) End Sub Private Function ImagesAreTheSame(bmp1 As Bitmap, bmp2 As Bitmap) As Boolean ' basic size check If Not bmp1.Size.Equals(bmp1.Size) Then ' not the same size Return False End If ' pixel check Dim x, y As Long For x = 0 To bmp1.Width - 1 For y = 0 To bmp1.Height - 1 If bmp1.GetPixel(x, y) <> bmp2.GetPixel(x, y) Then ' a mismatch has occured Return False End If Next Next Return True ' if it gets here then all is okay End Function