How to deal with enter to tab in vb6? -
public function entertotab(keyascii integer) if keyascii = vbkeyreturn sendkeys "{tab}" keyascii = 0 end if end function private sub txtusercode_keypress(keyascii integer) call entertotab(keyascii) end sub
- this code belongs log-in form.
- the
txtusercode
contains code of specific user stored in database. - while running form, when enter number in
txtusercode
, press enter doesn't go next text box, it's keyascii became 49 not equal 13. - the same thing happening pressing tab.
what switching next text field using setfocus
method instead of simulating tab?
private sub txtusercode_keypress(keyascii integer) if (keyascii = vbkeyreturn) txtnexttextfield.setfocus end if end sub
you use controls array (array of text fields contained in form) , increment index. use code text fields of form without having write redundant code.
so if user presses return in text field index 0, set focus index+1 (=1). create controls array, copy first text field , paste form. vb6 ask whether want create controls array. if click "yes", automatically. can use following code:
private sub txtfield_keypress(index integer, keyascii integer) if (keyascii = vbkeyreturn) if ((index + 1) < txtfield.count) txtfield(index+1).setfocus else msgbox "reached end of form!" end if end if end sub
Comments
Post a Comment