Ace Master Posted February 23, 2004 Posted February 23, 2004 (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 February 23, 2004 by Ace Master Quote
DR00ME Posted February 23, 2004 Posted February 23, 2004 DialogResult.Ok to somewhere I guess... Quote "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
Ace Master Posted February 23, 2004 Author Posted February 23, 2004 isn't working... this code work only in a "if ... then" statment.. I think.... Quote
TechnoTone Posted February 23, 2004 Posted February 23, 2004 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. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
DR00ME Posted February 23, 2004 Posted February 23, 2004 you program the mouse cursor to move on the button and auto click it lol joking... Quote "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 Iceplug Posted February 23, 2004 Leaders Posted February 23, 2004 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. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Ace Master Posted February 23, 2004 Author Posted February 23, 2004 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.. Quote
Leaders Iceplug Posted February 23, 2004 Leaders Posted February 23, 2004 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. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Ace Master Posted February 24, 2004 Author Posted February 24, 2004 iceplug > what do you mean by that ? Quote
bri189a Posted February 24, 2004 Posted February 24, 2004 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. Quote
Ace Master Posted February 24, 2004 Author Posted February 24, 2004 thanks for the answer, but... this code Do Until verifica_mesaj() = True Application.DoEvents() Loop ...has no effect . Is like I don't have it. Quote
Leaders Iceplug Posted February 24, 2004 Leaders Posted February 24, 2004 What do you mean? Are you saying that it doesn't stay inside of the loop? What does verifica_mesaj() do? Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Ace Master Posted February 24, 2004 Author Posted February 24, 2004 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. Quote
bri189a Posted February 24, 2004 Posted February 24, 2004 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#... Quote
Ace Master Posted February 24, 2004 Author Posted February 24, 2004 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 Quote
techmanbd Posted February 24, 2004 Posted February 24, 2004 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 Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Ace Master Posted February 25, 2004 Author Posted February 25, 2004 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() Quote
Administrators PlausiblyDamp Posted February 25, 2004 Administrators Posted February 25, 2004 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() Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Ace Master Posted February 25, 2004 Author Posted February 25, 2004 True..... don't need to show the form for each loop. :) thanks. Quote
Eng Posted March 18, 2004 Posted March 18, 2004 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: Quote
Administrators PlausiblyDamp Posted March 18, 2004 Administrators Posted March 18, 2004 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Ace Master Posted March 25, 2004 Author Posted March 25, 2004 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.... Quote
decrypt Posted March 26, 2004 Posted March 26, 2004 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... Quote
Administrators PlausiblyDamp Posted March 27, 2004 Administrators Posted March 27, 2004 One you are using the old VB6 msgbox rather than the .Net MessageBox.show and 2 it wouldn't execute the SendKeys until the messagebox has been closed manually anyway. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
decrypt Posted March 27, 2004 Posted March 27, 2004 Then do sendkeys.send("{enter}")??? That won't wait... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.