By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,484 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

Replacing Text Automatically - VB8

P: 3
This was asked on CodeProject also but I haven't received a working reply so am posting here. The only reply I did get there suggested using "e.Handled = true" but that didn't work no matter where I put it.

Below is the section I'm having trouble with at the moment:

Expand|Select|Wrap|Line Numbers
  1.     Friend Sub glbHooks_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles glbHooks.KeyPress
  2.         newStr = newStr & LCase(e.KeyChar)
  3.         n = 0
  4.  
  5.         If e.KeyChar = vbBack Then
  6.             tmpStr = ""
  7.             For i = 1 To newStr.Length
  8.                 If i < newStr.Length - 1 Then tmpStr = tmpStr & newStr.Substring(i - 1, 1)
  9.             Next
  10.             newStr = tmpStr
  11.         End If
  12.  
  13.         If newStr.Length = 4 Then
  14.             If newStr(3) = "-" Then
  15.                 If InStr(rkSet, newStr) Then
  16.                     n = 1
  17.                     My.Computer.Keyboard.SendKeys(Chr(8) & Chr(8) & Chr(8) & dicRepStr(newStr))
  18.                     newStr = ""
  19.                 End If
  20.  
  21.             End If
  22.  
  23.             tmpStr = ""
  24.             For i = 1 To newStr.Length
  25.                 If i <> 1 Then tmpStr = tmpStr & newStr.Substring(i - 1, 1)
  26.             Next
  27.             newStr = tmpStr
  28.         End If
  29.  
  30.         If n = 1 Then
  31.             Sleep(100)
  32.             My.Computer.Keyboard.SendKeys(Chr(8) & " ")
  33.         End If
  34.     End Sub
  35.  
What this is supposed to do is replace a 4-char usercode with user's choice of text. It works great but it adds a dash {-} at the end of the replacement text. The user chooses which symbol is the trigger and in my tests I'm using the dash. Which means the program is including the last-typed character.

I added the last "If" statement to try and remove it then add a space but it does no good. It just puts the dash AFTER the space.

Also, if I put "If n = 1 Then My.Computer.Keyboard.SendKeys(Chr(8))" at the beginning of this Sub then it will remove the dash after typing the next character. BTW the "Chr(8)" I tried when the "vbBack" wasn't taking out the dash, that's the only reason it's there now. Also, I originally had 4 "vbBack" {Chr(8)} in the replacing portion but have changed it around to try to get rid of that final character.

How do I get it so it won't send the dash {or whatever is chosen as the trigger symbol}?

Also, if I put a msgbox in that section then it doesn't put in the trigger character.
--> MsgBox("")
So is there a way to spoof a message box or something similar? I don't want to have to click "Okay" on the message box every time I use the hotkeys. I've tried sleep {for 100 & 500} but it didn't work.

Any help in this would be appreciated!

Peace to you and yours,
Matthew "Dra'Gon" Stohler
Mar 25 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.