I'm trying to open a form and getting this error - vb.net

Okay, here is my code.
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 1000
ProgressBar1.Value = 1000
Timer1.Interval = 1750
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Form3.Show()
Me.Close()
End Sub
End Class
On the line Form3.Show() I get
InvalidOperationException was unhandled.
An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.
What I have on Form3:
Public Class Form3
Public IPAddress As String = TextBox1.Text
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form4.Show()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Form4.varible1 = True Then
Label1.Text = "IP: " + IPAddress
End If
End Sub
End Class
Any help?

Change on form3
Public IPAddress As String = TextBox1.Text ...."TextBox1.Text is "" thats why you get the error"
To
Public IPAddress As String
End then add IPAddress = TextBox1.Text in you timer
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Form4.varible1 = True Then
IPAddress = TextBox1.Text
Label1.Text = "IP: " + IPAddress
End If
End Sub

Related

passing a parameter to fillby(vb.net)

I have problem passing a parameter to fillby
I made fill method call FillByA but there is problem!!
its said:
“too many arguments to ‘public override Overloads function fillbyA(data Table as ContactsDataSet.recordsDataTable) as integer’
This is my code:
Public Class Adminlogin
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text.Trim = "" Or TextBox2.Text.Trim = "" Then
MsgBox("you should complet ypur deails")
Else
//error happen here !
Me.AdminTableAdapter.FillByA(Me.UserDataSet1.Admin, Me.TextBox1.Text.Trim, Me.TextBox2.Text.Trim)
If Me.UserDataSet1.user.Count > 0 Then
Me.Close()
Test.Show()
Else
MsgBox("Logon failure, user name or password are incorrect!", MsgBoxStyle.Critical)
End If
End If
End Sub
Private Sub Ad_NameTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If IsNumeric(e.KeyChar.ToString()) Then
MessageBox.Show("Letters only!")
SendKeys.Send("{Backspace}")
End If
End Sub
Private Sub Ad_NameTextBox_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
admincon.Show()
End Sub
End Class

Interrupting loop in VB.net

I have a loop that runs but would like it to stop on the press of a button and start again when another is pressed. This is my code:
Public Class Form1
Private loopon As Boolean
Public Function ping(ByVal server As String) As String
Dim s As New Stopwatch
s.Start()
My.Computer.Network.Ping(server)
s.Stop()
Return s.ElapsedMilliseconds.ToString
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
loopon = True
TextBox1.Text = "Ping results:"
Do While loopon = True
TextBox1.AppendText(Environment.NewLine)
TextBox1.AppendText(ping("server name here"))
Loop
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
loopon = False
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = String.Empty
TextBox1.Text = "Ping results:"
loopon = True
End Sub
End Class
When I try to run the code, with debugging, my computer gives me a blue screen after a while and restarts. I'm pretty sure I messed up with the exiting of the loop. Any suggestions?
You could use a Timer to ping (say) every 5 seconds until the "Stop" button is clicked. In the Form Designer, drag a Timer onto the form, and use this code:
Public Class Form1
Private stopPing As Boolean
Public Sub Ping(ByVal server As String)
Dim s As New Stopwatch
s.Start()
My.Computer.Network.Ping(server)
s.Stop()
TextBox1.AppendText(Environment.NewLine & s.ElapsedMilliseconds.ToString)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = "Ping results:"
Ping "server name here"
Timer1.Interval = 5000 'Set timer Interval to 5 seconds
Timer1.Start
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
stopPing = True
End Sub
Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If stopPing Then Timer1.Stop Else Ping "server name here"
End Sub
End Class

Do Process while Progress Bar is Running

I know that knowledge is expensive, but is there who want to help me
i want to run process when progress bar is running,
i try with this code
Public Class Form2
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call Prcss()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Progress.Value < 100 Then
Progress.Value += 2
ElseIf Progress.Value = 100 Then
Timer1.Stop()
Form1.Show()
Me.Hide()
End If
End Sub
Private Sub Prcss()
With Progress
.Value = 0
Threading.Thread.Sleep(450)
Label1.Text = "Renewing Custom Content"
.Value = 20
Threading.Thread.Sleep(450)
Label1.Text = "Getting Information"
.Value = 50
Threading.Thread.Sleep(450)
Label1.Text = "Downloading Udpdate"
.Value = 70
Threading.Thread.Sleep(450)
Label1.Text = "Ready to Start"
.Value = 100
End With
End Sub
i don't know where is my mistake, i read this on my book.
Try using a BackgroundWorker or a Thread:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
For i As Integer = 1 To 1000
BackgroundWorker1.ReportProgress(CInt(i / 10))
Threading.Thread.Sleep(500)
Next
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
MessageBox.Show("Finished!")
End Sub
This is the basic example and require you to add a BackgroundWorker to the form. You can see help here: https://msdn.microsoft.com/es-es/library/cc221403(v=vs.95).aspx

Vb.net Error then use form4.show

I have a little problem with my program. I just maked a little program. I have a problem with code "Form4.Show()".
I put this code on button and then press button I receive error:
An error occurred creating the form. See Exception.IneerException for details. The error is: Object reference not set to an instance of an object.
I don't know what code I put wrong ... this button have only form4.show.
PS: this error is from try catch.
This is button code.
Try
Form4.Show
Catch ex as Exception
MessageBox.Show(ex.Message)
End Try
edit: all form4 code
Public Class Form4
Dim txt As String = Textbox1.Text
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
txt = "450IP-Gift"
Form5.Show()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
txt = "450IP"
Form5.Show()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
txt = "1150IP-Gift"
Form5.Show()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
txt = "1150IP"
Form5.Show()
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
txt = "3150IP-Gift"
Form5.Show()
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
txt = "3150IP"
Form5.Show()
End Sub
Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
txt = "4800IP-Gift"
Form5.Show()
End Sub
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
txt = "4800IP"
Form5.Show()
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
txt = "6300IP-Gift"
Form5.Show()
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
txt = "6300IP"
Form5.Show()
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
txt = "9600IP-Gift"
Form5.Show()
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
txt = "9600IP"
Form5.Show()
End Sub
Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
Me.Close()
End Sub
End Class
You need to initialize form4
Try
Dim form4 = New Form4()
form4.Show()
Catch ex as Exception
MessageBox.Show(ex.Message)
End Try

vb For loop repeat a certain number of times

So I am making a port scanner and have a min and max port, but can't get the port scanner to stop scanning when it reaches the maximum port?
I have tried doing an Exit For when port reaches portmax.
Here is the code:
Public Class Form1
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim counter As Integer
Button2.Enabled = False
'set counter explained before to 0
counter = 0
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
Dim host As String
Dim counter As Integer
Dim portmin As Integer = TextBox3.Text
Dim portmax As Integer = TextBox2.Text
'Set the host and port and counter
counter = counter + 1 'counter is for the timer
host = TextBox1.Text
For port As Integer = portmin To portmax
' Next part creates a socket to try and connect
' on with the given user information.
Dim hostadd As System.Net.IPAddress = _
System.Net.Dns.GetHostEntry(host).AddressList(0)
Dim EPhost As New System.Net.IPEndPoint(hostadd, port)
Dim s As New System.Net.Sockets.Socket( _
System.Net.Sockets.AddressFamily.InterNetwork, _
System.Net.Sockets.SocketType.Stream, _
System.Net.Sockets.ProtocolType.Tcp)
Try
s.Connect(EPhost)
Catch
End Try
If Not s.Connected Then
ListBox1.Items.Add("Port " + port.ToString + " is not open")
Else
ListBox1.Items.Add("Port " + port.ToString + " is open")
ListBox2.Items.Add(port.ToString)
End If
Label3.Text = "Open Ports: " + ListBox2.Items.Count.ToString
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
'stop button
Timer1.Stop()
Timer1.Enabled = False
Button1.Enabled = True
Button2.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Add("Scanning: " + TextBox1.Text)
ListBox1.Items.Add("-------------------")
Button2.Enabled = True
Button1.Enabled = False
Timer1.Enabled = True
Timer1.Start()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub ListBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox2.SelectedIndexChanged
End Sub
End Class
I would really appreciate any help
thanks,
Try to stop the Timer while in the scanning.
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
'Your code
Timer1.Enabled = True
End Sub
If thats the problem, and looks like it, you should consider using a Try/Catch block:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Try
Timer1.Enabled = False
'Your code
Catch ex As Exception
'Manage the error
Finally
Timer1.Enabled = True
End Try
End Sub
Try this
For port As Integer = portmin To portmax - 1