Results 1 to 9 of 9

Thread: Pause Execution Until Function Completed (web access function)

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Pause Execution Until Function Completed (web access function)

    I started a new thread as my previous thread is starting to branch out. Hope this is okay.

    I decided to simply read the contents of an ascii file from my website using the Inet control.

    This appears to work just fine.

    With one major exception.

    Before my routine finishes, my application has already continued down the code road without waiting for my function to complete.

    For example:

    The applications starting subroutine is called "Main". (original, right? lol!)

    Anyway, I added a line:

    'Application Registration Validation
    sUserInfo = AppRegValidation

    AppRegValidation is a FUNCTION that returns usertype USERINFO that simply contains two strings. .Username and .Email.

    Within AppRegValidation I am grabbing data from a text file using Inet1.OpenURL().

    Before AppRegValidation has completed its task, to read the text file, then parse through the data retrieved to compare it with the apps username and email to see if valid, the MAIN subroutine has continued on without waiting for the AppRegValidation return of USERINFO.

    How do I keep the application from running until AppRegValidation has completed and returned?

    Bear with me please. I'm old, senile, and a noob of the 5th order. ;-)

  2. #2
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    858

    Re: Pause Execution Until Function Completed (web access function)

    Haven't read your other thread.
    A search of forum may yield a number of results in this area.

    Since you're returning a structure, then just test for one of the properties.
    FWIW: When dealing with structures I normally use a "T" in front,
    where IMHO using a "s" causes confusion, since one assumes a
    string is being returned.

    One possible (haven't tried with Inet):

    Code:
    JumpHere:
    sUserInfo = AppRegValidation
    If Len(sUserInfo.{whatever}) = 0 Then GoTo JumpHere
    Last edited by vb6forever; Sep 21st, 2021 at 08:03 AM.

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Pause Execution Until Function Completed (web access function)

    Brr.....shudder.....
    What's wrong with
    Code:
    Do
       sUserInfo = AppRegValidation
    Loop Until Len(sUserInfo.Username) > 0
    No idea about inserting a mechanism to abort the loop (though should be possible with a boolean-var and a DoEvents)
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    858

    Re: Pause Execution Until Function Completed (web access function)

    Zvoni:

    Brr.....shudder....
    LOL Either will work. In ASM one uses Jumps all the time.
    Other than the leads to spaghetti code argument, if used sparely why not.

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Pause Execution Until Function Completed (web access function)

    Quote Originally Posted by vb6forever View Post
    Other than the leads to spaghetti code argument, if used sparely why not.
    You know what they say: Once you submit to the temptation......
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: Pause Execution Until Function Completed (web access function)

    Quote Originally Posted by vb6forever View Post
    Haven't read your other thread.
    A search of forum may yield a number of results in this area.

    Since you're returning a structure, then just test for one of the properties.
    FWIW: When dealing with structures I normally use a "T" in front,
    where IMHO using a "s" causes confusion, since one assumes a
    string is being returned.

    One possible (haven't tried with Inet):

    Code:
    JumpHere:
    sUserInfo = AppRegValidation
    If Len(sUserInfo.{whatever}) = 0 Then GoTo JumpHere
    The application was written nearly 20 years ago and I had yet to lock into a naming convention and stick with it.

    You are correct the 's' is for string. As I never settled on a 'structure' indication for struc variables, if it only contained strings I put an 's' in front. Bad, I know.

    I'm assuming "T" is for 'type', like in User Type?

    Perhaps a big "S" for structure? Or is that taken already? ;-0

    I search forum and webverse before posting here. I get frustrated at the difficulty of nailing down a satisfying answer and it is irritating that Google returns so many ADS as answers or Microsoft posts for VB.NET!

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: Pause Execution Until Function Completed (web access function)

    Quote Originally Posted by Zvoni View Post
    Brr.....shudder.....
    What's wrong with
    Code:
    Do
       sUserInfo = AppRegValidation
    Loop Until Len(sUserInfo.Username) > 0
    No idea about inserting a mechanism to abort the loop (though should be possible with a boolean-var and a DoEvents)
    I shudder at the use of GoTo and never use it. As for the Do Loop, I did end up doing and it works fine. But my hesitation was what appeared in code to be repeated calling of the AppRegValidation using the Loop. In my mind, if I already called it once and it should be running, why would I call it again and again and again. Somehow I equated this code to starting a bunch of threads of the same call. What I FAILED to realize until the caffeine in my system finally dropped to safe levels is that if my function has not completed yet, then it WON'T be called again in the loop.

    Like I said previously, I'm getting old and senile and am at Noob Level #5. This is why I come here, to hopefully regain some brain activity and get this blasted super old VB6 program updated and out of my sight! LOL!

  8. #8
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    858

    Re: Pause Execution Until Function Completed (web access function)

    webbiz:

    Remember you are the coder, so you can do anything you want that makes sense to you and accomplishes your objective.
    Each individual has their querks (e.g. only professionals use C, C++, Net, etc. which is their own bias they are expressing.)
    As Zvoni mentions you might want to consider having a mechanism to escape the Loop (whether mine or his).
    What I would do, is add an integer property to your structure (type). Call it whatever makes sense to you (e.g. Active, Done, Completed, ...).
    You could then check that property, and use it to either continue or escape the Loop. For example if value:
    -1 = No Response from User
    0 = Continue Loop
    1 = User Responded

    Add:
    Remember you have a three fold problem to deal with:
    1) User never responds (0) and loop goes on forever.
    How do you end the program (-1).
    2) User Responds Correctly and program continues (1)
    3) User Responds Incorrectly (0), How many times do you
    want to allow them to respond before ending the program (-1)?
    Last edited by vb6forever; Sep 21st, 2021 at 10:27 AM. Reason: Add:

  9. #9
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: Pause Execution Until Function Completed (web access function)

    Quote Originally Posted by webbiz View Post
    I started a new thread as my previous thread is starting to branch out. Hope this is okay.

    I decided to simply read the contents of an ascii file from my website using the Inet control.

    This appears to work just fine.

    With one major exception.

    Before my routine finishes, my application has already continued down the code road without waiting for my function to complete.

    For example:

    The applications starting subroutine is called "Main". (original, right? lol!)

    Anyway, I added a line:

    'Application Registration Validation
    sUserInfo = AppRegValidation

    AppRegValidation is a FUNCTION that returns usertype USERINFO that simply contains two strings. .Username and .Email.

    Within AppRegValidation I am grabbing data from a text file using Inet1.OpenURL().

    Before AppRegValidation has completed its task, to read the text file, then parse through the data retrieved to compare it with the apps username and email to see if valid, the MAIN subroutine has continued on without waiting for the AppRegValidation return of USERINFO.

    How do I keep the application from running until AppRegValidation has completed and returned?

    Bear with me please. I'm old, senile, and a noob of the 5th order. ;-)
    What I understand is:

    1) You call AppRegValidation to get some user info
    2) AppRegValidation returns too soon without the user info
    3) AppRegValidation uses Inet1.OpenURL to the the user info from a web server.

    But... I read that OpenURL is a synchronous call, it does not return until it already has the data.

    So, or I'm not understanding or it doesn't make sense (the is some error in the code or in the explanation).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width