Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Undelete Record function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Undelete Record function

    Here's my current version of an Undelete UDF (User-Defined Function). It is shown below and as an attached zip file.

    Note that it exits early if all records have been undeleted or if there are no records to undelete. Also there are optional filters and record # ranges, and an option to mark or not the undeleted records.

    Regards,

    Ira J. Perlow
    Computer Systems Design & Associates
    [email protected]

    Code:
    function UndeleteRecords as N(TableName as C,Options as C,Filter as C)
    ' Created by Computer Systems Design & Associates
    ' Copyright 2001 Computer Systems Design & Associates, All Rights Reserved
    ' Last Update: June 15, 2001
    
    ' Input: TableName	= Table (dbf) name to delete.  
    '							  If Null, it then prompts you for tables in the current database
    '							  If blank (but not null), it uses the current table
    '							  If "*", It prompts you for any table
    '			Options		= "I" - Display information before running with choice to cancel
    '							  "M" - Mark records that were undeleted
    '							  "R" - Prompt for record range
    '							  "F" - Prompt for filter
    '								if null, then IRM options are selected
    '			Filter		= Filter (in context of table) expression to process undelete for
    '							  If blank or null, all records will be processed
    '							  The filter expression may not be able to access the table fields unless
    '							  the current form's table is used
    
    ' Output:	Number of records that were undeleted
    '				Negative number indicates error
    
    ' Errors:	-1 = Cancelled operation
    '				-2 = Table name not found
    '				-3 = Table not available
    '				-4 = Other errors
    
    ' Typical Usage:
    '		Place a button on table to delete records with a function call like the example in it's code
    
    ' Examples:
    '		UndeleteRecords("tablename","IRM","")
    
    ' Notes: 
    '	The filter expression may not be able to access the table fields unless
    '	the current form's table is used
    
    ' Set default error return
    UndeleteRecords=-4
    
    If Options=="" 
    	Opt="IRM"
    ELSE
    	Opt=trim(Options)
    End If
    
    ' If not blank and not asterisk, use the supplied tablename
    IF .NOT.(TRIM(TableName)=="").AND..NOT.(ALLTRIM(TableName)=="*")
    	' If file does not exist, then return
    	IF .not.:File.Exists(TableName)
    		UndeleteRecords=-2
    		END
    	END IF
    	' Use the supplied Tablename
    	TabNam=TableName
    else if TableName==""
    	dim tlist[100] as C
    	tname=:A5.table_enum("")
    
    	IF .NOT.(trim(tname)=="")
    		' While the table_enum method returns 
    		' nonblank names, get next name
    		i=1
    		WHILE .not.(trim(tname)=="")
    			tlist[i]=tname
    			i=i+1
    			tname=:A5.table_enum(tname)
    		END WHILE
    		' sort the array otherwise names will be in 
    		' order in which operations were created.
    		sort_array("tlist")
    		' Show the user a list of names
    		choice=ui_get_list_array("Select Table to Undelete",1,"tlist")
    		' If the user selects a table, then do it
    		IF TRIM(choice)==""
    			UndeleteRecords=-1
    			END
    		END IF
    		getpath=IF(trim(:A5.Get_Master_Path())=="",:A5.Get_Path(),:A5.Get_Master_Path())
    		IF .NOT.:File.Exists(getpath+chr(92)+choice+".dbf")
    			UndeleteRecords=-2
    			END
    		END IF
    		TabNam=getpath+chr(92)+choice+".dbf"
    	END IF
    ELSE IF TRIM(TableName)=="" 
    	TabNam=table.current().Name_Get()+".dbf"
    ELSE
    	choice=ui_get_file("Table to Undelete Records:","Table(*.dbf)",table.current().Name_Get()+".dbf","X")
    	IF TRIM(choice)==""
    		UndeleteRecords=-1
    		END
    	END IF
    	TabNam=choice
    END IF
    'trace.writeln("Table selected="+TabNam)
    
    ' Save status of table being opened
    IF :Table.IsOpen(TabNam)
    	opened=1
    ELSE
    	opened=0
    END IF
    
    ' Set Flag to trap errors
    ErrFlag=0
    ON ERROR GOTO error_handler
    tbl=table.open(TabNam)
    ON ERROR GOTO 0
    
    ' If error in opening file, then exit with error
    IF  ErrFlag=1
    	UndeleteRecords=-3
    	END
    END IF 
    
    ' Counts of Regular and deleted records
    reccnt=tbl.records_get()
    recdel=tbl.records_deleted()
    
    IF "I" $ UPPER(Opt)
    	txt="Table: "+tabnam+CHR(10)+CHR(13)
    	txt=txt+"  Total Records: "+STR(reccnt+recdel,7,0)+CHR(10)+CHR(13)
    	txt=txt+"Deleted Records: "+STR(recdel,7,0)
    	choicen=ui_msg_box("Undelete Records?",txt,UI_OK_CANCEL+UI_QUESTION_SYMBOL+UI_SECOND_BUTTON_DEFAULT)
    	IF .not.(UI_OK_SELECTED=choicen)
    		UndeleteRecords=-1
    
    		' If the table was previously closed, close it now
    		IF opened=0
    			tbl.close() 
    		END IF
    
    		END
    	END IF
    END IF
    
    ' Exit if nothing to do
    IF recdel=0
    	UndeleteRecords=0
    	END 
    END IF
    
    IF "F" $ UPPER(Opt)
    	IF trim(filter)=="" 
    		dflt=".T."
    	ELSE
    		dflt=alltrim(filter)
    	END IF
    	choice=ui_get_expr("Enter Filter Expression","Filter:",dflt)
    	IF TRIM(choice)==""
    		UndeleteRecords=-1
    
    		' If the table was previously closed, close it now
    		IF opened=0
    			tbl.close() 
    		END IF
    
    		END
    	END IF
    	filtexp=alltrim(choice)
    ELSE
    	IF trim(filter)=="" 
    		dflt=".T."
    	ELSE
    		dflt=alltrim(filter)
    	END IF
    	filtexp=dflt
    END IF
    
    IF "R" $ UPPER(Opt)
    	choice=ui_get_number("Record Range for Undelete","Max Record="+LTRIM(STR(reccnt+recdel))+"   Begin Record #:","1")
    	IF (0>=VAL(choice)).or.(VAL(choice)>reccnt+recdel)
    		UndeleteRecords=-1
    
    		' If the table was previously closed, close it now
    		IF opened=0
    			tbl.close() 
    		END IF
    
    		END
    	END IF
    	rangebeg=VAL(choice)
    
    	choice=ui_get_number("Record Range for Undelete","Max Record="+LTRIM(STR(reccnt+recdel))+"     End Record #:",LTRIM(STR(reccnt+recdel)))
    	IF (0>=VAL(choice)).or.(VAL(choice)>reccnt+recdel).or.(rangebeg>VAL(choice))
    		UndeleteRecords=-1
    
    		' If the table was previously closed, close it now
    		IF opened=0
    			tbl.close() 
    		END IF
    
    		END
    	END IF
    	rangeend=VAL(choice)
    ELSE
    	rangebeg=1
    	rangeend=reccnt+recdel
    END IF
    
    Undeleted=0
    
    i=1
    ' Get pointer to delete/mark field
    ' Field contains "-" (Dash) for Marked, "*" (Asterick) for Deleted,
    '	 " " (space) for regular record
    fld=tbl.field_get(0)
    
    i=rangebeg
    ON ERROR GOTO error_handler
    
    nxt:
    
    	tbl.fetch_goto(i)
    	IF tbl.is_deleted()
    		tbl.change_begin()
    		ErrFlag=0
    		fil=eval(filtexp)
    		IF ErrFlag=1
    			fil=.T.
    			'trace.writeln("rec #="+LTRIM(STR(i))+"default")
    		ELSE
    			'trace.writeln("rec #="+LTRIM(STR(i))+"  filter="+IF(fil,".T.",".F."))
    		END IF
    		IF eval(filtexp)
    			IF "M" $ UPPER(Opt)
    				' Mark record
    				tbl.mark()
    				' Alternative way to do the mark
    				'fld.value_put("-")
    			ELSE
    				' Undelete record
    				fld.value_put(" ")
    			END IF
    			Undeleted=Undeleted+1
    		END IF
    
    		tbl.change_end(.t.)
    	END IF
    	i=i+1
    ' If some records still deleted and range has not yet been reached, repeat
    IF rangeend>=i.and.recdel>Undeleted
    	GOTO nxt 
    END IF
    
    ON ERROR GOTO 0
    
    ' New counts of Regular and deleted records
    newcnt=tbl.records_get()
    newdel=tbl.records_deleted()
    
    ' If the table was previously closed, close it now
    IF opened=0
    	tbl.close() 
    END IF
    
    UndeleteRecords=Undeleted
    
    ui_msg_box("Undelete Results","Undeleted "+LTRIM(STR(Undeleted))+" records in table"+CHR(10)+CHR(13)+tabnam,UI_OK+UI_INFORMATION_SYMBOL)
     
    END
    
    ' Error handler
    error_handler:
    ErrFlag=1
    'errcode=error_code_get()
    'errmsg=error_text_get(err)
    RESUME NEXT
    
    END
    
    end function
    Last edited by AaronBBrown; 01-09-2007, 12:41 PM.
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



    #2
    RE: Undelete Record function

    Smarty pants. Just kidding! i am humbly educated, now, and will save your instructions for future use!
    Thanks,
    Wanda

    Comment

    Working...
    X