Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi.

 

I have a loop code for waiting a condition to be true. In that loop I have a msgbox.

 

For every msgbox, I need to have automatically �press ok� because after true condition is valid to exit the loop without user to press ok.

 

This is the code

 

         oCP.Write(Encoding.ASCII.GetBytes("D" & Chr(13)))

           Do Until verifica_mesaj()
               MsgBox("Loading in progress...", MsgBoxStyle.Information)
           Loop

           oCP.Write(Encoding.ASCII.GetBytes("F" & Chr(13)))


 

 

thanks

 

ps. later edit

 

I can have something like this :

 

do nothing until condition true

code

loop

Edited by Ace Master
Posted
DialogResult.Ok to somewhere I guess...

"Everything should be made as simple as possible, but not simpler."

"It's not that I'm so smart , it's just that I stay with problems longer ."

- Albert Einstein

Posted

I don't think you can do that. When you display a message box your code will wait until that message box is closed by the user.

 

For you requirements you will have to write your own form to display the message that you can then close yourself when the loop has finished.

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted
you program the mouse cursor to move on the button and auto click it lol joking...

"Everything should be made as simple as possible, but not simpler."

"It's not that I'm so smart , it's just that I stay with problems longer ."

- Albert Einstein

  • Leaders
Posted
You can create your own form to do this. You can add a timer to your form, and make it look like a MsgBox... and then you can have the timer close the form. :)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

I see....

 

But why in my loop only the msgbox is working? What if I want nothing to happen in my loop ? like below..

 

 

Do Until verifica_mesaj()

 

Loop

 

 

or what code to write to wait until the condition is true and then to go further with code..

  • Leaders
Posted
Hmm... usually if you want a tight loop like that, you will want to add Application.DoEvents into it so that other things can occur. :)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

Application.DoEvents() allows other things to happen while your in a loop basically.

 

Do Until verifica_mesaj=true

 

Loop

 

would result in your program being in an infinite loop without the Application.DoEvents() being in it. The Application.DoEvents() will allow other messages (events) to process in the mean-time you could say, where without it, no other messages (events) can be processed until control is released from the loop, and without any code to do that... infinite loop.

  • Leaders
Posted

What do you mean? Are you saying that it doesn't stay inside of the loop?

What does verifica_mesaj() do?

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

Yes. The loop is not working.

 

this is the code now

 


 oCP.Write(Encoding.ASCII.GetBytes("D" & Chr(13)))


           Do Until verifica_mesaj() = True
               Application.DoEvents()
                ' msgbox("please wait...")
           Loop


           oCP.Write(Encoding.ASCII.GetBytes("F" & Chr(13)))

 

"verifica_mesaj" check if my receiving RS232 string has the last char = ">"

 

       If output.EndsWith(">") Then
           Return True
       Else
           Return False
       End If

 

 

The weird stuff here is that if I use the msgbox the loop is working and the msgbox stays until the verifica_mesaj = true. After that if you press the ok from the msgbox the next command is send to the serial.

 

Maybe you need to know more about my code.

 

I have other function, which receive char by char from the serial. In this function, I call verifica_mesaj until the last char is out from the serial , because I need to know what output has. If output has the last char ">" is ok and the trimite_mesaj is true and then exit loop and send the other command to the serial.

Posted

On each round of your loop you calling a procedure. Loops are usually done using a test...not a procedure, plus if the procedure doesn't return anything it will be, as you said, as if nothing was there.

 

From what it looks like what you are trying to do your just trying to display a message to the user to wait while the program does something in which case you don't want to be using a loop, you just want a custom form, as they said above, that will close itself when it is done doing the procedure... that's really simple to do... make your form all pretty and how you like it... make it a dialog box style and remove set the control box property to false along with any other items you don't want seen, such as show in task bar.

 

Then in your code:

 

'Tell user to wait while I do this

Dim myForm as New myCustomForm()

 

myForm.TopMost = True

myForm.Show()

Me.Enabled = False 'Keeps user from doing anything on this form

 

'Do my stuff

'

'

'

'

'End my stuff

 

Me.Enabled = true 'Allow user to use this form again

myForm.Close() 'Close the message

 

Forgive my lack of VB syntax, I work C#...

Posted

bri189a >> I don't know if that will going to work.

 

I need a loop to keep checking the verifica_mesaj if true or not, until the string is over from the serial

 

If I put the code you suggested, the first calling will not have verifica_mesaj true because is not waiting for later checking...and will not work.

 

I think..

 

 

Anyway ...if anybody has other code idea for this I will appreciate verry much .

 

do this : line code 1

 

wait until verifica_mesaj = true

 

do this : line code 2

Posted

Don't use a timer. Just have it check in your loop

 

oCP.Write(Encoding.ASCII.GetBytes("D" & Chr(13)))

 

Do Until verifica_mesaj() = True

sstrString = readinput here ' However you are reading your input

if sstrString = ">" then

verifica_mesaj() = true

end if

Application.DoEvents()

' msgbox("please wait...")

Loop

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

thanks to all for the help you give me.

 

After I make a small analisys of the answers I made this code which works fine.

 

oCP.Write(Encoding.ASCII.GetBytes("D" & Chr(13)))
           Dim stai As New wait


           Do Until verifica_mesaj() = True

               stai.TopMost = True
               stai.Show()

               If output.EndsWith("F") Then
                   Exit Do
               End If
               Application.DoEvents()
               'MsgBox("please wait...")
           Loop


           oCP.Write(Encoding.ASCII.GetBytes("F" & Chr(13)))

           stai.Close()

  • Administrators
Posted

Would the following not work?

'No need to display the form every time through loop
Dim stai As New wait
stai.TopMost = True
stai.Show()

oCP.Write(Encoding.ASCII.GetBytes("D" & Chr(13)))

Do Until verifica_mesaj() = True
   If output.EndsWith("F") Then
       Exit Do
   End If
   Application.DoEvents()
Loop

oCP.Write(Encoding.ASCII.GetBytes("F" & Chr(13)))

stai.Close()

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • 4 weeks later...
Posted

This thread was excatly what I needed to do in my application. However, when I try typing it in, it gives me an error during my decalration of...

 

Dim stai AS New wait

 

It says the type 'wait' is not declared. Am I missing something? :confused:

Posted
wait is the name of a form in his application - you will need to create a form of your own and use it in place of wait.

 

Hi.

 

I used afte all a form which is shown in a do until code. After the condition is true..the form is closed....

Posted

why not just do:

 

 

Private sub timer1_tick(blah)Handles timer1.tick
msgBox("Waiting")
Sendkeys.sendwait("{enter}")
End sub

 

if you want it to automatically press ok, i think that would work...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...