Solved

push button

Posted on 2001-07-29
20
355 Views
Last Modified: 2010-05-18
I need a push button, that means i need my command button make event untill the user push it, as you know when we push a command component and hold it, it just makes one event.

thanks
hamed
0
Comment
Question by:h_mohsenian
  • 8
  • 5
  • 3
  • +4
20 Comments
 
LVL 5

Expert Comment

by:jklmn
ID: 6331872
Hi,

Do you mean this:

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MsgBox "Pushing."
End Sub
0
 
LVL 1

Author Comment

by:h_mohsenian
ID: 6332025
no! your code just calls one time.for example suppose that i have a Text and a command now if we exec this code :

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Text = Str$(Val(Text1.Text) + 1)
End Sub

and push the command and hold it Text1.Text just increment one time, but i want it start to incrementing and contineu untill i finish holding the command button!

i hope u understand the problem ! if it is not enouph please tell me

best regards
hamed
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6332051
Add a timer control. Put the code that you want repeating in it's _Timer event. Set the interval to how fast you want it to repeat.

Private Sub Command1_MouseDown(...)
Timer1.Enabled = True
End Sub
Private Sub Command1_MouseUp(...)
Timer1.Enabled = False
End Sub
0
 
LVL 1

Author Comment

by:h_mohsenian
ID: 6332086
yes , it can work ( thanks alot ). but i have a lot of commands . becouse i have a keyboard for a PC-based control System.like some devices in an industial place that controlled by computer and the keyborad is the user interface. if i use ur method it will be uncleared. i think u are agree with me. but if we could build a <One> independent command button with an internal Timer it is good. but i think it must be some better ways!

thanks
hamed
0
 
LVL 1

Author Comment

by:h_mohsenian
ID: 6332107
I can build a Tbutton with internal timer in Delphi ( I am a Delphi programmer not VB ) . and make activex and use it in VB. but this question is not for me I ask it for my friend and he just studied VB. and it will be make problems to him .

therefor i think you ( VB programmers ) can make a New Command Component with a internal timer with the same action that KDivad said . but stile i think there must be a better way!

best regards
hamed
0
 
LVL 3

Expert Comment

by:adg
ID: 6332226
I'm sorry if the following is too much detail - I don't know anything about Delphi so I'm not sure if this is a similar process.  

This is an implementation of a VB ActiveX control.  Create an activex control project (an option when creating a new VB project).  Put a timer and a commandbutton on it and paste the following code marked as EXHIBIT A into it. Then close all the project windows but do not exit the IDE. It is important to close all the windows associated with project1.  

Open another project in the same IDE session.  It will probably be called project2. So now you have project1 containing the usercontrol and project2 which will use the control.  Right-click on project2 and make it the start-up project.  A new icon was added to the bottom of the toolbox called UserControl1. Drag the newly created control from the toolbox to Form1 in project2.  Open the form and paste the following short code marked as EXHIBIT B into it.  

Now Save the project group and run it. Clicking on the usercontrol1 (which is a wrapper for the command button) will repeatedly fire the PushFire event, which I think is what you want.

Hope it helps!


---------------------------------------------
'UserControl1.ctl  - EXHIBIT A

Option Explicit

Private iPushInterval As Integer

Event PushFire()

Private Sub UserControl_Initialize()
    Timer1.Enabled = False
    PushInterval = 200
End Sub

Private Sub command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
       Timer1.Enabled = True
    End If
End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
       Timer1.Enabled = False
    End If
End Sub

Private Sub Timer1_Timer()
    RaiseEvent PushFire
End Sub

Private Sub UserControl_Resize()
    Command1.Move 0, 0, Width, Height
End Sub

Public Property Get PushInterval() As Integer
    PushInterval = iPushInterval
End Property

Public Property Let PushInterval(ByVal iNewValue As Integer)
    If iNewValue > 0 And iNewValue < 65500 Then
        iPushInterval = iNewValue
        Timer1.Interval = iPushInterval
    End If
End Property
-------------------------------------------------------

'Form1.frm - EXHIBIT B

Option Explicit

Private Sub UserControl11_PushFire()
    Debug.Print "PushFire " & CStr(Rnd)
End Sub
0
 
LVL 3

Expert Comment

by:Bahnass
ID: 6332325
Dear h_mohsenian
1-    Would U Pls. try checkbox
    but change property   Style = Graphical
   it will look just like a button
2 - I agree to Have special Timer  as mentioned
3- if U have many buttons try a control array that makes U write one event code

I hope that helps
Best regards
0
 
LVL 4

Expert Comment

by:nutwiss
ID: 6332549
have you thought of using a scrollbar or an up/down control instead of a standard command button to set values?
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6332569
It would be easy enough to create a control in VB that looks and acts like a command button. Essentially an ActiveX control, but embedded in the project. I just did so to make sure I knew what I was talking about. Basically, you set the interval property to whatever you wish the delay to be and then use it essentially the same as you would a normal command button. Other than that, he can just replace his commandbuttons with this tbutton.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6332571
Oh, duh, one other thing: If it sounds good, I'll post the file here.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 3

Expert Comment

by:adg
ID: 6332587
If it's a useful technique and it has some benefit over the one I've already posted, then why not go ahead and post it anyway?  Even if h_mohsenian can't use it, maybe someone looking at this question in the future might benefit...
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6332617
The method I've already described, the file is simply a longer way of saying the same thing. It is essentially the same as yours, just a bit "fuller" (I included more of the most likely properties and methods). Also, I raise the click event (instead of pushfire) to simplify control replacement. I see no need to post what is little more than an expanded duplicate of yours and which I already described unless interest is expressed (by anyone) to give me a reason to bloat this thread (more than EE has already done.)

Someone looking at this thread in the future can simply post a new message. My email address is unlikely to change (reroute from a private domain to my current address) so I will get the notif that a post has been made.
0
 
LVL 3

Expert Comment

by:adg
ID: 6332769
Now that you mention it, I think I see your point.  I took your suggestion and coded it into an activex control.  I didn't know that you were going to follow up with one yourself or I wouldn't have done that.  

0
 
LVL 5

Expert Comment

by:KDivad
ID: 6332780
That's OK, I didn't know myself that I as going to. When I got the email notif from this thread after I had posted, I decided then to write it and post when I checked on the latest comments.

If h_mohsenian decides he likes the activex idea, you're welcome to the points. I only show up here to help. I don't object to getting the points, but I really don't care as long as the asker is helped.
0
 
LVL 5

Accepted Solution

by:
KDivad earned 100 total points
ID: 6332790
Regarding an earlier post:

I think this is the easiest way to do this. While there are several available methods, the others (that I know of) just get more and more complex. One (subclassing), if it would work, has the potential to crash VB if you aren't careful.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7161651
Hi h_mohsenian,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept KDivad's comment(s) as an answer.

h_mohsenian, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Author Comment

by:h_mohsenian
ID: 7162769
hi ,
As I told before in my question I am a Delphi programmer NOT a VB programmer ( THEREFOR DIRECT CODE COULD HELP ME ) and it was a question for helping my friend (not for myself). unfortunately I could not help him and he solved his problem himself! Therefor I can not be sure that which was the good answer. BUT maybe you are right and KDivad's answer is good. NOW if you want I will accept it.
Also why not I will accept it right now.BUT they did not help me as a some one who is not VB programmer.

THANKS for all of my friend's comments.

Hamed
0
 
LVL 5

Expert Comment

by:KDivad
ID: 7163973
<<BUT they did not help me as a some one who is not VB programmer.>>

And you did not come back and tell us that you needed the control that would solve the issue. Had you expressed interest in the control I mentioned (and spent the time to write), I would have posted it and you would have received your help.

1. The control I wrote did imitate a keypress and even accessed Windows' settings for the keyboard repeat delay and repeat speed, so I suppose my getting the points was warranted.

2. If you decided we did not help, you could have asked for your points refunded and the question PAQ'ed.

3. If your friend is writing a VB app, surely this info would have helped him out even without the actual code.

4. Finally, why give me the points if you don't know if I helped?


KDL

Don't blame us when it's your fault for not returning.
0
 
LVL 1

Author Comment

by:h_mohsenian
ID: 7164079
Take it easy my friend. I did not want to do anything to insult you. ( if I done it ,realy sorry ) but I think you can understand me. there are two facts 1.the comments coult not help me in <that time> ( by any cause ) 2. I did not forget the question ( just I passed it because my friend solved himself )

Now why did I accept your comment ? because they told me it was perfect and there was a problem in me to understand it. Therefor I HAVE TO accept it because it was my duty to do it ;-)

Anyways , we are here to help our friends and just friendly talking :-) . I know that my reaction was not so good but I told about it.

sorry that I wasted you time. see you again in other programming groups ( Delphi or VC but not VB ;-) )
Hamed ;-)
0
 
LVL 5

Expert Comment

by:KDivad
ID: 7164580
You didn't insult me, don't worry about that. I must apologize for over-reacting, I've had a really bad couple of weeks.

<<Now why did I accept your comment ? because they told me it was perfect and there was a problem in me to understand it. Therefor I HAVE TO accept it because it was my duty to do it ;-)>>

Actually, you are wrong there. If anything can be defined as your duty, it was to ask for clarification. The idea behind EE is for you to ask about the answer until it makes sense to you. If you don't ask, you don't learn. Most users simply give a bad grade and say that they did it because they didn't understand the answer. Then why accept at all? If you were to look at some of my questions, you'd find that I pester the experts until I figure it out.

You didn't waste my time. I wasn't sure about making activex controls at the time so I learned by helping.


You won't see me around! The only time I show up here anymore is to hunt down something I remember seeing and want to look at again or I get an email indicating that a thread I was in had a new post made. EE has just gotten way too slow for my taste and I'm tired of waiting on it to load (though it is better than it was a few months ago!)

Later,
KDL
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now