How to send whatsapp pdf message without api using vb.net - vb.net

I'm able to send text msg from whatsapp using vb.net. Colud someone tell me how to send pdf document from vb.net. Thanks....
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim web As New WebBrowser
web.Navigate("whatsapp://send?phone=" & TextBox1.Text & "&text=" & TextBox2.Text.Replace(" ", "+") & "")
' web.Navigate("wa.me/send?phone=" & TextBox1.Text & "&attachment=" & TextBox2.Text.Replace(" ", "+") & "")
Timer1.Start()
Catch ex As Exception
Timer1.Stop()
End Try
End Sub
Dim sec As Integer = 0
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Sec += 1
If sec = 10 Then
SendKeys.Send("{ENTER}")
Timer1.Stop()
sec = 0
End If
End Sub

Related

save pictures from Webcam using EMGU

I want to modify my program in VB 2015 that captures a photo using a webcam and saves it to my folder. The problem is that it replaces every picture taken, I want to save every picture with this format name picture01, picture02 etc.
Info: I am using Emgu.
picture
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Try
PictureBox1.Image = capture.QueryFrame.ToBitmap()
Catch ex As Exception
capture = New Emgu.CV.Capture
End Try
End Sub
Private Sub startWebcam_Click(sender As Object, e As EventArgs) Handles startWebcam.Click
Timer1.Start()
End Sub
Private Sub captWebcam_Click(sender As Object, e As EventArgs) Handles captWebcam.Click
Dim picnumber As Integer = 0
Timer1.Stop()
'Save the picture
PictureBox1.Image.Save("D:\WEBCAM\Img01.JPEG", Imaging.ImageFormat.Jpeg)
capture.Dispose()
End Sub
You could make your file name a date stamp, that way it will always be unique:
Dim a As String = Now.ToShortDateString & Now.ToLongTimeString
a = a.Replace(":", "").Replace("/", "").Replace("\", "")
PictureBox1.Image.Save("D:\WEBCAM\" & a & ".JPEG", Imaging.ImageFormat.Jpeg)
You could also use a simple integer increment:
Private FileID as Integer = 0
Private Sub captWebcam_Click(sender As Object, e As EventArgs) Handles captWebcam.Click
Timer1.Stop()
'Save the picture
FileID += 1
PictureBox1.Image.Save("D:\WEBCAM\Img" & FileID.ToString("00") & ".JPEG", Imaging.ImageFormat.Jpeg)
capture.Dispose()
End Sub

printing to a file in a windows forms application---Visual Basic

So I'm coding a program in Visual Basic that gets the user to input book details (ISBN Number, Author ........) and then prints the details to a file. I have the following code which displays the form and all the input boxes however I'm clueless on where I need to place the code to print to a file.
The code to print to the file is as follows
FileOpen(1, "C:\test\testbook.txt", OpenMode.Append)
PrintLine(1, ISBN & " " & Author & " " & Title & " " & PageCount)
FileClose()
I tried placing it in the sub for the form but that didn't work. My question is where do I have to put this code in order for it to print to a file
Full code:
Public Class createBookform
Public ISBN, Author, Title As String
Public PageCount As Integer
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FileOpen(1, "C:\test\testbook.txt", OpenMode.Append)
PrintLine(1, ISBN & " " & Author & " " & Title & " " & PageCount)
FileClose()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
ISBN = TextBox1.Text
End Sub
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
Author = TextBox3.Text
End Sub
Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
Title = TextBox4.Text
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
PageCount = TextBox2.Text
End Sub
Private Sub OKbUTTON_Click(sender As Object, e As EventArgs) Handles OKbUTTON.Click
MessageBox.Show("New book entered successfully", "Book confirmation")
Close()
End Sub
End Class
windows form that opens when code is executed
Unless if I'm missing something, do you just mean to do:
Public Class createBookform
Public ISBN, Author, Title As String
Public PageCount As Integer
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
ISBN = TextBox1.Text
End Sub
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
Author = TextBox3.Text
End Sub
Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
Title = TextBox4.Text
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
PageCount = TextBox2.Text
End Sub
Private Sub OKbUTTON_Click(sender As Object, e As EventArgs) Handles OKbUTTON.Click
FileOpen(1, "C:\test\testbook.txt", OpenMode.Append)
PrintLine(1, ISBN & " " & Author & " " & Title & " " & PageCount)
FileClose()
MessageBox.Show("New book entered successfully", "Book confirmation")
Close()
End Sub
End Class
?
Typically, you wouldn't bother with the variables or the TextChanged events at all, and you would just use this:
Public Class createBookform
Private Sub OKbUTTON_Click(sender As Object, e As EventArgs) Handles OKbUTTON.Click
FileOpen(1, "C:\test\testbook.txt", OpenMode.Append)
PrintLine(1, TextBox1.Text & " " & TextBox3.Text & " " & TextBox4.Text & " " & TextBox2.Text)
FileClose()
MessageBox.Show("New book entered successfully", "Book confirmation")
Close()
End Sub
End Class
And to make it clearer, you would rename your text boxes something that makes sense (e.g., txbISBN for the ISBN text box).

VB.Net - Timer Control freezes application

I have added a Timer control to a vb.net application that is used to check if a website is up or down. There are two Timer controls in the app. Both are from System.Windows.Forms.Timer.
There is Timer1 and Timer2. Timer1 is used to perform the website check. Timer2 is simply to display a current date and time in the ToolStrip at the base of the form. The Timer2 runs without issue displaying the time, but when I start the website check that runs Timer1, the application freezes after two checks. Sometimes it runs longer, but eventually freezes.
I have to End Task from within Task Manager in order to shut down the application. I have tested this from within the Debugger and after running the executable. I have also completely removed Timer2 and tested, but the freezing remains. Here is my code. Any assistance would be greatly appreciated.
Imports System
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
lblStatus.Text = ""
Timer1.Stop()
btnStart.Enabled = True
btnStop.Enabled = False
End Sub
Public Function CheckAddress(ByVal URL As String) As Boolean
Try
Dim request As WebRequest = WebRequest.Create(URL)
Dim response As WebResponse = request.GetResponse()
Catch ex As Exception
Return False
End Try
Return True
End Function
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Dim startPoint As Integer = -1
If CheckAddress(txtAddress.Text).ToString() = True Then
rtxtResults.AppendText(" -- " & txtAddress.Text & " - Website shows UP at " & tsClock.Text & " - " & vbNewLine)
ElseIf CheckAddress(txtAddress.Text).ToString() = False Then
rtxtResults.AppendText(" -- " & txtAddress.Text & " - Website shows DOWN at " & tsClock.Text & " - " & vbNewLine)
End If
Do
startPoint = rtxtResults.Find("Website shows DOWN at", startPoint + 1, RichTextBoxFinds.None)
If (startPoint >= 0) Then
rtxtResults.SelectionStart = startPoint
rtxtResults.SelectionLength = "Website shows DOWN at".Length
rtxtResults.SelectionColor = Color.Red
End If
Loop Until startPoint < 0
End Sub
Private Sub Timer2_Tick(sender As System.Object, e As System.EventArgs)
tsClock.Text = Now()
End Sub
Private Sub btnStart_Click(sender As System.Object, e As System.EventArgs) Handles btnStart.Click
If txtInterval.Text = "" Then
MsgBox("Must enter a number")
Exit Sub
End If
lblStatus.ForeColor = Color.Green
lblStatus.Text = "Running"
btnStart.Enabled = False
btnStop.Enabled = True
Timer1.Interval = Int(txtInterval.Text) * 1000
Timer1.Start()
End Sub
Private Sub btnStop_Click(sender As System.Object, e As System.EventArgs) Handles btnStop.Click
lblStatus.ForeColor = Color.Red
lblStatus.Text = "Stopped"
btnStop.Enabled = False
btnStart.Enabled = True
Timer1.Stop()
End Sub
End Class
Your application's UI will "freeze" until the Timer1_Tick method completes. Most likely your Timer1_Tick's Do...Loop is not exiting. Try deleting the Do and Loop lines.

Bring Window To Top/Active

I need some help with a small little program that I am making for a game. I can't get it to work so it switch to the game and then press the buttons that I want. It finds the window but just don't switch to it or make it active. Am I using the correct function?
Public Class Form1
Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Integer) As Integer
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Dim Hwnd As Long = BringWindowToTop("Aftermath v0.9.0 (build: Apr 15 2015 14:38:12) - final D3D9")
Dim Hnd As Integer = Win32.FindWindow(Nothing, "Aftermath v0.9.0 (build: Apr 15 2015 14:38:12) - final D3D9") & BringWindowToTop(Hnd)
If (Not Hnd = 0) Then
SendKeys.Send("{enter}")
SendKeys.Send("/ginvite " & Chr(34) & TextBox1.Text & Chr(34))
Else
MessageBox.Show("Error")
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim curItem As String = ListBox1.SelectedItem.ToString()
SendKeys.Send("/ginvite " & Chr(34) & curItem & Chr(34))
SendKeys.Send("{enter}")
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim curItem As String = ListBox1.SelectedItem.ToString()
SendKeys.Send("/gaccept " & Chr(34) & curItem & Chr(34))
SendKeys.Send("{enter}")
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
For i As Integer = 0 To Me.ListBox1.Items.Count - 1
Me.ListBox1.SetSelected(i, True)
Next
'Dim curItems As String = ListBox1.SelectedItems.ToString()
'SendKeys.Send("/ginvite" & Chr(34) & curItems & Chr(34))
'SendKeys.Send("{enter}")
End Sub
End Class
I would also love if you could help me with my list box. I want it so it prints our each string with Chr(34) in front and behind it.
The code that I currently have (doesn't work):
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
For i As Integer = 0 To Me.ListBox1.Items.Count - 1
Me.ListBox1.SetSelected(i, True)
Next
'Dim curItems As String = ListBox1.SelectedItems.ToString()
'SendKeys.Send("/ginvite" & Chr(34) & curItems & Chr(34))
'SendKeys.Send("{enter}")
End Sub

Changing background image with timer

Here is my code in vb.net for automatically changing image using timer but code doesn't work...
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.BackgroundImage = Image.FromFile("C:\images\\" + Label1.Text + "1.jpg")
Dim i As Integer = Convert.ToInt32(Label1.Text)
i += 1
If (i > 4) Then
i = 1
End If
Label1.Text = i.ToString()
End Sub
Move the counter out to class level. Incorporating the comments from dbasnett as well. Also, shouldn't the label reflect the current image number? The way you have it the value in the Label is one "ahead" of the background image.
Try something more like:
Private i As Integer = 1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim FileName As String = "C:\images\" & i.ToString & ".jpg"
Try
Me.BackgroundImage = Image.FromFile(FileName)
Label1.Text = i.ToString()
i += 1
If (i > 4) Then
i = 1
End If
Catch ex As Exception
Debug.Print(FileName)
MessageBox.Show(FileName & vbCrLf & vbCrLf & ex.ToString, "Error Loading Image")
End Try
End Sub