Tuesday, November 25, 2008

Fun with Recursion

I needed to backup a subdirectory and need to go through all subdirectories under it.

I used recursion to solve the problem.  

For those who don't know, recursion is when a function calls itself to solve a problem.  The classic example is factorial.  5 Factorial is 5*4*3*2*1.  here's a function to do that
Function Factorial (number as integer) as long
if number=1 then
return 1
        else
return factorial (number-1)*number
end if
end function

Run through the code

Friday, November 14, 2008

Goofy Error and Cool library

Goofy Error
While working on a VB 2005 application (backup application to do multi-generational backups of critical files), I got a rather strange error. The error was 
"The item "obj\Debug\BackupConfig.BackupJobForm.resources" was specified more than once in the "Resources" parameter.  Duplicate items are not supported by the "Resources" parameter. BackupConfig"

I did a little googling, and tried to delete the obj folder under the application.  It did nothing.

I wound up having to delete the form and start over again.  I think it had to do with the form being saved as "FORM1" and then renamed to "BACKUPJOBFORM".  I think that the dependent files (aka the. resx and the .designer files) somehow got corrupted.
Library
I ran across an cool open source library that encapsulates zip file compression for dot net apps.  
Here is the link for some example code (VB of course). 

Wednesday, November 12, 2008

Lessons From Adobe Livecycle Designer

Today I was using Adobe's Livecycle Designer to create a fillable PDF form.  Livecycle is Adobe's fillable form creation utility that comes as a part of Acrobat Pro.

To be honest, I think that program is cumbersome and difficult to use.

Anyway, here's some lessions learned.

1.  Try to have Adobe find the fields
Typically, you'll create your form in Word or Publisher and then import into Adobe.  If use use Adobe Acrobat Pro first, instead of Livecycle, it has a built-in find form fields features that's handy.  It will look at your form, and try to guess where the fields go.  It gets things wrong all the time., but running this first will save you time. 

2.   When working in Livecycle, save often
I've lost several forms because Livecycle died.  Save early and often to save time and effort.  My main problem were malformed javascripts.  Adobe should be able to throw an execption saying "you're scripts are screwy" instead of crashing.

3.  When adding different Radio Button Groups.
Creating one group is easy.  The second is where it gets hard.  The easiest way I found to cre
ate seperate radio button groups (a group is
 a collection of radio buttons that are mutually exclusive, turning on one, turns the others off) is 
  1. Drag the new radio button to the form
  2. right click on the button 
  3. Click on "Wrap in New Radio Button Group" (see figure)
  4. You're done
Validation
There are times you would like to advise your users that the values they entered are inccrrect.  There are really good reasons to do so.

First, you put a form out to collect data from users.   If they have made a mistake, they will be able to correct it and put the correct information into the form.  Once the form is received, all you can do is guess or attempt to contact the user for clairfication.  It makes sense to do the editing before you receive the form.  Second, there are some values that are simply wrong.  A data of 2/30/xxxx is always wrong.  If they entered this date, did they mean 1/30 or 3/30?

Be careful with edits, though.  You must allow for unknown values, even if it doesn't make sense to you (for example, on gender), but its better than making the user lie in order to submit the form.


To do edits, place the validation code into the validation script in livecyle.  Below are two examples of validation code.

Livecycle desginer 8
//Validate days in the month based upon month(1 <= this.rawValue && this.rawValue <=29 && MonthField.rawValue ==2) || (1 <= this.rawValue
 &&
 this.rawValue <=30 && (MonthField.rawValue ==4 || MonthField.rawValue ==6 || MonthField.rawValue ==9 || MonthField.rawValue ==11)) || (1 <= this.rawValue && this.rawValue <=31 && (MonthField.rawValue ==1 || MonthField.rawValue ==3 || MonthField.rawValue ==7 || MonthField.rawValue ==8 || MonthField.rawValue ==10 || MonthField.rawValue ==12));
 
 
//Validate the year
var dt = new Date();
var cyr = dt.getFullYear();
1917 <= this.rawValue && this.rawValue <=parseInt(cyr);
Creating Radio Button Groups