Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Code to make Enter key act like Tab

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,35487
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Code to make Enter key act like Tab
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Code to make Enter key act like Tab - 6/16/2006 12:58:30 AM   
  zeg37

 

Posts: 15
Score: 0
Joined: 6/16/2006
Status: offline
I am working with a data access page and I have an unbound text field that is used to search for specific records from my database.  I would like to limit the amount of text a user can type into the field, or better yet write code to cause the enter key to respond like a tab key.  I've found a variety of java code and some visual basic code for changing the enter key, but haven't had any success getting it to run.  I would prefer to use VBScipt if possible.  I've tried many variations of the code below without success:

<Script language=vbscript event=onkeypress for=vProject>
<!--
      Sub vProject_KeyPress (KeyAscii as Integer)
      If KeyAscii = 13 then
      KeyAscii = 0
      Sendkeys "{TAB}"
      End If
      End Sub
-->
</SCRIPT>
 
Any suggestions would be greatly appreciated.
 
Zeg
 
 
Post #: 1
 
 RE: Code to make Enter key act like Tab - 6/16/2006 2:23:20 AM   
  mikeock


Posts: 124
Score: 1
Joined: 6/8/2006
Status: offline
The first issue that i see with your code, is that appers you are trying to attempt VB syntax in VBS.
the reason I say this is becuse you have KeyAscii as Integer).
VBS does not allow you to declare the type of variable they are all seen as variant type.


So instead make the line Sub vProject_KeyPress (KeyAscii) .

The other thing that I would look at, is the onkeypress event. I can't quite recall how to use this but I do believe the syntax you have is incorrect.

May8be check out Microsft's Script center page and look at the HTA section.

Hope this Helps!

Mike

_____________________________

My sig sucks!

(in reply to zeg37)
 
 
Post #: 2
 
 RE: Code to make Enter key act like Tab - 6/16/2006 2:38:47 AM   
  zeg37

 

Posts: 15
Score: 0
Joined: 6/16/2006
Status: offline
Mike,

I'm pretty new to writing code, so I'm not surprised that there is error in my syntax.  I pretty much cobbled the code together with what little info I could find.  Thanks for your response.

Zeg

(in reply to mikeock)
 
 
Post #: 3
 
 RE: Code to make Enter key act like Tab - 6/16/2006 3:00:23 AM   
  mikeock


Posts: 124
Score: 1
Joined: 6/8/2006
Status: offline
Zeg,

also to do a sendkeys method you need to create the object to do the sendkeys.
Something along these lines:
Set WshShell = Wscript.CreateObject("Wscript.Shell")

then to do your sendkeys you do a
WshShell.Sendkeys "{TAB}"

so it would look more like this

Sub vProject_KeyPress (KeyAscii)
  Set WshShell = Wscript.CreateObject("Wscript.Shell")
  If KeyAscii = 13 then
     KeyAscii = 0
      WshShell.Sendkeys "{TAB}"
  End IF
  Set WshShell = nothing
End sub

_____________________________

My sig sucks!

(in reply to zeg37)
 
 
Post #: 4
 
 RE: Code to make Enter key act like Tab - 6/16/2006 4:35:33 AM   
  zeg37

 

Posts: 15
Score: 0
Joined: 6/16/2006
Status: offline
Mike,

First, let me say a huge "THANKS" for your assistance.  I've spent hours trying to figure out how to make this work.

On that note,  I tried the code in your last post and received a variety of invalid character errors. One was for a empty space which I seemed to have eliminated by using the delete key until the next line of code moved up a line.  (I did drop that line back down.) Then the invalid character was the "=" in the line:

KeyAscii = 0

I wasn't quite sure how to fix that. 

Obviously I need to gain better proficiency in VBScript.  Any books you can recommend for someone who has had little or no programming experience?  Most online tutorials don't go beyond the very basics while the books seem to be written on the assumption that the reader already has experience (usually in visual basic).  I'd like to gain some understanding of what I'm writing (okay...copying and pasting) and why it does or doesn't work.

Again, thank you for our help.  It's much appreciated.

Zeg

(in reply to mikeock)
 
 
Post #: 5
 
 RE: Code to make Enter key act like Tab - 6/16/2006 7:28:36 AM  1 votes
  mikeock


Posts: 124
Score: 1
Joined: 6/8/2006
Status: offline
The two books that I use for vbscript are VBScript programmers reference (Wrox bout $34.95) and VBS in a nutshell (o'rielly bout $24.95).


The wrox book has a lot of examples and breakdowns. I use the nutshell book more a s a quick reference for a function.

Back to the issue. I don't think that the line KeyAscii = 0 is required... Try it without it and see what happens!

Let me know if you need further assistance!

_____________________________

My sig sucks!

(in reply to zeg37)
 
 
Post #: 6
 
 RE: Code to make Enter key act like Tab - 6/16/2006 7:49:45 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
If this is being done in a web page, then here is how I handle this situation (I hate sendkeys). First I make sure that the tabindex property is set for all the controls that I want to be ablr to tab through and that the indices are in the proper order. Next in the OnKeypress event sub for each control I put this:

           Sub vProject_OnKeyPress(oKey)
               If oKey.KeyCode = 13 Then
                   GotoNextTab(window.event.srcElement.TabIndex)
               End If
           End Sub

Then I have this sub somewhere in my code:

           Sub GotoNextTab(nTab)
               Dim oNode
               For Each oNode In document.all
                   If oNode.TabIndex = nTab + 1 Then
                       oNode.Focus
                   End If
               Next
           End Sub

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to mikeock)
 
 
Post #: 7
 
 RE: Code to make Enter key act like Tab - 6/19/2006 1:45:36 AM   
  zeg37

 

Posts: 15
Score: 0
Joined: 6/16/2006
Status: offline
Thanks for your response.  I am working with a web page that was created as an Access DAP (data access page).  I inherited this project and am a real novice at writing code.  That said, I copied your code within the script blocks automatically generated by Microsoft’s Script Editor.   I’m getting Invalid Character errors on lines in red - it’s my understanding that <!-- and --> are VBScript conventions so the error message is throwing me.  I tried the code without them, and got the same error messages. Frankly, it is sheer stubbornness that is driving me at this point.  It may just be my lack of experience but it seems that even though  DAP’s were created to use VBScript, straight forward code just doesn’t work like it would on a regular web page.

 
<SCRIPT language=vbscript >
<!--
Sub vProject_OnKeyPress(oKey)
           If oKey.KeyCode = 13 Then
            GotoNextTab(window.event.srcElement.TabIndex)      
           End If           
           End Sub
-->
</SCRIPT>
<SCRIPT language=vbscript>
<!--
Sub GotoNextTab(nTab)               
            Dim oNode               
            For Each oNode In document.all
                        If oNode.TabIndex = nTab + 1 Then
                           oNode.Focus
                        End If     
            Next          
End Sub
-->
</SCRIPT>
 
 

(in reply to ebgreen)
 
 
Post #: 8
 
 RE: Code to make Enter key act like Tab - 6/19/2006 2:02:38 AM   
  mikeock


Posts: 124
Score: 1
Joined: 6/8/2006
Status: offline
<!-- --> is an html comment tag.
Dunno if it shoudl work within the script tag or not

_____________________________

My sig sucks!

(in reply to zeg37)
 
 
Post #: 9
 
 RE: Code to make Enter key act like Tab - 6/19/2006 2:51:06 AM   
  zeg37

 

Posts: 15
Score: 0
Joined: 6/16/2006
Status: offline
Rob -

Okay, significant note to self...don't copy and paste the code, type it out!  Frustrated with the error messages I was receiving, I deleted the code I had pasted from your post and typed it in.  No more error messages and it WORKS!

Many, many thanks to you and Mike for all your help. 

Deb

(in reply to mikeock)
 
 
Post #: 10
 
 RE: Code to make Enter key act like Tab - 6/19/2006 2:55:52 AM   
  zeg37

 

Posts: 15
Score: 0
Joined: 6/16/2006
Status: offline
Mike -

Thanks for your input on this problem - I really appreciate the time you spent trying to help me find a solution.  I will look for the books you recommended and hopefully I'll be writing code myself in the future.

Thanks again!


(in reply to zeg37)
 
 
Post #: 11
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Code to make Enter key act like Tab Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts