Alpha Video Training
Results 1 to 2 of 2

Thread: Writing a subfunction in a UDF with local_variables()

  1. #1
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,584

    Default Writing a subfunction in a UDF with local_variables()

    I am confused on where to put the END WITH statement if I redirect to an error handler in a subfunction that is after the END statement

    An example:

    dim lv as p = local_variables()
    dim myvar as c
    dim commit_flag as L
    myvar = mysub(lv)

    Code:
    function mysub as C (vars as P)
    WITH vars
    commit_flag = .t.
    'code here to open a table to enter or change records
    on error goto ERRMSG
    tbl = table.open("mytable")
    tbl.change_begin()
    ....
    tbl.change_end(commit_flag)
    tbl.close()
    
    mysub = 'some variable
    '  1 - place END WITH here?
    end
    ERRMSG:
    commit_flag = .f.
    script_play_local("Err_Msg")
    RESUME NEXT
    '  2 - or place END WITH here?
    end function
    If commit_flag is dimmed a local variable and the END WITH is put before the END statement in #1, will the error_handler reset it properly?
    And if there is no error then the script will never find the END WITH in #2 which would cause an error wouldn't it?

    How would you do it?
    Last edited by MoGrace; 02-16-2019 at 04:53 PM.
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

  2. #2
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,584

    Default Re: Writing a subfunction in a UDF with local_variables()

    Hah! Found the answer here (hope it works...)

    The END WITH goes at #1 then in the error handler a dot is put before the commit_flag variable to indicate the parent UDF variable space is local as in

    ERRMSG:
    .commit_flag = .f.

    Found this Xbasic tip for web components but it should work for the desktop.
    Last edited by MoGrace; 02-16-2019 at 04:56 PM.
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

Similar Threads

  1. Help with writing a Function
    By WaltMorgan in forum Alpha Five Version 8
    Replies: 7
    Last Post: 02-22-2008, 10:46 AM
  2. Writing to Alpha DBF from C#
    By acidcigarfiend in forum Alpha Five Version 8
    Replies: 1
    Last Post: 10-04-2007, 08:45 AM
  3. help writing query please
    By gkeramidas in forum Alpha Five Version 7
    Replies: 3
    Last Post: 11-15-2006, 05:11 PM
  4. Writing data through ADO
    By Sholom Hamada in forum Alpha Five Version 6
    Replies: 1
    Last Post: 07-28-2004, 01:29 PM
  5. Writing a Letter
    By John Berry in forum Alpha Five Version 5
    Replies: 1
    Last Post: 05-11-2004, 09:32 AM

Bookmarks

Posting Permissions

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