Converted test code generates an error (C# to VB.Net) - vb.net

I have converted a C# code to VB.net and have applied the small adjustments required.
But when I test the code, it generates an error at the point where these instructions are:
If Not capture.Cued Then
capture.Filename = counter & ".wmv"
I am no expert in DirectShow and I need that code to continue learning. Please Could anyone give me their generous help?
I would appreciate any help. Thank you.
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports DirectX.Capture
Imports DShowNET
Public Class MyWebCam
Inherits Form
' Muaz Khan (#muazkh) - http://muaz-khan.blogspot.com
Private capture As Capture = Nothing
Private filters As Filters = Nothing
Private counter As Integer = 1
Private timer As New Timer()
Private deviceNumber As Integer = 0
Public Sub New()
InitializeComponent()
End Sub
'============================================================================
Private Sub Form1_Shown(sender As Object, e As EventArgs)
filters = New Filters()
If filters.VideoInputDevices IsNot Nothing Then
Try
preview(deviceNumber)
Catch ex As Exception
MessageBox.Show("Maybe any other software is already using your WebCam." & vbLf & vbLf & " Error Message: " & vbLf & vbLf & ex.Message)
End Try
Else
btnStartVideoCapture.Enabled = False
MessageBox.Show("No video device connected to your PC!")
End If
timer.Interval = 600000
' 10 minutes!
AddHandler timer.Tick, Function(obj, evt)
If btnStartVideoCapture.Text = "STOP" Then
counter += 1
If capture IsNot Nothing AndAlso counter > 1 Then
capture.[Stop]()
If Not capture.Cued Then
capture.Filename = counter & ".wmv"
End If
capture.Cue()
capture.Start()
End If
End If
End Function
If filters.VideoInputDevices IsNot Nothing Then
For i = 0 To filters.VideoInputDevices.Count - 1
Dim device = filters.VideoInputDevices(i)
Dim btn = New Button()
btn.Text = i.ToString()
btn.ForeColor = Color.White
btn.BackColor = Color.DarkSlateBlue
btn.Width = 25
AddHandler btn.Click, Function(obj, evt)
Dim thisButton = DirectCast(obj, Button)
If Integer.Parse(thisButton.Text) <> deviceNumber Then
If capture IsNot Nothing Then
capture.Dispose()
capture.[Stop]()
capture.PreviewWindow = Nothing
End If
deviceNumber = Integer.Parse(thisButton.Text)
preview(deviceNumber)
End If
End Function
FlowLayoutPanel1.Controls.Add(btn)
Next
End If
End Sub
'============================================================================
Private Sub preview(deviceNo As Integer)
Try
' MessageBox.Show("deviceNo = > " + deviceNo);
capture = New Capture(filters.VideoInputDevices(deviceNo), filters.AudioInputDevices(0))
capture.PreviewWindow = Panel1
If btnStartVideoCapture.Text = "STOP" Then
counter += 1
If Not capture.Cued Then
capture.Filename = counter & ".wmv"
End If
capture.Cue()
End If
capture.Start()
Catch
End Try
End Sub
'============================================================================
Private Sub btnStartVideoCapture_Click(sender As System.Object, e As System.EventArgs) Handles btnStartVideoCapture.Click
startOrStopCapturing(capture)
End Sub
'============================================================================
Private Sub startOrStopCapturing(capture As Capture)
btnStartVideoCapture.Visible = False
'**** THE ERROR BEGINS TO APPEAR HERE ************
'****
'****
If capture IsNot Nothing Then
capture.[Stop]()
End If
If timer.Enabled Then
timer.[Stop]()
End If
If btnStartVideoCapture.Text = "START" Then
btnStartVideoCapture.Text = "STOP"
btnStartVideoCapture.BackColor = Color.Maroon
Try
If Not capture.Cued Then
capture.Filename = counter & ".wmv"
End If
capture.Cue()
capture.Start()
timer.Start()
Catch ex As Exception
MessageBox.Show("Error Message: " & vbLf & vbLf & ex.Message)
End Try
Else
btnStartVideoCapture.Text = "START"
btnStartVideoCapture.BackColor = Color.DarkSlateBlue
End If
btnStartVideoCapture.Visible = True
End Sub
'============================================================================
Private Sub InitializeComponent()
Me.btnStartVideoCapture = New System.Windows.Forms.Button()
Me.FlowLayoutPanel1 = New System.Windows.Forms.FlowLayoutPanel()
Me.Panel1 = New System.Windows.Forms.Panel()
Me.SuspendLayout()
'
'btnStartVideoCapture
'
Me.btnStartVideoCapture.BackColor = System.Drawing.Color.DarkSlateBlue
Me.btnStartVideoCapture.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnStartVideoCapture.ForeColor = System.Drawing.Color.White
Me.btnStartVideoCapture.Location = New System.Drawing.Point(498, 421)
Me.btnStartVideoCapture.Name = "btnStartVideoCapture"
Me.btnStartVideoCapture.Size = New System.Drawing.Size(89, 38)
Me.btnStartVideoCapture.TabIndex = 2
Me.btnStartVideoCapture.Text = "START"
Me.btnStartVideoCapture.UseVisualStyleBackColor = False
'
'FlowLayoutPanel1
'
Me.FlowLayoutPanel1.Location = New System.Drawing.Point(0, 421)
Me.FlowLayoutPanel1.Name = "FlowLayoutPanel1"
Me.FlowLayoutPanel1.Size = New System.Drawing.Size(502, 38)
Me.FlowLayoutPanel1.TabIndex = 3
'
'Panel1
'
Me.Panel1.Location = New System.Drawing.Point(0, -3)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(587, 418)
Me.Panel1.TabIndex = 4
'
'Form1
'
Me.BackColor = System.Drawing.Color.Black
Me.ClientSize = New System.Drawing.Size(585, 458)
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.FlowLayoutPanel1)
Me.Controls.Add(Me.btnStartVideoCapture)
Me.Name = "Form1"
Me.ResumeLayout(False)
End Sub
Private WithEvents btnStartVideoCapture As System.Windows.Forms.Button
Friend WithEvents FlowLayoutPanel1 As System.Windows.Forms.FlowLayoutPanel
Friend WithEvents Panel1 As System.Windows.Forms.Panel
End Class

In the startStopCapturing you dont't check if the capture IsNothing. The capture object is initialized when you enter the preview method at the form Shown event or at the timer event.
Everywhere you have code in place that checks the capture object for IsNothing and to avoid using it but, in startStopCapturing, you don't have this check to protect the code in the IF that change the button text.
Private Sub startOrStopCapturing(capture As Capture)
btnStartVideoCapture.Visible = False
If capture IsNot Nothing Then
capture.[Stop]()
capture.Dispose()
capture = Nothing
If timer.Enabled Then
timer.[Stop]()
End If
btnStartVideoCapture.Text = "START"
btnStartVideoCapture.BackColor = Color.DarkSlateBlue
Else
Try
capture = New Capture(filters.VideoInputDevices(deviceNumber), _
filters.AudioInputDevices(0))
capture.Filename = counter & ".wmv"
capture.Cue()
capture.Start()
timer.Start()
btnStartVideoCapture.Text = "STOP"
btnStartVideoCapture.BackColor = Color.Maroon
Catch ex As Exception
MessageBox.Show("Error Message: " & vbLf & vbLf & ex.Message)
End Try
End If
btnStartVideoCapture.Visible = True
End Sub
Also this code in the inline button_click event seems to be wrong
If capture IsNot Nothing Then
capture.Dispose()
capture.[Stop]()
capture.PreviewWindow = Nothing
End iF
Do not use a disposed object and set it to Nothing because without that you could fool again your code in belivieng that the capture object is valid
If capture IsNot Nothing Then
capture.[Stop]()
capture.PreviewWindow = Nothing
capture.Dispose()
capture = Nothing
End iF

Related

How to show MsgBox after finishing unzip process

I have this code:
Private Sub KickoffExtract()
actionStatus.Text = "Se instaleaza actualizarea.. va rugam asteptati."
lblProgress.Text = "Se extrage..."
Dim args(2) As String
args(0) = GetSettingItem("./updUrl.info", "UPDATE_FILENAME")
args(1) = extractPath
_backgroundWorker1 = New System.ComponentModel.BackgroundWorker()
_backgroundWorker1.WorkerSupportsCancellation = False
_backgroundWorker1.WorkerReportsProgress = False
AddHandler Me._backgroundWorker1.DoWork, New DoWorkEventHandler(AddressOf Me.UnzipFile)
_backgroundWorker1.RunWorkerAsync(args)
End Sub
Private Sub UnzipFile(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim extractCancelled As Boolean = False
Dim args() As String = e.Argument
Dim zipToRead As String = args(0)
Dim extractDir As String = args(1)
Try
Using zip As ZipFile = ZipFile.Read(zipToRead)
totalEntriesToProcess = zip.Entries.Count
SetProgressBarMax(zip.Entries.Count)
AddHandler zip.ExtractProgress, New EventHandler(Of ExtractProgressEventArgs)(AddressOf Me.zip_ExtractProgress)
zip.ExtractAll(extractDir, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently)
End Using
Catch ex1 As Exception
MessageBox.Show(String.Format("Actualizatorul a intampinat o problema in extragerea pachetului. {0}", ex1.Message), "Error Extracting", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
End Try
End Sub
Private Sub SetProgressBarMax(ByVal n As Integer)
If ProgBar.InvokeRequired Then
ProgBar.Invoke(New Action(Of Integer)(AddressOf SetProgressBarMax), New Object() {n})
Else
ProgBar.Value = 0
ProgBar.Maximum = n
ProgBar.Step = 1
End If
End Sub
Private Sub zip_ExtractProgress(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
If _operationCanceled Then
e.Cancel = True
Return
End If
If (e.EventType = Ionic.Zip.ZipProgressEventType.Extracting_AfterExtractEntry) Then
StepEntryProgress(e)
ElseIf (e.EventType = ZipProgressEventType.Extracting_BeforeExtractAll) Then
End If
End Sub
Private Sub StepEntryProgress(ByVal e As ExtractProgressEventArgs)
If ProgBar.InvokeRequired Then
ProgBar.Invoke(New ZipProgress(AddressOf StepEntryProgress), New Object() {e})
Else
ProgBar.PerformStep()
System.Threading.Thread.Sleep(100)
nFilesCompleted = nFilesCompleted + 1
lblProgress.Text = String.Format("{0} din {1} fisiere...({2})", nFilesCompleted, totalEntriesToProcess, e.CurrentEntry.FileName)
Me.Update()
End If
End Sub
and this code on a button:
If Not File.Exists("./" + GetSettingItem("./updUrl.info", "UPDATE_FILENAME")) Then
MessageBox.Show("Actualizarea nu s-a descarcat corespunzator.", "Nu se poate extrage", MessageBoxButtons.OK)
End If
If Not String.IsNullOrEmpty("./" + GetSettingItem("./updUrl.info", "UPDATE_FILENAME")) And
Not String.IsNullOrEmpty(extractPath) Then
If Not Directory.Exists(extractPath) Then
Directory.CreateDirectory(extractPath)
End If
nFilesCompleted = 0
_operationCanceled = False
btnUnzip.Enabled = False
KickoffExtract()
End If
How can I show a message after completing the UnZip process? I tried
If ProgBar.Maximum Then
MsgBox("finish")
End If
but it doesn't work. I'm using dotnetzip 1.9, and the most of the code is from UnZip example.
If you check the documentation of BackgroundWorker you will notice that there are two events that can be linked to an event handler in your code.
One of them is the RunWorkerCompleted and in the MSDN page they say
Occurs when the background operation has completed, has been canceled,
or has raised an exception.
So, it is just a matter to write an event handler and bind the event.
AddHandler Me._backgroundWorker1.RunWorkerCompleted, New RunWorkerCompletedEventHandler(AddressOf Me.UnzipComplete)
and then
Private Sub UnzipComplete(ByVal sender As System.Object, _
ByVal e As RunWorkerCompletedEventArgs)
If e.Cancelled = True Then
MessageBox.Show("Canceled!")
ElseIf e.Error IsNot Nothing Then
MessageBox.Show("Error: " & e.Error.Message)
Else
MessageBox.Show("Unzip Completed!")
End If
End Sub

Picturebox Not functioning according to its purpose in VB.Net

I am really puzzled about my program right now because it acts really different according to its purpose what I am trying to do is that I if the text in textbox in the previous form is the same as the text in the textbox on the next form it will show picture1 which is a checkmark otherwise it will show the picture2 which is a crossmark but what happens is instead it will act correctly if one of the text is empty or null but if all textboxes has a value whether the texts on the texboxes satisfies the statement it will always show the picture2 which is a crossmark. I hope you can help me.Thanks in advance.
Imports System.Convert
Imports System.IO
Imports System.Windows.Forms.PictureBox
Imports System.Drawing.Image
Public Class Form4
Inherits System.Windows.Forms.Form
Private frm1 As Form1
Private frm2 As Form2
Public frm3 As Form3
Private frm4 As Form4
Private frm5 As Form5
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lbl3 As Integer
lbl3 = CInt(lbl3)
Me.Visible = False
End Sub
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
Public Sub New5(ByVal callerInstance As Form2)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm2 = callerInstance
End Sub
Public Sub New4(ByVal callerInstance As Form3)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm3 = callerInstance
End Sub
Public Sub New3(ByVal callerInstance As Form4)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm4 = callerInstance
End Sub
Public Sub New5(ByVal callerInstance As Form5)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm5 = 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 frm2 As Form2 = Form2
Dim frm3 As Form3 = Form3
Dim frm5 As Form5 = Form5
frm5.Label21.Text = frm1.TextBox1.Text
frm5.Label21.ForeColor = Color.Black
frm5.Label22.Text = frm1.TextBox2.Text
frm5.Label22.ForeColor = Color.Black
frm5.Label23.Text = frm1.TextBox3.Text
frm5.Label23.ForeColor = Color.Black
frm5.Label24.Text = frm1.TextBox4.Text
frm5.Label24.ForeColor = Color.Black
frm5.Label25.Text = frm1.TextBox5.Text
frm5.Label25.ForeColor = Color.Black
frm5.Label26.Text = frm1.TextBox6.Text
frm5.Label26.ForeColor = Color.Black
frm5.Label27.Text = frm1.TextBox7.Text
frm5.Label27.ForeColor = Color.Black
frm2.Label28.Text = frm1.TextBox8.Text
frm2.Label28.ForeColor = Color.Black
frm5.Label29.Text = frm1.TextBox9.Text
frm5.Label29.ForeColor = Color.Black
frm5.Label30.Text = frm1.TextBox10.Text
frm5.Label30.ForeColor = Color.Black
frm5.Label31.Text = frm1.TextBox11.Text
frm5.Label31.ForeColor = Color.Black
frm5.Label32.Text = frm1.TextBox12.Text
frm5.Label32.ForeColor = Color.Black
frm5.Label33.Text = frm1.TextBox13.Text
frm5.Label33.ForeColor = Color.Black
frm5.Label34.Text = frm1.TextBox14.Text
frm5.Label34.ForeColor = Color.Black
frm5.Label35.Text = frm1.TextBox15.Text
frm5.Label35.ForeColor = Color.Black
frm5.Label36.Text = frm1.TextBox16.Text
frm5.Label36.ForeColor = Color.Black
frm5.Label37.Text = frm1.TextBox17.Text
frm5.Label37.ForeColor = Color.Black
frm5.Label38.Text = frm1.TextBox18.Text
frm5.Label38.ForeColor = Color.Black
frm5.Label39.Text = frm1.TextBox19.Text
frm5.Label39.ForeColor = Color.Black
frm5.Label40.Text = frm1.TextBox20.Text
frm5.Label40.ForeColor = Color.Black
Dim tb1 As TextBox = frm3.TextBox1
Dim tb2 As TextBox = frm3.TextBox2
Dim tb3 As TextBox = frm3.TextBox3
Dim tb4 As TextBox = frm3.TextBox4
Dim tb5 As TextBox = frm3.TextBox5
Dim tb6 As TextBox = frm3.TextBox6
Dim tb7 As TextBox = frm3.TextBox7
Dim tb8 As TextBox = frm3.TextBox8
Dim tb9 As TextBox = frm3.TextBox9
Dim tb10 As TextBox = frm3.TextBox10
If tb1.Text IsNot Nothing Then
If (frm1.TextBox2.Text.Equals(tb1.Text)) And frm1.TextBox2.Text = tb1.Text Then
frm5.PictureBox1.Image = Image.FromFile("D:\checkmark.jpg")
Else
frm5.PictureBox1.Image = Image.FromFile("D:\crossmark.jpg")
End If
Else
frm5.PictureBox1.Image = Image.FromFile("D:\crossmark.jpg")
End If
If tb2.Text IsNot Nothing Then
If (frm1.TextBox4.Text.Equals(tb2.Text)) And frm1.TextBox4.Text = tb2.Text Then
frm5.PictureBox2.Image = Image.FromFile("D:\checkmark.jpg")
Else
frm5.PictureBox2.Image = Image.FromFile("D:\crossmark.jpg")
End If
Else
frm5.PictureBox1.Image = Image.FromFile("D:\crossmark.jpg")
End If
If tb3.Text IsNot Nothing Then
If (frm1.TextBox6.Text.Equals(tb3.Text)) And frm1.TextBox6.Text = tb3.Text Then
frm5.PictureBox3.Image = Image.FromFile("D:\checkmark.jpg")
Else
frm5.PictureBox3.Image = Image.FromFile("D:\crossmark.jpg")
End If
Else
frm5.PictureBox3.Image = Image.FromFile("D:\crossmark.jpg")
End If
If tb4.Text IsNot Nothing Then
If (frm1.TextBox8.Text.Equals(tb4.Text)) And frm1.TextBox8.Text = tb4.Text Then
frm5.PictureBox4.Image = Image.FromFile("D:\checkmark.jpg")
Else
frm5.PictureBox4.Image = Image.FromFile("D:\crossmark.jpg")
End If
Else
frm5.PictureBox3.Image = Image.FromFile("D:\crossmark.jpg")
End If
If tb5.Text IsNot Nothing Then
If (frm1.TextBox10.Text.Equals(tb5.Text)) And frm1.TextBox10.Text = tb5.Text Then
frm5.PictureBox5.Image = Image.FromFile("D:\checkmark.jpg")
Else
frm5.PictureBox5.Image = Image.FromFile("D:\crossmark.jpg")
End If
Else
frm5.PictureBox3.Image = Image.FromFile("D:\crossmark.jpg")
End If
If tb6.Text IsNot Nothing Then
If (frm1.TextBox12.Text.Equals(tb6.Text)) And frm1.TextBox12.Text = tb6.Text Then
frm5.PictureBox6.Image = Image.FromFile("D:\checkmark.jpg")
Else
frm5.PictureBox6.Image = Image.FromFile("D:\crossmark.jpg")
End If
Else
frm5.PictureBox3.Image = Image.FromFile("D:\crossmark.jpg")
End If
If tb7.Text IsNot Nothing Then
If (frm1.TextBox14.Text.Equals(tb7.Text)) And frm1.TextBox14.Text = tb7.Text Then
frm5.PictureBox7.Image = Image.FromFile("D:\checkmark.jpg")
Else
frm5.PictureBox7.Image = Image.FromFile("D:\crossmark.jpg")
End If
Else
frm5.PictureBox3.Image = Image.FromFile("D:\crossmark.jpg")
End If
If tb8.Text IsNot Nothing Then
If (frm1.TextBox16.Text.Equals(tb8.Text)) And frm1.TextBox16.Text = tb8.Text Then
frm5.PictureBox8.Image = Image.FromFile("D:\checkmark.jpg")
Else
frm5.PictureBox8.Image = Image.FromFile("D:\crossmark.jpg")
End If
Else
frm5.PictureBox3.Image = Image.FromFile("D:\crossmark.jpg")
End If
If tb9.Text IsNot Nothing Then
If (frm1.TextBox18.Text.Equals(tb9.Text)) And frm1.TextBox18.Text = tb9.Text Then
frm5.PictureBox9.Image = Image.FromFile("D:\checkmark.jpg")
Else
frm5.PictureBox9.Image = Image.FromFile("D:\crossmark.jpg")
End If
Else
frm5.PictureBox3.Image = Image.FromFile("D:\crossmark.jpg")
End If
If tb10.Text IsNot Nothing Then
If (frm1.TextBox20.Text.Equals(tb10.Text)) And frm1.TextBox20.Text = tb10.Text Then
frm5.PictureBox10.Image = Image.FromFile("D:\checkmark.jpg")
Else
frm5.PictureBox10.Image = Image.FromFile("D:\crossmark.jpg")
End If
Else
frm5.PictureBox10.Image = Image.FromFile("D:\crossmark.jpg")
End If
If frm5 IsNot Nothing Then
frm5.Visible = False
frm5.Show() 'Show Second Form
Me.Hide()
End If
End Sub
Private Sub Form5HasBeenClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
Throw New NotImplementedException
End Sub
End Class
I tried you're code and to make it work I needed to change a few things.
1e change If tb1.Text IsNot Nothing Then to:
If Not tb1.Text = "" Then" "Otherwise the else didn't work if I erased the textbox"
2e I needed to change frm1 to Form1 and frm5 to Form5"It gave me errors"
3e if you use If (frm1.TextBox2.Text.Equals(tb1.Text)) And frm1.TextBox2.Text = tb1.Text Then
"aren't you checking 2 times for the same ?"
so change it to:
If (Form1.TextBox2.Text.Equals(tb1.Text)) Then
Then the code works and does what it needs to do.
If Not tb1.Text = "" Then
If (Form1.TextBox2.Text.Equals(tb1.Text)) Then
Form5.PictureBox1.Image = Image.FromFile("D:\checkmark.jpg")
Else
Form5.PictureBox1.Image = Image.FromFile("D:\crossmark.jpg")
End If
Else
Form5.PictureBox1.Image = Image.FromFile("D:\crossmark.jpg")
End If

Weird Picturebox Behavior

I have this program that i have 10 pictureboxes if the textbox of form1 is the same as the text in the textbox of form3 it will show the picture of a check mark otherwise it will show the picture of a crossmark..But when I typed in the answers when it shows the result it only shows one picturebox and one picturebox and always shows a checkmark which is not doing the purpose of the program and the other nine pictureboxes were missing.. (I already checked the pictureboxes and it the enabled and visible properties were all set to TRUE) Thanks in advance guys I hope you can help me with this problem.
Imports System.Convert
Imports System.IO
Imports System.Windows.Forms.PictureBox
Imports System.Drawing.Image
Public Class Form4
Inherits System.Windows.Forms.Form
Public frm1 As Form1
Private frm2 As Form2
Public frm3 As Form3
Private frm4 As Form4
Private frm5 As Form5
Private Form5 As Form5
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lbl3 As Integer
lbl3 = CInt(lbl3)
Me.Visible = False
End Sub
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
Public Sub New5(ByVal callerInstance As Form2)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm2 = callerInstance
End Sub
Public Sub New4(ByVal callerInstance As Form3)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm3 = callerInstance
End Sub
Public Sub New3(ByVal callerInstance As Form4)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm4 = callerInstance
End Sub
Public Sub New5(ByVal callerInstance As Form5)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm5 = 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 frm2 As Form2 = Form2
Dim frm3 As Form3 = Form3
Dim frm5 As Form5 = Form5
If frm5 Is Nothing Then
frm5 = New Form5(Me)
AddHandler frm2.FormClosed, AddressOf Me.Form5HasBeenClosed
frm5.Label21.Text = frm1.TextBox1.Text
frm5.Label21.ForeColor = Color.Black
frm5.Label22.Text = frm1.TextBox2.Text
frm5.Label22.ForeColor = Color.Black
frm5.Label23.Text = frm1.TextBox3.Text
frm5.Label23.ForeColor = Color.Black
frm5.Label24.Text = frm1.TextBox4.Text
frm5.Label24.ForeColor = Color.Black
frm5.Label25.Text = frm1.TextBox5.Text
frm5.Label25.ForeColor = Color.Black
frm5.Label26.Text = frm1.TextBox6.Text
frm5.Label26.ForeColor = Color.Black
frm5.Label27.Text = frm1.TextBox7.Text
frm5.Label27.ForeColor = Color.Black
frm2.Label28.Text = frm1.TextBox8.Text
frm2.Label28.ForeColor = Color.Black
frm5.Label29.Text = frm1.TextBox9.Text
frm5.Label29.ForeColor = Color.Black
frm5.Label30.Text = frm1.TextBox10.Text
frm5.Label30.ForeColor = Color.Black
frm5.Label31.Text = frm1.TextBox11.Text
frm5.Label31.ForeColor = Color.Black
frm5.Label32.Text = frm1.TextBox12.Text
frm5.Label32.ForeColor = Color.Black
frm5.Label33.Text = frm1.TextBox13.Text
frm5.Label33.ForeColor = Color.Black
frm5.Label34.Text = frm1.TextBox14.Text
frm5.Label34.ForeColor = Color.Black
frm5.Label35.Text = frm1.TextBox15.Text
frm5.Label35.ForeColor = Color.Black
frm5.Label36.Text = frm1.TextBox16.Text
frm5.Label36.ForeColor = Color.Black
frm5.Label37.Text = frm1.TextBox17.Text
frm5.Label37.ForeColor = Color.Black
frm5.Label38.Text = frm1.TextBox18.Text
frm5.Label38.ForeColor = Color.Black
frm5.Label39.Text = frm1.TextBox19.Text
frm5.Label39.ForeColor = Color.Black
frm5.Label40.Text = frm1.TextBox20.Text
frm5.Label40.ForeColor = Color.Black
End If
If frm5 IsNot Nothing Then
frm5.Show(Me) 'Show Second Form
Me.Hide()
End If
If CBool(String.Compare(frm1.TextBox2.Text.Trim(), frm3.TextBox1.Text.Trim(), True)) Then
frm5.PictureBox1.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox1.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox4.Text.Trim(), frm3.TextBox2.Text.Trim(), True)) Then
frm5.PictureBox2.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox2.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox6.Text.Trim(), frm3.TextBox3.Text.Trim(), True)) Then
frm5.PictureBox3.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox3.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox8.Text.Trim(), frm3.TextBox4.Text.Trim(), True)) Then
frm5.PictureBox4.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox4.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox10.Text.Trim(), frm3.TextBox5.Text.Trim(), True)) Then
frm5.PictureBox5.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox5.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox12.Text.Trim(), frm3.TextBox6.Text.Trim(), True)) Then
frm5.PictureBox6.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox6.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox14.Text.Trim(), frm3.TextBox7.Text.Trim(), True)) Then
frm5.PictureBox7.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox7.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox16.Text.Trim(), frm3.TextBox8.Text.Trim(), True)) Then
frm5.PictureBox8.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox8.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox18.Text.Trim(), frm3.TextBox9.Text.Trim(), True)) Then
frm5.PictureBox9.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox9.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox20.Text.Trim(), frm3.TextBox10.Text.Trim(), True)) Then
frm5.PictureBox10.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox10.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
frm5.Show()
Me.Hide()
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
If frm5 IsNot Nothing Then
frm5.Visible = False
frm5.Show() 'Show Second Form
Me.Hide()
End If
End Sub
Private Sub Form5HasBeenClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
Throw New NotImplementedException
End Sub
End Class
There are some issues here that needs to be addressed:
1. You have pasted far to much code. All you needed was to paste the If statements (Because that is where you are having problem, and that is where the problem is).
2. And this is regarding your problem:
String.Compare will give you the result 0 if two strings match. 0 (which is also known as false if you convert it to Boolean). So when two strings match you correctly display a Cross. Compare will also tell you which String is bigger than the other. 1 if the first one is bigger, -1 if it isn't (Sidetrack not important here). I suggest you do the following instead:
If frm1.TextBox2.Text.ToUpper().Equals(frm3.TextBox1.Text.ToUpper()) Then
In this case it is pretty obvious what happends. If string 1 is equal to string two then the result is True. No CBool required.
Your ifstatements are messed up. Question 2-oo will only be addressed if the first statement is false. I will show you what I mean.
If statement = true Then
Display checkmark
Else
Display cross
'Now you do the next one inside the else statement
If statement2 = True Then
'Display checkmark
Else
Display cross
'And then you continue the nesting
End If
End If
What you need to do is this:
If statement = true Then
'Display check
Else
'Display cross
End If 'Notice how I close the ifstatement before I go to the next one.
If statement2 = true Then
'Display check
Else
'Display cross
End If
etc...
I hope you get this, otherwise let me know and I'll try to simplify it further.

Dual Monitor screen saver fail

I am attempting to make a dual screen screen saver. It was working at the beginning but now it isn't working. Here is the start up function:
Sub Main()
Dim x = 0
For Each screen As Screen In screen.AllScreens
Dim screensaver As ScrSav = New ScrSav(screen.Bounds)
screensaver.Location = screen.Bounds.Location
screensaver.Show()
x += 1
Debug.Print(screen.Bounds.Left & " " & screen.Bounds.Top & " " & screen.Bounds.Width & " " & screen.Bounds.Height & " " & "")
Next
Application.Run()
End Sub
and here is the form code
Public Class ScrSav
Public Sub New()
InitializeComponent()
End Sub
Public Sub New(xBounds As Rectangle)
InitializeComponent()
Me.Bounds = xBounds
Debug.Print(Me.Bounds.Left & " " & Me.Bounds.Top & " " & Me.Bounds.Width & " " & Me.Bounds.Height & " " & "")
Cards.Location = New Point((Me.Width - Cards.Width) / 2, (Me.Height - Cards.Height) / 2)
Header.Location = New Point((Me.Width - Header.Width) / 2, 0)
Cards.Navigate("http://pah.guycothal.com/screensaver.aspx")
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End
End Sub
Private Sub ScrSav_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
End
End Sub
End Class
What am i doing wrong???
I am initializing the 2 screen the way others are. in fact, i have a few places where I have put debugging in place to see what is going on in each of the subs. here is what is it outputting
0 0 1280 800 <--main
0 0 1280 800 <--new
1280 -224 1280 1024 <-main
1280 -224 1280 1024 <-new
I have labeled which sub each is from to make it easier to understand. Also, here is what is on the form itself
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class ScrSav
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ScrSav))
Me.Cards = New System.Windows.Forms.WebBrowser()
Me.Header = New System.Windows.Forms.PictureBox()
CType(Me.Header, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Cards
'
Me.Cards.AllowNavigation = False
Me.Cards.AllowWebBrowserDrop = False
Me.Cards.IsWebBrowserContextMenuEnabled = False
Me.Cards.Location = New System.Drawing.Point(128, 137)
Me.Cards.MaximumSize = New System.Drawing.Size(640, 200)
Me.Cards.MinimumSize = New System.Drawing.Size(640, 200)
Me.Cards.Name = "Cards"
Me.Cards.ScriptErrorsSuppressed = True
Me.Cards.ScrollBarsEnabled = False
Me.Cards.Size = New System.Drawing.Size(640, 200)
Me.Cards.TabIndex = 0
Me.Cards.TabStop = False
Me.Cards.Url = New System.Uri("http://pah.guycothal.com/screensaver.aspx", System.UriKind.Absolute)
Me.Cards.WebBrowserShortcutsEnabled = False
'
'Header
'
Me.Header.Image = CType(resources.GetObject("Header.Image"), System.Drawing.Image)
Me.Header.InitialImage = CType(resources.GetObject("Header.InitialImage"), System.Drawing.Image)
Me.Header.Location = New System.Drawing.Point(0, 0)
Me.Header.MaximumSize = New System.Drawing.Size(2000, 60)
Me.Header.MinimumSize = New System.Drawing.Size(2000, 60)
Me.Header.Name = "Header"
Me.Header.Size = New System.Drawing.Size(2000, 60)
Me.Header.TabIndex = 1
Me.Header.TabStop = False
'
'ScrSav
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.BackColor = System.Drawing.Color.Black
Me.ClientSize = New System.Drawing.Size(991, 453)
Me.Controls.Add(Me.Header)
Me.Controls.Add(Me.Cards)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.Name = "ScrSav"
Me.ShowInTaskbar = False
Me.Text = "ScrSav"
Me.TopMost = True
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
CType(Me.Header, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
Friend WithEvents Cards As System.Windows.Forms.WebBrowser
Friend WithEvents Header As System.Windows.Forms.PictureBox
End Class

ThreadState always is "Unstarted"

When I start a thread, the ThreadState always is "Unstarted" even if I do a "Thread.Abort()", my thread starts and finish the work good... I don't know why I get that always the same state.
Dim thread_1 As System.Threading.Thread = New Threading.Thread(AddressOf mithread)
thread_1.Start()
System.Threading.Thread.Sleep(100)
While not thread_1.ThreadState = Threading.ThreadState.Running
MsgBox(thread_1.ThreadState.ToString) ' "Unstarted"
thread_1.Abort()
MsgBox(thread_1.ThreadState.ToString) ' "Unstarted" again and again...
End While
UPDATE
This is the sub who calls the thread, and the problem is the "while" statament is not waiting,
PS: You can see a comment explanation at the middle of this sub:
public sub...
...
If Not playerargs = Nothing Then
If randomize.Checked = True Then
Dim thread_1 As System.Threading.Thread = New Threading.Thread(AddressOf mithread)
thread_1.Start()
System.Threading.Thread.Sleep(50)
While thread_1.ThreadState = Threading.ThreadState.Running
Windows.Forms.Application.DoEvents()
End While
Else
progresslabel.Text = "All files added..."
End If
' HERE IS THE PROBLEM, IF I CHECK "AUTOCLOSE" CHECKBOX THEN,
' THE FORM ALWAYS TRY TO CLOSE BEFORE THREAD IS COMPLETED:
' -----------------------------------------
If autoclose.Checked = True Then Me.Close()
'------------------------------------------
Else
...
End Sub
And here is the "mithread" thread:
Public Sub mithread()
Dim Str As String
Dim Pattern As String = ControlChars.Quote
Dim ArgsArray() As String
Str = Replace(playerargs, " " & ControlChars.Quote, "")
ArgsArray = Split(Str, Pattern)
Using objWriter As New System.IO.StreamWriter(Temp_file, False, System.Text.Encoding.UTF8)
Dim n As Integer = 0
Dim count As Integer = 0
Dim foldercount As Integer = -1
For Each folder In ArgsArray
foldercount += 1
If foldercount > 1 Then
InvokeControl(ProgBarPlus1, Sub(x) x.Max = foldercount)
End If
Next
If foldercount = 1 Then
For Each folder In ArgsArray
If Not folder = Nothing Then
Dim di As New IO.DirectoryInfo(folder)
Dim files As IO.FileInfo() = di.GetFiles("*")
Dim file As IO.FileInfo
InvokeControl(ProgBarPlus1, Sub(x) x.Max = files.Count)
For Each file In files
n += 1
CheckPrimeNumber(n)
count += 1
If file.Extension.ToLower = ".lnk" Then
Dim ShotcutTarget As String = Shortcut.ResolveShortcut((file.FullName).ToString())
objWriter.Write(ShotcutTarget & vbCrLf)
Else
objWriter.Write(file.FullName & vbCrLf)
End If
Next
End If
Next
ElseIf foldercount > 1 Then
For Each folder In ArgsArray
If Not folder = Nothing Then
Dim di As New IO.DirectoryInfo(folder)
Dim files As IO.FileInfo() = di.GetFiles("*")
Dim file As IO.FileInfo
InvokeControl(ProgBarPlus1, Sub(x) x.Value += 1)
For Each file In files
If file.Extension.ToLower = ".lnk" Then
Dim ShotcutTarget As String = Shortcut.ResolveShortcut((file.FullName).ToString())
objWriter.Write(ShotcutTarget & vbCrLf)
Else
objWriter.Write(file.FullName & vbCrLf)
End If
Next
End If
Next
End If
End Using
If Not thread_1.ThreadState = Threading.ThreadState.AbortRequested Then
MsgBox(thread_1.ThreadState.ToString)
Randomize_a_file.RandomizeFile(Temp_file)
InvokeControl(ProgBarPlus1, Sub(x) x.Value = 0)
' Process.Start(userSelectedPlayerFilePath, ControlChars.Quote & Temp_file.ToString() & ControlChars.Quote)
InvokeControl(progresslabel, Sub(x) x.Text = "All files launched...")
End If
End Sub
Its not easy to work out what your problem is, but i can say for sure a While Loop and DoEvents is not the way forward at all.
Instead raise an event when the thread has done all its work, subscribe to the event, and when it is raise close the form (if autoclose = true):
Public Class Form1
Public Event threadCompleted()
Public Sub New()
InitializeComponent()
AddHandler threadCompleted, AddressOf Me.Thread_Completed
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t1 As New Threading.Thread(AddressOf mithread)
t1.Start()
End Sub
Public Sub mithread()
'simulate some work:
Threading.Thread.Sleep(3000)
'then raise the event when done
RaiseEvent threadCompleted()
End Sub
Public Delegate Sub Thread_CompletedDelegate()
Private Sub Thread_Completed()
If Me.InvokeRequired Then
Me.BeginInvoke(New Thread_CompletedDelegate(AddressOf Thread_Completed))
Else
If autoclose.Checked = True Then
Me.Close()
End If
End If
End Sub
End Class
Or use a background worker which does all this, plus handles reporting progress and cancelation all for you.
Sounds like something is happening in mithread that is preventing the thread from fully starting. I ran similar code with an empty sub for mithread and I get the expected threadstate (Stopped then Aborted).
Sub Main()
Dim thread_1 As System.Threading.Thread = New Threading.Thread(AddressOf mithread)
thread_1.Start()
System.Threading.Thread.Sleep(100)
While Not thread_1.ThreadState = Threading.ThreadState.Running
Console.WriteLine(thread_1.ThreadState.ToString)
thread_1.Abort()
Console.WriteLine(thread_1.ThreadState.ToString)
If thread_1.ThreadState = Threading.ThreadState.Aborted Then Exit While
End While
End Sub
Sub mithread()
End Sub