RobertoFreemano
asked on
NotePad App = detect key word if typed... VB.NET 2010
Hi Experts,
My App is simple textBox (notepad) app...
I want to type away like NopePad... but if i type in special words... e.g. BEEP, then message box BEEP will appear... i use this as a simple example...
Type> something
Do> something else
I must be able to sent-up many key words and they'll perform what i need.
Thanks,
Roberto
My App is simple textBox (notepad) app...
I want to type away like NopePad... but if i type in special words... e.g. BEEP, then message box BEEP will appear... i use this as a simple example...
Type> something
Do> something else
I must be able to sent-up many key words and they'll perform what i need.
Thanks,
Roberto
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If TextBox1.Text = "beep" Then
MsgBox("beep")
End If
End Sub
ASKER
Arcee123,
Do u have VB code please?
Thanks,
Roberto
Do u have VB code please?
Thanks,
Roberto
ASKER
I guest this event would have t be triggered by ENTER keydown
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
Console.WriteLine("Enter")
MsgBox("yes")
End If
End Sub
ASKER
I GOT IT WORKING - WHOOTS!
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
Console.WriteLine("Enter")
If TextBox1.Text.IndexOf("beep") > 0 Then
ToolStripStatusLabel1.Text = "Word Found"
MsgBox("Word Found")
Else
ToolStripStatusLabel1.Text = "Word Not Found"
End If
End If
End Sub
ASKER
How do I add more words?
I know this example doesn't work.
I know this example doesn't work.
If TextBox1.Text.IndexOf("beep" or "something else" or "another word") > 0 Then
ASKER
Ok, i found a bug... can an Expert please help?
If I launch the app... type in beep, press ENTER - nothing happends...
If I launch the app... type in anything, press ENTER, then type in beep - msg("BEEP") appears.
If I launch the app... type in beep, press ENTER - nothing happends...
If I launch the app... type in anything, press ENTER, then type in beep - msg("BEEP") appears.
Are you using the code from http:#37108741
ASKER
Hi CC,
i found code from random google searches.
i found code from random google searches.
What code are you using now?
ASKER
I GOT IT WORKING - WHOOTS! - this bit above...
ASKER
<ElseIf> is the only other way i can think of detecting multiple words and acting on it.
If e.KeyCode = Keys.Enter Then
Console.WriteLine("Enter")
If TextBox1.Text.IndexOf("beep") > 0 Then
ToolStripStatusLabel1.Text = "Word Found"
MsgBox("Word Found")
ElseIf TextBox1.Text.IndexOf("bing") > 0 Then
ToolStripStatusLabel1.Text = "Word Found"
MsgBox("Word Found")
Else
ToolStripStatusLabel1.Text = "Word Not Found"
End If
One option is to use a list of strings and then a loop to see if any of the words in list match with the textbox content.
ASKER
HEADING: Ok, i found a bug... can an Expert please help?
A workaround was to simpley popluate the Textbox at startup, then, once ENTER is hit, words seems to ping up once detected.
Anyone got any further ideas?
Thanks,
Rob
A workaround was to simpley popluate the Textbox at startup, then, once ENTER is hit, words seems to ping up once detected.
Anyone got any further ideas?
Thanks,
Rob
ASKER
Hi CC,
I've intergrated another piece of code (which you resolved previously); which is where this project is leading. My issue here is with:
txt = InputBox("Enter IP_Address")
and
.Arguments = "/C ping" &Â txt
No ping results returned from input box.
IF I SET TO YOUR ORIGINAL EXAMPLE, IT WORKS.
.Arguments = "/C ping xx.xx.xx.xx"
I'm boosting Points on this!!!!!!
I've intergrated another piece of code (which you resolved previously); which is where this project is leading. My issue here is with:
txt = InputBox("Enter IP_Address")
and
.Arguments = "/C ping" &Â txt
No ping results returned from input box.
IF I SET TO YOUR ORIGINAL EXAMPLE, IT WORKS.
.Arguments = "/C ping xx.xx.xx.xx"
I'm boosting Points on this!!!!!!
If e.KeyCode = Keys.Enter Then
Console.WriteLine("Enter")
If TextBox1.Text.IndexOf("ping") > 0 Then
ToolStripStatusLabel1.Text = "Word Found"
REM MsgBox("Word Found")
txt = InputBox("Enter IP_Address")
' ping experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_26931696.html
Dim ps As New Process
With ps.StartInfo
.FileName = "cmd.exe"
.Arguments = "/C ping" & txt
ToolStripStatusLabel1.Text = txt
.CreateNoWindow = True
.UseShellExecute = False
.RedirectStandardOutput = True
End With
ps.Start()
ps.WaitForExit()
Dim output As String = ps.StandardOutput.ReadToEnd()
ps.Close()
TextBox1.Text &= (output)
>.Arguments = "/C ping" &Â txt
Could it be because you are missing a space?
.Arguments = "/C ping "Â & txt
Could it be because you are missing a space?
.Arguments = "/C ping "Â & txt
ASKER
Hi CC,
Yes, that was it - thanks man.
I wonder if you know how to stop the action... so i:
1. type in ping
2. press enter
3. inputbox
4. ping results pop into textbox.
5. IF I TYPE IN ANYTHING ELSE (RANDOM) &Â PRESS ENTER >Â I DON'T WANT IT TO PING.
>Â CANCEL INPUTBOX ON ENTER-KEY
I'm guessing it's something to do with the process? but ps.close already happens.
Thanks,
Roberto
Yes, that was it - thanks man.
I wonder if you know how to stop the action... so i:
1. type in ping
2. press enter
3. inputbox
4. ping results pop into textbox.
5. IF I TYPE IN ANYTHING ELSE (RANDOM) &Â PRESS ENTER >Â I DON'T WANT IT TO PING.
>Â CANCEL INPUTBOX ON ENTER-KEY
I'm guessing it's something to do with the process? but ps.close already happens.
Thanks,
Roberto
ASKER
> CANCEL INPUTBOX ON ENTER-KEY - unless i purposely type ping again.
is this a loop?
is this a loop?
Not sure I understand you question. Do you only want to run code if you type ping in textbox?
ASKER
Yes, that's it!
Type PING> enter key
Start process
Result
End process
Type PING> enter key
Start process
Result
End process
Your code is inside
If TextBox1.Text.IndexOf("pin g") >Â 0 Then
so it should not execute if anything other than ping is typed.
If TextBox1.Text.IndexOf("pin
so it should not execute if anything other than ping is typed.
ASKER
Sorry CC,
I'll sort this out this weekend - promise... been on holiday :)
I'll sort this out this weekend - promise... been on holiday :)
No problem. Hope you enjoyed your holidays.
ASKER
Hi CC,
Sadly it's still not working...
1. I type PING
2. Inputbox... type = Â IP Address xx.xx.xx.xx
3. result
4. if i type in anything (i.e. Boo)... press enter... I get the Inputbox
:(
Sadly it's still not working...
1. I type PING
2. Inputbox... type = Â IP Address xx.xx.xx.xx
3. result
4. if i type in anything (i.e. Boo)... press enter... I get the Inputbox
:(
>If TextBox1.Text.IndexOf("pin g") >Â 0 Then
This should not have worked. If ping is the only work then IndexOf will return 0. If not found, it returns -1.
I have just tested this and it works.
This should not have worked. If ping is the only work then IndexOf will return 0. If not found, it returns -1.
I have just tested this and it works.
ASKER
Can i ping the other VM - yes I think so - yes
ASKER
oops- ignore - lol
ASKER
Hi CC,
Sorry about the wait... I've wonder if you could take a look at this vid I put together and see where I'm going wrong?
Thanks,
Roberto
ping-test-notepad.zip
Sorry about the wait... I've wonder if you could take a look at this vid I put together and see where I'm going wrong?
Thanks,
Roberto
ping-test-notepad.zip
Hmm. You did not mention this before that its a multiline text box.
You would need to do something like below
If TextBox1.Text.EndsWith("pi ng") Then
You would need to do something like below
If TextBox1.Text.EndsWith("pi
ASKER
WOW - thanks CC, that's done the trick - sorry I should have mentioned multiline TB...
i last thing if i may...
have the type cursor move to the bottom, ready to type again... currently, it stays on the top line.
i last thing if i may...
have the type cursor move to the bottom, ready to type again... currently, it stays on the top line.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you sooooo much CC
;)
;)
Start with this....
and add from here.
This case looks for keystrokes and highlights the word based on logic.
You can expand from here.
It's JQUERY, so it runs in the client.
Open in new window