Home > Software engineering >  For loop in response to the enter key
For loop in response to the enter key

Time:09-17

I think in the For loop each time you press the enter key or delay after the execution a TextBox1 and TextBox2 comparison, excuse me what method can be implemented?

CodePudding user response:

Add a line of doevents loop body

CodePudding user response:

Use the GetAsyncKeyState this API

CodePudding user response:

Why in the loop?
Enter the comparison on the KeyPress event response is good
Delay after the comparison can be placed in the Timer, Timer interval is what you want to delay time,

CodePudding user response:

Don't forget, VB is event driven,

CodePudding user response:

For loop plus a while loop within

Roughly as follows

Dim BiaoJi as Boolean=false

For I=0 to 10

While booblean=false

DoEvents

'
of program at this time in an infinite loop'you can according to your actual condition to judge the keys
'is to obtain the global keys or forms to get key?

End while

Next I

I think your question is how to in the loop body get key information, rather than the other problems, because I am a cell phone back to stick son, so the code given is not complete, you can combine with others given the code combination can solve your problem,

CodePudding user response:

refer to 6th floor qq_35328269 response:
add a while loop within a for loop

Roughly as follows

Dim BiaoJi as Boolean=false

For I=0 to 10

While booblean=false

DoEvents

'
of program at this time in an infinite loop'you can according to your actual condition to judge the keys
'is to obtain the global keys or forms to get key?

End while

Next I

I think your question is how to in the loop body get key information, rather than the other problems, because I am a cell phone back to stick son, so the code given is not complete, you can combine with others given the code combination can solve your problem,
there are people who such code? Overlapping
VB is event driven, buttons have a KeyPress events, delay can use the Timer event,
Ask, "' you can according to your actual situation to determine key" how to use the code?
Don't tell me, setting up a KeyPress event to set the variable, then in cyclic code processing,
Don't put the idea to apply directly to the VB, C

CodePudding user response:

An example, in the infinite loop timing to extract data for processing,
New forms, throw a timer, a command and then paste the following code,
 
Option Explicit

Private Sub Command1_Click ()
Timer1. Per delay Interval=1000 '1000 milliseconds (inaccurate) on a processing
Timer1. Enabled=True
The Do While 1=1 "infinite loop
Command1. Caption=Rnd () 'random number displayed on the button
DoEvents
Loop
End Sub

Private Sub Timer1_Timer ()
Form1. Print Now () & amp; Command1. Caption 'timing processing logic: the form in the Numbers shown on the print button
End Sub


CodePudding user response:

refer to 7th floor of123 response:
Quote: refer to the sixth floor qq_35328269 response:

For loop plus a while loop within

Roughly as follows

Dim BiaoJi as Boolean=false

For I=0 to 10

While booblean=false

DoEvents

'
of program at this time in an infinite loop'you can according to your actual condition to judge the keys
'is to obtain the global keys or forms to get key?

End while

Next I

I think your question is how to in the loop body get key information, rather than the other problems, because I am a cell phone back to stick son, so the code given is not complete, you can combine with others given the code combination can solve your problem,
there are people who such code? Overlapping
VB is event driven, buttons have a KeyPress events, delay can use the Timer event,
Ask, "' you can according to your actual situation to determine key" how to use the code?
Don't tell me, setting up a KeyPress event to set the variable, then in cyclic code processing,
Don't put the idea to apply directly to the VB, C

It is you, before the string intercept post play you face you don't play enough?

"Great spirit", could you tell me who give you confidence assumed a sermon in the form of a pack to force around disorderly comment on other people's code?

You know CSDN undiscovered talent, you are a novice loading force around, perpetuated this misunderstanding, aren't you ashamed? Modesty is important, you know?

At the same time, others reply thumb up to me and is ok with you? Why don't you think it over why anyone would give me the code thumb up?

In addition, I use VB experience than C more than ten years, the thinking of what C set of VB? Is simply nonsense, in my opinion, all the high-level language is only an idea, if you don't know why I say this, because you don't learn, you still have lots more to it, don't know how to achieve mastery through a comprehensive study, don't understand the word of all roads lead to Rome, besides, I have posted the code is common in VB application,

Because before I return to mobile phone, I put up a perfect code,

CodePudding user response:

refer to 6th floor qq_35328269 response:
add a while loop within a for loop

Roughly as follows

Dim BiaoJi as Boolean=false

For I=0 to 10

While booblean=false

DoEvents

'
of program at this time in an infinite loop'you can according to your actual condition to judge the keys
'is to obtain the global keys or forms to get key?

End while

Next I

I think your question is how to in the loop body get key information, rather than the other problems, because I am a cell phone back to stick son, so the code given is not complete, you can combine with others given the code combination can solve your problem,

The elder brothers... )...

CodePudding user response:

 

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Int32) As Int16

Public Const VK_ENTER=13 'enter keys

Private Sub Button1_Click (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles for. Click

Dim BiaoJi As Boolean

For I As Int16=0 To 100 'represents a 100 - cycle

Sign "infinite loop conditions, role is to execute the next cycle has been waiting for key press
'can directly substitute While True, but for a beginner to understand, I am here defines a Boolean tag
While BiaoJi=False

My application.doevents () 'release control, in order to avoid Windows interface feign death

'under the infinite loop has been the detection of the key state, the enter key after found the blank space key is pressed, exit the infinite loop, perform a FOR loop
If GetAsyncKeyState (VK_ENTER)=- 32767 Then Exit While

'four GetAsyncKeyState returns a value of
'not currently in a state of press 0: key, and since the last call GetAsyncKeyState after change key has not been in;
'1: not currently in a state of press the key, but before that, since the last call GetAsyncKeyState) after the key has been pressed;
'- 32768 (hexadecimal number & amp; H8000) : press the key of the current, but before that, since the last call GetAsyncKeyState) after the key is not pressed;
'- 32767 (hexadecimal number & amp; H8001) : press the key of the current, and before that, since the last call GetAsyncKeyState) after the key has been press,

End While

Me. The Text="current loop variables:" & amp; I

Next I

End Sub



Because don't have VB6 environment, use VB.NET,

Do not match the data type for VB6 with VB.NET, the API function GetAsyncKeyState declaration section, INT32 into Long, Int16 Integer instead, can be used in VB6,

At the same time in VB6,

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related