Home > Software engineering >  VB how to realize continuous query condition are satisfied
VB how to realize continuous query condition are satisfied

Time:10-23

Deep haunts me, there is a problem,, but I am a novice, not done similar project, so, have to come to CSDN,,

I want to realize this function: in a process, when to meet certain conditions, I will perform a piece of code, judgment conditions, there are two, three or more, after thinking, check I came up with several programs: the following

1. Use a timer, whether conditions to meet
Private Sub Timer1_Timer ()

If condition 1=True And condition 2=True And 3=True Then
. Execute the code..
End the If

End Sub

2. Write your own an infinite loop
Public Sub power ()
Dim Condition As Boolean
Condition=True 'has set itself a loop Condition
Do the While Condition=True 'unceasing cycle to judge whether meet the conditions, once meet Condition is executed I think code

If condition 1=True And condition 2=True And 3=True Then
. Execute the code..
End the If

Loop
End Sub

But I found that programming, using the above two methods will make the program died, the other CPU utilization rate up to 50%. Don't know is there any other way, to keep circulation judgment conditions are met, as soon as conditions meet the requirements of I, is executed to code!!!!




CodePudding user response:

On the "event" by...

CodePudding user response:

Timer, won't make program die,

The second method, can add a Sleep (10);

CodePudding user response:

refer to the second floor caozhy response:
, won't make program timer die,

The second method, can add a Sleep (10);

1. Use the timer will increase the burden of CPU, because I'm real-time demand is higher, when the timer time constant is 1 ms
let alone?2. Add after sleep is still the same, suspended animation program, other buttons on the interface can't operation

CodePudding user response:

reference 1st floor Topc008 response:
against "events" on the...

How to "event" on? Please give me a small example, the instance of what, don't understand ah,,,,,,,,,,, prawn shrimp shrimp, shrimp ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

CodePudding user response:

reference rewsna3 reply: 3/f
Quote: refer to the second floor caozhy response:

Timer, won't make program die,

The second method, can add a Sleep (10);

1. Use the timer will increase the burden of CPU, because I'm real-time demand is higher, when the timer time constant is 1 ms
let alone?2. Add after sleep is still the same, suspended animation program, other buttons on the interface can't operate

How do these conditions be changed?

CodePudding user response:

Either you give complete code, or your own, examples on "VB programmers guide" I said,

CodePudding user response:

In circulation processing timely release of the system control:
 Public Sub power () 
Dim Condition As Boolean
Condition=True 'has set itself a loop Condition
Do the While Condition=True 'unceasing cycle to judge whether meet the conditions, once meet Condition is executed I think code

If condition 1=True And condition 2=True And 3=True Then
. Execute the code..
End the If
DoEvents' * * * * *
Loop
End Sub

In general, the Timer scheme should not cause "suspended animation", unless you set the interval too short,

CodePudding user response:

Don't know how your condition, guess:
With n label control storage conditions of n values, then through Label1_Change event whether it n label value meet the requirements of you, if met, will perform certain code,

, of course, also can be defined class module from events, more flexible...

CodePudding user response:

Main such questions is very bad.

You at least say a understand your requirement, how often do you need to determine, for example, determine what conditions, is from where judgment conditions and so on. As for your post code is secondary. No telling.

Don't say, you take out a condition, the dripping wet is not difficult.

CodePudding user response:

reference rewsna3 reply: 3/f
Quote: refer to the second floor caozhy response:

Timer, won't make program die,

The second method, can add a Sleep (10);

1. Use the timer will increase the burden of CPU, because I'm real-time demand is higher, when the timer time constant is 1 ms
let alone?2. Add after sleep is still the same, suspended animation program, other buttons on the interface can't operate

If so, the res VB to do, the timer minimum around 20 ms, again small didn't make much sense, ran an empty event is also spend a lot of time,

CodePudding user response:

Should be a data acquisition program of class, I feel to consider other people's thing, sampling frequency, and then to do you need speed, requires quick can use C to do, VB this, try to break down into smaller and time-consuming process to invoke,
For example,
If condition 1=True And condition 2=True And 3=True Then
. Execute the code.. (run to spend a year)
End the If
And say, I want my programs faster, so how to give you advice?
If this part of the code to run for more than 100 ms word you need to find a way to break down,
  •  Tags:  
  • API
  • Related