[Help] Updating label with integer
Hi guys. I am having what I feel should be a really simple problem. However, I have not been able to fix it after changing my method of doing this several times.
I usually code in C++, but I decided to try VB for this. Basically, the point of the program is to send a spam message to an email address (or cell phone
). I need label9 to display the integer value stored in sent, updating frequently.
I originally put the lines:
within the send loop of the fuction bw_dowork, but the label did not change at all. Then I changed it to display sent in label9 whenever label9 was clicked on or hovered over. That made label9 display the number 0 even long after many messages had been sent (even though I clicked AFTER multiple messages had been sent). The current version starts a new thread just for updating label9. However, it won't display anything. I added in a change of stored text in label9 to "Started Counting...", and that worked. I have not had any build errors, the application just doesn't display sent in label9.
Tell me what you think. (And don't be too hard on me, this is my first project in VB)
The parts that mpgh censored are bw. runworkerasync() and bw2. runworkerasync() (Without the spaces)
I usually code in C++, but I decided to try VB for this. Basically, the point of the program is to send a spam message to an email address (or cell phone
). I need label9 to display the integer value stored in sent, updating frequently.I originally put the lines:
Code:
sent = sent + 1 label9.text = sent
Tell me what you think. (And don't be too hard on me, this is my first project in VB)
Code:
Imports System.Net.Mail
Imports System
Imports System.ComponentModel
Public Class Form1
Dim x As Integer
Dim sent As Integer = 0
Dim bw As BackgroundWorker = New BackgroundWorker
Dim bw2 As BackgroundWorker = New BackgroundWorker
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
bw.WorkerSupportsCancellation = True
bw.WorkerReportsProgress = False
Label8.Text = "Sending..."
bw****nWorkerAsync()
End Sub
Private Sub bw_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
Dim AnEmailMessage As New MailMessage
Dim TheTelephoneNumber As String = TextBox3.Text
Dim MyCarrier As String = TextBox4.Text
Dim at As String = "@"
Dim delaytext As String = TextBox7.Text
Dim delay As Integer = Val(delaytext)
x = 1
AnEmailMessage.From = New MailAddress(TextBox1.Text)
AnEmailMessage.To.Add(TheTelephoneNumber + at + MyCarrier)
AnEmailMessage.Subject = (TextBox5.Text)
AnEmailMessage.Body = (TextBox6.Text)
AnEmailMessage.Priority = MailPriority.High
Dim SimpleSMTP As New SmtpClient("smtp.live.com")
SimpleSMTP.Port = 25
SimpleSMTP.EnableSsl = True
SimpleSMTP.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
Do While x = 1
SimpleSMTP.Send(AnEmailMessage)
sent = sent + 1
System.Threading.Thread.Sleep(delay)
Loop
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
x = 0
Label8.Text = "Stopped"
End Sub
Private Sub Label9_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label9.Click
bw.WorkerSupportsCancellation = True
bw.WorkerReportsProgress = False
Label9.Text = "Started Counting..."
bw2****nWorkerAsync()
End Sub
Private Sub bw2_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
Do While 1 = 1
Label9.Text = sent
System.Threading.Thread.Sleep(500)
Loop
End Sub
End Class
