I'm experimenting with a simple auto typer. I've made several of these before, but have never received this error. I just want to be able to send the text within textbox3 to the currently focused window. Here's the code :
code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Timer1.Enabled = False Then
Timer1.Enabled = True
Button2.Text = "Stop"
ElseIf Timer1.Enabled = True Then
Timer1.Enabled = False
Button2.Text = "Send"
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If CheckBox1.Checked = True Then
SendKeys.Send("{ENTER}")
SendKeys.Send(TextBox3.Text)
ElseIf CheckBox1.Checked = False Then
SendKeys.Send(TextBox3.Text)
End If
End Sub
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
Timer1.Interval = NumericUpDown1.Value
End Sub
Thats the only portion involving the sendkeys method and timer. Some of the text within textbox3 comes from variables as well, if that helps to know.
In another (now deleted) question, you claim the error happens here:
SendKeys.Send(Textbox3.Text)
Well, what is the value of Textbox3.Text which produces the error? According to the documentation, specifying repeated keys would involve a key token and an integer separate by a space, enclosed in curly braces. Something like "{LEFT 42}" or "{h 10}". So if you're entering something like "{A B}" then it's going to fail.
Presumably the runtime value of Textbox3.Text has an invalid format for SendKeys.Send(), or is mis-using characters which are otherwise reserved for the format string.
Related
This is a small piece of code for a project I'm working on for my study.
We have to make a program in Visual Basic (with Visual Studio 2015) that copies text from the first text box and pastes it into the second one once you press the button that states: "Show Name".
We are meant to handle it so that if the value entered is between 'A' to 'Z' then it copies the text and pastes it normally once you press the button into the second text box.
We are also supposed to make it so that, if the value is a number (between 0 and 9) we are meant to have a message which pops up saying something like: "Error - You Entered a Number".
We are also supposed to make a box that pops up saying: "Error - You Entered Something Other Than a Number", if the value is a character other than a letter or a number. I am in kind of a rush and would appreciate any help soon.
Here is my code so far. (I know Keys.A and Keys.Z and the message box is wrong, which I need to fix, too):
Public Class MyFirstProgram
Private Sub DisplayTextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisplayTextButton.Click
ShowTextBox.Text = EnterTextBox.Text
End Sub
Private Sub me_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Dim letterEntered As Char
If e.KeyCode < Keys.A Or e.KeyCode > Keys.Z Then
MsgBox("Error - Use letter keys only!", MsgBoxStyle.OkOnly, )
Else
letterEntered = LCase(ChrW(e.KeyCode))
If ShowTextBox.Text = "" Then
ShowTextBox.Text = letterEntered
Else
ShowTextBox.Text = ShowTextBox.Text + letterEntered
End If
End If
End Sub
Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
EnterTextBox.Text = ""
End Sub
Private Sub MyFirstProgram_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True
End Sub
End Class
Oh, and I'm new to Visual Basic/programming; so, please try to be patient if you can. Sorry :/
Use KeyPress press event .. instead of keyDown
Private Sub me_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
'If e.KeyCode < Keys.A Or e.KeyCode > Keys.Z Then
' MsgBox("Error - Use letter keys only!", MsgBoxStyle.OkOnly, )
'Else
' Dim letterEntered = LCase(ChrW(e.KeyCode))
' ShowTextBox.Text = ShowTextBox.Text + letterEntered
'End If
'e.Handled = True
End Sub
Private Sub Form1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress
If Not Char.IsLetter(e.KeyChar) Then
MsgBox("Error - Use letter keys only!", MsgBoxStyle.OkOnly)
e.Handled = True
End If
End Sub
just look in to the IsNumeric Function if it could help you.
I want to know the code to the following illustration.
i have one form with some checkboxs and one button,
screen is here
i've try with this code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If CheckBox1.Checked = True And CheckBox2.Checked = True And CheckBox3.Checked = True And CheckBox4.Checked = True Then
'when the button is clicked will be the process for moving images
'Like
System.IO.File.Copy(Application.StartupPath + "\File\Pic1.jpg", "D:\File\Pic1.jpg")
End If
End Sub
I was tired with that code, is there a shorter coding ?
for example, if the checkbox1.checked = true and another checkbox not checked then only moving one pict
If I understand the question, you want to copy pictures 1 to 4 if the checkboxes 1 to 4 are checked.
Try this:
Dim SourcePath As string = Application.StartupPath + "\File\"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
CopyFile(CheckBox1, "Pic1.jpg")
CopyFile(CheckBox2, "Pic2.jpg")
CopyFile(CheckBox3, "Pic3.jpg")
CopyFile(CheckBox4, "Pic4.jpg")
End Sub
Private Sub CopyFile(CB As CheckBox, FileName As String)
If CB.Checked Then
System.IO.File.Copy(SourcePath + FileName, "D:\File\" + FileName)
End If
End Sub
In visual basic,
I want to make a TextBox2 visible when TextBox1.Text = "SHUTDOWN"
this is my code
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs)
Handles TextBox1.TextChanged
AcceptButton = Button1
If TextBox1.Text = "SHUTDOWN" Then
TextBox2.Visible = True
End If
End Sub
but it's not working
note: there is no error message... and the textbox1 charachter casing is "upper" so it will be "SHUTDOWN" and not working means that when i write "SHUTDOWN" in textbox1, textbox2 don't become visible
.NET is case sensitive, that means that shutdown is not the same as SHUTDOWN. You can use Equals with the overload that takes a StringComparison:
If TextBox1.Text.Equals("SHUTDOWN", StringComparison.CurrentCultureIgnorecase) Then
TextBox2.Visible = True
End If
Another option in VB.NET only is to use OPTION Compare on file- or on project level.
If you use this as first line in your file:
Option Compare Text
You get a case-insensitive comparison. However, i would prefer the .NET way.
Text: Results in string comparisons based on a case-insensitive text sort
order determined by your system's locale. This type of comparison is
useful if your strings contain all text characters, and you want to
compare them taking into account alphabetic equivalences such as case
insensitivity and closely related letters. For example, you might want
to consider A and a to be equal, and Ä and ä to come before B and b.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Textbox2.visible = False
End Sub
Protected Sub TxtBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtBox1.TextChanged
If TxtBox1.Text.ToUpper = "SHUTDOWN" Then
TextBox2.Visible = True
Else
TextBox2.Visible = False
End If
End Sub
To ignore the case of your text (if that is the problem) you could use the following:
If TextBox1.Text.ToUpper() = "SHUTDOWN" Then
TextBox2.Visible = True
End If
also be sure your TextBox2 has the right coordinates when became visible.
Just did a test with:
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
If (TextBox1.Text = "SHUTDOWN") Then
TextBox2.Visible = True
End If
End Sub
Found no problems - it may be AcceptButton = Button1. I'm not sure why it isn't working but mine is working when "SHUTDOWN" is entered. Try changing the AcceptButton to a comment (') and then trying the code, if it works then its the AcceptButton variable.
May not be declared probably to store a button?
Dim Wrd As String = "SHUTDOWN"
Protected Sub TxtBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtBox1.TextChanged
If Wrd = TxtBox1.Text.ToUpper Then
TxtBox5.Visible = True
End If
End Sub
I have a script that logs into a website and can autoclick something very fast for the given interval. Now ever since I added my newest detail in, everything in the script works, except the autoclicker. Once I click the button to start the autoclicker it doesn't even click once.
Here is the code I just added
With WebBrowser1
Do Until Not (.IsBusy)
Application.DoEvents()
Loop
Do Until .ReadyState = WebBrowserReadyState.Complete
Application.DoEvents()
Loop
End With
Dim htmlText As String
If Not (WebBrowser1.Document.Body.InnerHtml) Is Nothing Then
htmlText = WebBrowser1.Document.Body.InnerHtml
If InStr(htmlText, "Microsoft account") Then
MessageBox.Show("You have entered in a wrong password or the account doesn't exist.")
'code to go here if it is true
Else
MessageBox.Show("Sign in successful. Proceed on...")
'code to go here if it is false
End If
End If
what the code does is it tells you if you used the correct login credentials or the wrong ones. But i don't understand how that would affect my autoclicking button?
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButton1.Checked = True Then
Timer1.Interval = 40
ElseIf RadioButton2.Checked = True Then
Timer1.Interval = 100
Else
Timer1.Interval = 500
End If
Timer1.Start()
WebBrowser1.Document.GetElementById("NewGamertag").SetAttribute("value", txtTurbo.Text)
WebBrowser1.Document.GetElementById("claimIt").InvokeMember("Click")
End Sub
Where timer1 =
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
WebBrowser1.Document.GetElementById("claimIt").InvokeMember("Click")
End Sub
Make your timer1.enable = true, else it wont be work.
I have a case where i need to generate millions of unique codes. For this I have created a generate function where the random number is generated. I call this function from a for loop and add the generated number on a list box. my code is as follow
for i=1 to val(txtnumber.txt)
mynum=generate()
next
I have created a lable on form where i wanted to display the no of secs elapsed while processing the loop. I used timer control as
timer1.start()
for i=1 to val(txtnumber.text)
mynum=generate()
listbox1.items.add(mynum)
next
timer1.stop
and on timer1_tick function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = Val(Label1.Text) + 1
End Sub
but when i click generate button, all numbers are generated, but timer doesnot shows time elapsed.
I may have missed something, so please help me out
This is probably best handled in a BackgroundWorker. Place one on the form and set its WorkerReportsProgress=True. Also, placing a million numbers in a ListBox probably isn't a good idea, so I omitted that.
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Button1.Enabled = False
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim started As DateTime = Now
For i As Integer = 1 To val(txtnumber.txt)
mynum=generate()
BackgroundWorker1.ReportProgress(i, Nothing)
Next
Dim ended As TimeSpan = Now.Subtract(started)
BackgroundWorker1.ReportProgress(0, ended.TotalSeconds.ToString)
End Sub
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
If e.UserState IsNot Nothing Then
Label1.Text = e.UserState.ToString()
Else
Label1.Text = e.ProgressPercentage.ToString
End If
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
Button1.Enabled = True
End Sub
Your label should be updating correctly when the worker reports the ProgressChanged event.
What you're encountering is a threading issue. The work you are doing to generate the numbers is being executing by the UI thread, so it never gets a chance to update the screen. Take a look here: How to prevent UI from freezing during lengthy process?
This one might also have good information for you: Updating UI from another thread
Try this:
Private _Counter As Integer = 0
Private _StartTime As Date = Now
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
_StartTime = Now
_Counter = CInt(Val(txtnumber.Text))
ListBox1.Items.Clear()
Label1.Text = "0"
Timer1.Interval = 50
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
ListBox1.Items.Add(generate())
Label1.Text = New Date((Now - _StartTime).Ticks).ToString("HH:mm:ss.ff")
_Counter -= 1
If (_Counter <= 0) Then
Timer1.Stop()
End If
End Sub
Or you can research actual Threading.