| | |
how to run a sub over again from a button click...
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 100
Reputation:
Solved Threads: 2
Another problem I am looking into is the following:
How does one use a command button to run private sub's (again) or (at all)?
For instance if a website isn't available at the exact moment that it is being checked for certain information on it. I have it set to say "not there." Then, I want to have a "retry" command button appear (which it does) and call the same sub's that did the work b4 to check for that information again in case the site was just too busy or whatever...
I have been googling for the better part of a day on this. I cant seem to get this to work without errors (syntax).
That "should" go to the sub that I want to run again. Then after that I want it to go to another sub for 'data-arrival'... (But no point in that if I cant get the first one to work) again if the retry button is clicked. I hope this is clear enough to actually understand.
Any ideas? Thanks
How does one use a command button to run private sub's (again) or (at all)?
For instance if a website isn't available at the exact moment that it is being checked for certain information on it. I have it set to say "not there." Then, I want to have a "retry" command button appear (which it does) and call the same sub's that did the work b4 to check for that information again in case the site was just too busy or whatever...
I have been googling for the better part of a day on this. I cant seem to get this to work without errors (syntax).
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Command2_Click() Call Winsock2_Connect End Sub
That "should" go to the sub that I want to run again. Then after that I want it to go to another sub for 'data-arrival'... (But no point in that if I cant get the first one to work) again if the retry button is clicked. I hope this is clear enough to actually understand.

Any ideas? Thanks
Last edited by squidd; Nov 23rd, 2008 at 2:44 am.
well, one way to tell what subs were successful and which ones weren't would be to create a set of boolean flags... for example...
then when you retest you run the sub you can check what still needs to run...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
private bSomeSub as boolean private bSomeFunction as boolean private sub SomeSub() on error goto Oops 'whatever is in the sub 'lots of code or not so much :p bSomeSub = true Oops: end sub private function SomeFunction() as byte on error goto Oops 'whatever the function code is 'lots of code :p SomeFunction = resultingData bSomeFunction = true Oops: end Function
then when you retest you run the sub you can check what still needs to run...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
private sub cmdCommand_Click() if bSomeSub = false then call SomeSub if bSomeFunction = false then someResult = SomeFunction(someData) end sub
... there is no bug that enough coffee cannot fix...
... i really need to drink more coffee at night...
ok, since you're using the winsock control, you have a few options you can use... in this case, the name of your control is Winsock2 i think... anyway...
winsock2.state, check that out...
.state can be several things, 0 through to 9
0 - closed
1 - open
2 - listening
3 - connection pending
4 - resolving host
5 - host resolved
6 - connecting
7 - connected
8 - closing
9 - error
so, check it and see where you're at...
ok, since you're using the winsock control, you have a few options you can use... in this case, the name of your control is Winsock2 i think... anyway...
winsock2.state, check that out...
.state can be several things, 0 through to 9
0 - closed
1 - open
2 - listening
3 - connection pending
4 - resolving host
5 - host resolved
6 - connecting
7 - connected
8 - closing
9 - error
so, check it and see where you're at...
... there is no bug that enough coffee cannot fix...
•
•
Join Date: Nov 2007
Posts: 100
Reputation:
Solved Threads: 2
•
•
•
•
I will look into your solutions and get back to you.
Thanks for the help.
I have 2 Private Sub's that should run when a button is pressed.
They are the following:
Private Sub Winsock2_Connect() and....
Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
I have tried it as:
private Winsock2_Connect as boolean
private Winsock2_DataArrival as boolean
and as
private Winsock2_Connect() as boolean
private Winsock2_DataArrival(ByVal bytesTotal As Long) as boolean
I have tried to set them up as you described in your first reply. I get an error of 'ambiguous name detected.'
~~Also, the winsock.state should be 'closed' as per the code telling it to close. I dont know why I sould need to use that bit. Maybe you could explain a little more clearly on what I would do to use it effectively. What I think you want me to do is:
1: Create an integer (Dim State As Integer)
2: Then print the state of the Winsock (Winsock2.State = State)
Print State (or whatever)
Other than that im not sure why you want me to try that.
Thank you for the help as always.
Last edited by squidd; Nov 23rd, 2008 at 10:10 pm.
ambiguous name detected because you have to lead the variable name with a b (naming convention for boolean), otherwise you're matching the sub name completely which works as an abiguity...
as for the piece related to state; it was a different method to solve the problem... if you attempt to connect with winsock (control), the state changes during the connection attempt; if the connection attempt errors, the state will be set to 9... if you're trying to make it log in, you could loop while the state is not 7 or 9, if it's 7 then the connection has been successfully established, if it's 9, then it errored... you could also use it in combinatoin with something similar to your pause proceedure you'd listed before to set a time out of, say... 10 seconds....
anyway...
just a thought...
as for the piece related to state; it was a different method to solve the problem... if you attempt to connect with winsock (control), the state changes during the connection attempt; if the connection attempt errors, the state will be set to 9... if you're trying to make it log in, you could loop while the state is not 7 or 9, if it's 7 then the connection has been successfully established, if it's 9, then it errored... you could also use it in combinatoin with something similar to your pause proceedure you'd listed before to set a time out of, say... 10 seconds....
anyway...
just a thought... ... there is no bug that enough coffee cannot fix...
•
•
Join Date: Nov 2007
Posts: 100
Reputation:
Solved Threads: 2
Trying your first methos, I am still getting an error.
Compile Error: Arguement not optional
I dont need 'End If' statements in there either i suppose because I get an error if I try to put them in.
But i am hoping this will work.
I will text the 'state' method now i suppose just to see how that works.
Thanks again
Compile Error: Arguement not optional
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Command2_Click() If bWinsock2_Connect = False Then Call Winsock2_Connect If bWinsock2_DataArrival = False Then Call Winsock2_DataArrival End Sub
I dont need 'End If' statements in there either i suppose because I get an error if I try to put them in.
But i am hoping this will work.
I will text the 'state' method now i suppose just to see how that works.
Thanks again
•
•
Join Date: Nov 2007
Posts: 100
Reputation:
Solved Threads: 2
I tried the 'state' approach and it does work. I would really like to see it as it does throughout the entire process line by line, but i dont know how to do that. What I mean is like make a textbox to show the conntion status throughout the entire process and with each change of state, then a new value is added to the text box while leaving the previous value.
I wonder though, is there a way just the use a command button to re-run the entire needed form minus the 'form load' without calling all of the subs?
I will look into that for right now i suppose.
I wonder though, is there a way just the use a command button to re-run the entire needed form minus the 'form load' without calling all of the subs?
I will look into that for right now i suppose.
well, unfortunately i don't remember how to convert an enum to its string value... not sure i ever knew actually
. anyway; the enum set up for this is
MSWinsockLib.StateConstants
others you might be interested in are
MSWinsockLib.ErrorConstants
MSWinsockLib.ProtocolConstants
having your program automaticly list the status changes could be done by looping; but that takes up a fair bit of processor time... and basicly locks your program up; though if you had a connection loop, which i believe you do; you could update the status in the text box everytime you finished a loop... keep track of what your previous status was and only add the new status if it changes... to add it to a text box, on the next line, just set the text box to multiline and add the new status with vbCrlf (character return, line feed) to break the line... might also want to lock the text box so the user can't alter it's current contents...
you could also use a direct loop that just monitored the state for changes; this would basicly lock up the program until it decides it's finished with the conection attempt... you could break the loop upon achiving the status you want, an error, or a timeout...
hope that helps some, might just be confusing... not enough coffee yet for 3 am...
. anyway; the enum set up for this isMSWinsockLib.StateConstants
others you might be interested in are
MSWinsockLib.ErrorConstants
MSWinsockLib.ProtocolConstants
having your program automaticly list the status changes could be done by looping; but that takes up a fair bit of processor time... and basicly locks your program up; though if you had a connection loop, which i believe you do; you could update the status in the text box everytime you finished a loop... keep track of what your previous status was and only add the new status if it changes... to add it to a text box, on the next line, just set the text box to multiline and add the new status with vbCrlf (character return, line feed) to break the line... might also want to lock the text box so the user can't alter it's current contents...
you could also use a direct loop that just monitored the state for changes; this would basicly lock up the program until it decides it's finished with the conection attempt... you could break the loop upon achiving the status you want, an error, or a timeout...
hope that helps some, might just be confusing... not enough coffee yet for 3 am...
... there is no bug that enough coffee cannot fix...
•
•
Join Date: Nov 2007
Posts: 100
Reputation:
Solved Threads: 2
*SOLVED BY KAIN*
Welp, i got it fixed... I just did this:
I thought it would completely reload everything, and maybe it does, but it is so fast i cant tell its being done.
either way. solved. plus I did what you suggested and I can now see the status in the textbox by doing the following:
[code/]
text2.text = Winsock2.state[/code
and for every subsequent line i simply added:
[code/]
text2.text = text2.text & vbCrLf & Winsock2.state[/code
Works like a charm and I see 0,4,7,0... perfecto...
thanks for the help, added to your rep and am giving you the solved regardless of how I got there.
much appreciated!
p.s. do you have any idea why I get an error when I tried to run this sub call?
I could call the other sub's fine except this one. mabye because there was more to it?
Winsock2_DataArrival(ByVal bytesTotal As Long) <------
but when I added that I got a syntax error... just curious. thanks again!
Welp, i got it fixed... I just did this:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Call Form_Load
I thought it would completely reload everything, and maybe it does, but it is so fast i cant tell its being done.
either way. solved. plus I did what you suggested and I can now see the status in the textbox by doing the following:
[code/]
text2.text = Winsock2.state[/code
and for every subsequent line i simply added:
[code/]
text2.text = text2.text & vbCrLf & Winsock2.state[/code
Works like a charm and I see 0,4,7,0... perfecto...
thanks for the help, added to your rep and am giving you the solved regardless of how I got there.

much appreciated!
p.s. do you have any idea why I get an error when I tried to run this sub call?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Call Winsock2_DataArrival
I could call the other sub's fine except this one. mabye because there was more to it?
Winsock2_DataArrival(ByVal bytesTotal As Long) <------
but when I added that I got a syntax error... just curious. thanks again!
Last edited by squidd; Nov 26th, 2008 at 7:14 am.
![]() |
Similar Threads
- Button click event only working the second time (C#)
- Error message when attempting to run program in Windows XP (Windows NT / 2000 / XP)
- Run msn messenger on button click in asp.net 2.0 (ASP.NET)
- Run messenger on button click (ASP.NET)
- Cannot Run Spyware Doctor (Viruses, Spyware and other Nasties)
- Button event lost.. (ASP.NET)
- Recognizing when a button is pressed. (Java)
- left mouse button and keyboard stop working after minutes/hours (Viruses, Spyware and other Nasties)
- having problem..click me something...please help me out. (Viruses, Spyware and other Nasties)
- Desktop folder shortcuts quit, can't double-click & launch media files (Viruses, Spyware and other Nasties)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Urgency for vb code...
- Next Thread: Unable to create Link in the Word, using VB6
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window





