|
-
May 15th, 2010, 01:15 PM
#1
Thread Starter
Member
[RESOLVED] Visual Basic Command Button Problem
hi,
i just want to ask what is the right code for this,
for example i have a command button and instead of clicking it by the mouse the keyboard enter key will do the job,
i mean you can click the command button by mouse and also you can use enter to execute the command?
sorry im really a noob about this,
i know this isnt my line, its just my hobby
thanks
-
May 15th, 2010, 01:33 PM
#2
Re: Visual Basic Command Button Problem
Welcome to the forums. Yes, ensure button has the focus first.
-
May 15th, 2010, 01:37 PM
#3
Re: Visual Basic Command Button Problem
You may set button's Default property to True however be aware that it may create some side effects.
-
May 15th, 2010, 01:38 PM
#4
Thread Starter
Member
Re: Visual Basic Command Button Problem
sir did you i need to add this
am i correct?
sorry
and thanks sir for welcoming me
-
May 15th, 2010, 01:44 PM
#5
Re: Visual Basic Command Button Problem
You need to Tab through the controls until the rectangular focus marker gets on the button you want to 'click'.
If you have an input form for example, a few text boxes and an OK/Cancel buttons, you can use the Keypress event of the textboxes to catch the enter and execute the OK if the user presses Enter in one of the textboxes.
-
May 15th, 2010, 01:48 PM
#6
Re: Visual Basic Command Button Problem
Did anyone see my reply in post #3?
-
May 15th, 2010, 01:52 PM
#7
Re: Visual Basic Command Button Problem
Yeah, but we're ignoring you. J/k His solution will probably depend on what the form does and looks like. If it is simple with only a few buttons, like an input form or something withat a few command buttons (Yes/No, Yes/No/Cancel etc) the Default property should more than ok.
-
May 15th, 2010, 01:53 PM
#8
Re: Visual Basic Command Button Problem
 Originally Posted by baja_yu
Yeah, but we're ignoring you. J/k  ....
I know; that's why I was sarcastic... 
On more serious note Default can work but definitely like you said depends on the entire design.
-
May 15th, 2010, 02:10 PM
#9
Thread Starter
Member
Re: Visual Basic Command Button Problem
hehehe
sorry guys for being such a noob, 
im really a newbie
@Baja_yu
yes i understand now sir,
yes i have command button and a textbox,
if i put something on text box i have to press the command button to execute the command,
i try the keypress event it doesnt work :-?
or maybe i have a mistake on it?
@sir Rhino
You may set button's Default property to True however be aware that it may create some side effects.
Sir i will try but what side effects may occur sir?
well i will just try and find out
thank you all for the response
i really apreciate you answer a question from a noob like me
-
May 15th, 2010, 02:18 PM
#10
Re: Visual Basic Command Button Problem
 Originally Posted by eyestrain
well i will just try and find out
Yea, you just do that and please stop saying that "sir" thing...
-
May 15th, 2010, 03:10 PM
#11
Re: Visual Basic Command Button Problem
This is how you would do it with the KeyPress method
Code:
Option Explicit
Private Sub Command1_Click()
MsgBox "button was clicked"
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then 'Enter
Call Command1_Click
End If
End Sub
Now, when you press Enter while typing in the text box, the click event of the command box will fire and the message box will be shown. Just an example, you can modify it to suite your needs.
-
May 16th, 2010, 02:07 AM
#12
Thread Starter
Member
Re: Visual Basic Command Button Problem
@baja_yu
thanks it is now working,
thanks sir LaVolpe, sir Rhino and sir Baja_yu for the great help
please expect me to ask more question in the future, i really appreciate everything
your unwavering assistance is a big help to this community
regards
-
May 16th, 2010, 07:36 AM
#13
Re: Visual Basic Command Button Problem
No problem! 
Like Rhino said before, you don't have to call us sir. Also, if your question is answered, please take time to mark the thread as 'Resolved'. You can do so by going to the Thread Tools menu which is on the right side, above your original post, and choosing Mark Thread Resolved.
-
May 16th, 2010, 10:04 PM
#14
Frenzied Member
Re: [RESOLVED] Visual Basic Command Button Problem
Since "Call" is optional, forget you ever saw it 
I've heard that using Call is bad coding habits / excess memory. Looking for the source now,
-
May 17th, 2010, 01:56 AM
#15
Re: [RESOLVED] Visual Basic Command Button Problem
I'd love to see the info on that.
There's a very, very limited scenario under which a memory leak can occur, but is limited to functions that pass Arrays as return values. It's described here http://support.microsoft.com/kb/q197190/
There are a lot of other good uses for Call, for example, when you don't need the return value from the function etc.
Other than that, since it's optional, I guess it comes down to personal preference/stlyle.
EDIT: In fact, the memory leak only happens if the call is implicit to UBound or LBound like described in the test. If you explicitly Call the ArryFunc in the example, there is no leak.
Last edited by baja_yu; May 17th, 2010 at 03:02 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|