Friday, August 22, 2014

Line break in exchange appointments

I'm using the EWS (Exchange Web Service) Api with VB.Net to create appointments and I couldn't get it to accept the newline character.  Everything kept getting printed on one line and seemed to ignore my newline formatting.  vbNewLine didn't seem to work.  I also read something about having to put in extra spaces at the beginning or the end of the line, but that also didn't work.  I finally found a post which advised that appointments are stored in html format.  What finally worked was the html line break "<br />".

Thanks to Luke for the answer.

Wednesday, August 20, 2014

Registering a DLL file

The application I am working on uses Windows Image Acquisition 2.0 to access and control a scanner.  The problem was that after I installed and then uninstalled the program, I kept getting the error 'WIA' is not declared. It may be inaccessible due to its protection level. That should have been easy enough to fix, just reference the Microsoft Windows Image Acquisition Library v2.0.  The problem was that it wasn't there.  (Or at least I couldn't see it.)  I finally figured out that Gary didn't have version 2.0 on his XP computer and had to get a copy and register it separately.  When the program was installed, it registered the wiaaut.dll file to the one Gary included in the program files instead of the system32 folder.  As soon as I uninstalled the program, there went my reference to "WIA".  To fix the problem, I had to re-register the copy that was still in the system32 folder.  After I rebuilt the program, we also had to re-register wiaaut.dll on all the computers the program was installed on.



Here is how to do it.
  1. From the start bar, type cmd in the search field (don't hit enter)
  2. Right click cmd.exe and run as administrator (goes directly to system32 folder)
  3. At the prompt type: regsvr32 wiaaut.dll (hit enter)
To unregister the same dll
  1. Pull up the same cmd prompt
  2. At the prompt type: regsvr32 /u wiaaut.dll

Tuesday, August 12, 2014

Using VB.Net to check a checkbox on a pdf

It took me a little while to figure out how to check and uncheck a checkbox on a pdf form using VB.Net. The value of the checkbox has to be set to either "0" for unchecked or "1" for checked.  Here is the code I used to access the form and get to the checkbox.

' Reference to Acrobat application

Dim gApp As Acrobat.CAcroApp

'IAC objects
Dim gPdDoc As Acrobat.CAcroPDDoc

Dim formApp As AFORMAUTLib.AFormApp
Dim acroForm As AFORMAUTLib.Fields = Nothing
Dim field As AFORMAUTLib.Field

'Initialize Acrobat by creating App object
gApp = CreateObject("AcroExch.App")

' Initialize the PDF object
gPdDoc = CreateObject("AcroExch.PDDoc")

' Open an example PDF file in acrobat
If gPdDoc.Open("C:\example.pdf") Then 
   
   ' I'm still not sure what all of this does
   s = gPdDoc.GetFileName
   gPdDoc.OpenAVDoc(s)

   formApp = CreateObject("AFormAut.App")
  
   ' Get a reference to the fields from the form 
   acroForm = formApp.Fields

   ' Get a reference to the particular checkbox field 
   ' This uses the data structure of the form to find the form, 
   ' then page, then fieldname
   field = acroForm.Item("form1[0].#subform[0].Checkbox3[0]")
   
   ' Set the checkmark to "on"
   field.Value = "1"

   ' Set the checkmark to "off"
   field.Value = "0"
 
Else
   MsgBox("Failed to open")
End If

Monday, August 11, 2014

Dynamic pdf causing issues - unable to access form fields

I just figured out an issue that I don't think Gary ever got to the bottom of.  It all came down to the fact that not all pdf forms are created equal, and some of the forms we were using were getting saved in a different format that wasn't working with our code.  It would appear that pdf's can come in about 4 different formats.

From the adobe blog:

Flat PDF – A PDF with no XFA stream and no non-signature elements. Basically there are no fields in the document. It is important to note that a “Flat” PDF may still have some layers, such as the comment layer. In this case the flatness refers to the lack of data fields. 
Static PDF – A PDF which contains an XFA stream and the form layout does not change. Static forms may be interactive (a user can still fill in fields). If a dynamic XDP is rendered with LiveCycle Forms with the Render At Client option set to “No” then the resulting PDF is no longer dynamic – it is now static and behaves like any other static PDF.
Dynamic PDF – Dynamic PDFs allow the layout of the form to be altered either through user interaction or through script. An example is a form that adds subforms based on a user input. If a static XDP is rendered with LiveCycle Forms with the Render At Client option set to “Yes” then the resulting PDF is no longer static – it is now dynamic and behaves like any other dynamic PDF. 
Acroform – A non-XFA based PDF form, usually created directly in Adobe Acrobat (as opposed to using LiveCycle Designer).
When I tried running the following code
formApp = CreateObject("AFormAut.App")
acroForm = formApp.Fields
If the form was saved in Adobe LiveCycle as Static, acroForm would contain all of the fields from the form, however if it was saved as dynamic, no error was thrown, but acroForm would not contain any fields.  Both static and dynamic forms use XFA streams (Adobe's flavor of xml) to render the pages, but the underlying structure and the way the form is displayed can be dramatically changed in a dynamic form.  It would appear that my code was unable to access the fields, because the structure of the fields on a dynamic form can change after it is rendered.  A field that was on page 1 to start with could end up on page 10 after the client using the form made some selections that altered the form or even problematically before the form was first rendered.  

To fix my issue, I just went into Adobe Lifecycle and used the save as function to save the dynamic forms as static forms.

Thanks to the following links that helped me figure this issue out.

Tuesday, August 5, 2014

Installing a Service

I learned how to install a service yesterday from the command line.
  1. Pull up a command window
    • Start bar, type cmd and click cmd.exe.
  2. Change directory to the correct Microsoft.net framework: For me the directory was at:
    • cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
  3. Execute installutil
    • C:\Windows\Microsoft.NET\Framework\v4.0.30319>installutil C:\(location of the service)\Myservice\Bin\Myservice.exe
  4. Start the service
    • Open the Window Services list
      1. Open a run box.
      2. Type services.msc and press return.
    • Right Click the service and select Start.


When making changes to the Service, make sure to uninstall the service before re-installing it.
  1. Stop the service
    • Open the Window Services list
      1. Open a run box. 
      2. Type services.msc and press return.
    • Right Click the service and select Stop.
  2. Close the Window Services list
  3. Pull up a command window
    • Start bar, type cmd and click cmd.exe.
  4. Change directory to the correct Microsoft.net framework: For me the directory was at:
    • cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
  5. Execute installutil with /U Parameter
    • C:\Windows\Microsoft.NET\Framework\v4.0.30319>installutil /U C:\(location of the service)\Myservice\Bin\Myservice.exe

Thanks to Jayesh Jain for the great article on Creating a Windows Service in VB.NET 


Using Powershell to create a Csv list of files in a folder

I wanted to be able to compare a list of files in a folder with a list I had from a table in the database.  There had to be a better way than just printing up the database list and checking them off one by one.  That's when I learned about Windows Powershell. Apparently Powershell is "Microsoft’s new command console and scripting language."  I found instructions on the internet on how to create a csv file of all the files in a folder using the Powershell cmdlet, Export-Csv.  From the Microsoft Technet site: "The Export-Csv cmdlet makes it easy to export data as a comma-separated values (CSV) file; all you need to do is call Export-Csv followed by the path to the CSV file."

When you install Windows Powershell, there is supposed to be a shortcut by clicking Start, pointing to All Programs, pointing to Windows PowerShell 1.0, and then clicking Windows PowerShell. Powershell was already installed on my computer, but I couldn't find it there and had to go to C:\Windows\System32\WindowsPowerShell\v1.0 to find PowerShell.exe.

To create a csv file of all the documents in C:\Users\djspecht\Documents and place the csv file in the same folder, the command would go like this. (Commands are not case sensitive.)

PS C:\> dir C:\Users\djspecht\Documents | export-csv C:\Users\djspecht\Documents\TestList.csv

Friday, August 1, 2014

Debugging a socket

I am quickly getting a taste of the following quote:

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian Kernighan
In other words, if you barely understood the code you were writing when you wrote it, you are going to have an extremely hard time trying to figure out issues with that code further down the road.  The iServer notification program I rewrote to alert users of readings of temperature and  humidity that were outside of excepted ranges is a good example.  My supervisor had me rewrite the program, taking out the threading that was used because he was concerned the threading might be causing some of the problems.  I did that and it mostly works.  (I still have an issue with socket connections timing out.)  I did, however, quickly realize why Gary used threads.  Connecting to a socket is very time intensive and it locks the program while it sits there waiting for the socket response.  Each iServer socket connection takes 10-15 seconds and with 32 iServers that equates to about 6-8 minutes for the whole process.  Gary's other program which monitors the iServers can get the readings for all the iServers in about 10-15 seconds. In other words, Gary is able to use threads to query all the iServers at the same time and keep his program from becoming unresponsive.  My program works, but I was concerned that it becoming unresponsive while it was waiting for all the socket connections would eventually cause problems.  So I found an example on the Microsoft developer network for using an Asynchronous Client Socket. It looked to be straight forward, but when I tried to implement the code, I got no benefits.  My code was taking just as long and was still locking up the application.  Well..., in order to make asynchronous calls to the socket, the example is using threading.  Obviously, I didn't understand enough about threading and where I needed to use it in my programming.  I believe the issue was that I was using the threads in my server class, when I needed to be using the threads outside the server class in the main class.  The thread needs to allow each server to try and make a connection with the socket and get the needed readings. While one server is waiting for a response, the thread needs to sleep and give a chance for the next server to make a connection.  That can't be done inside the server class. It has to be done from the outside.  Once again grasshopper, you still have much to learn!

Tuesday, July 22, 2014

Entity Framework - Compiling transformation warnings

I started getting Compiling transformation warnings when updating my Entity Framework Model.edmx file with new columns in 2 of the tables I was working on.  I managed to find the error online and discovered that the warnings don't cause problems and that Microsoft knows of and has no plans of fixing them.  I thought this was very interesting.  It gives a little glimpse into how a major company prioritizes the bugs/issues that they work on fixing within a piece of software.

The following two warnings show up in my Model.tt when building a VB edmx: 

Compiling transformation: Variable 'errors' is passed by reference before it has been assigned a value. A null reference exception could result at runtime. (line 622) 

Compiling transformation: Variable 'lazyLoadingAttributeValue' is passed by reference before it has been assigned a value. A null reference exception could result at runtime. (line 676)

Closed Sep 25, 2013 at 5:08 PM by RoMiller
EF Team Triage: As we start to plan the releases that follow EF6 we are doing a large triage effort on our backlog of bugs, features and tasks. Our aim is to have our backlog be a realistic representation of what we (or our contributors) may add to EF in the future.

This reduces the number of issues we need to sift thru as we plan each release. For example, coming into the planning for the set of releases after EF6 we had 600+ items on the backlog. A large number of these items are very low priority and will realistically never be addressed.

As a result of this we are closing a number of items as “Won’t Fix”. These items fall into one of the following buckets:
  • Items that are either low priority or expensive to implement and we don’t believe provide enough benefit to outweigh the cost of implementing (given that time spent implementing them would detract from implementing other features).
  • Items created by a member of the EF Team that we have not seen customers asking for and we don’t believe would provide significant benefit to customers.
  • Bugs that only manifest in corner cases and have workarounds.
These decisions are not final, if you disagree with this resolution for an item feel free to let us know.

Friday, July 18, 2014

Week 2

I am learning that one of the biggest things I need to do, which takes up more time than I think it ought to, is access data from the database.  For the iServer project I have tried to keep the data separate in a Data class.  After researching it more on the internet, it looks like there might be a better way using entities.  According to Wikipedia, "an entity is something that exists in itself, actually or hypothetically." In programming, an entity is an object and is usually tied to a concept or business logic. It is often used to map the correlation between a database table and a class object. (Paliath 2010)  I remember talking a little bit about Microsoft's Entity Framework (EF) in class.  Entity Framework is Microsoft's "recommended data access technology for new applications." I tried start the project over using EF, but I must still need to install something, because it didn't work for me.  My only real hesitation with using it is possibly not having enough control over how it accesses the database.  I learned a lot from my SQL Server instructor, Patrick Callahan and would like to be able to use some of the stored procedures he taught for inserting into the database. Otherwise, it looks like it will greatly streamline the creation of a project that uses a database.

Now, for the most frustrating thing that I had happen to me this week.  I had been working on logging error information to a table and it suddenly stopped working.  As I was using the Visual Studio debugger, I noticed that my Device class didn't look like my Notification class or Server class when it initialized.  The other classes showed {WindowsApplication1.Notification} when I moved the mouse over them in debug mode.  When I moved the mouse over a Device it just showed { }.  I thought somehow I had broken the Device class.  I tried copying all the code from the class, delete the class and then recreate it.  I tried creating a whole new project and copying all the code back into it.  Nothing seemed to work.  I did notice that I was still getting back some data that could only happen by going through a device object, but I was still stuck on the idea that I had "broken" the class.  I finally started commenting out big blocks of the Device class and narrowed it down to my overrided ToString function.  Wow! A couple of hours wasted on something to which I now say, "Duh!" From this, I learned two valuable lessons.  First, the debugger displays an object's ToString value, which for user defined classes is the class name.  Initially, my device classes showed an empty string. The second lesson was not to get let yourself get too focused on one idea for a problem, especially when there is information that contradicts your initial thinking.

Saturday, July 12, 2014

Week 1

My first week as a programmer is behind me!  First of all, it is a lot quieter in my little cubicle than it was out on the 911 dispatch floor. I will miss the excitement of 911 calls and the constant interaction with co-workers.  I know they will continue to do an excellent job over there and I will miss them all! (Good thing I still get to come back and harass them on weekends.)

Task number 1 was to get me set up on a computer.  Who knew that would end up taking a day and a half.  Seems that our software source control program, SourceSafe 2005 doesn't play well with Windows 7. From this experience I have learned two things.  First, SourceSafe is no longer supported.  From what I can tell, SourceSafe started out as a good source control program, but per Jeff Atwood's blog, it "was never updated architecturally to reflect modern source control practices." I'm thinking that Microsoft's Team Foundation Server would be the most likely upgrade for us. Second, source control is very important if you have more than one person working on source code at a time.  A SCM (Source Code Management) tool allows coders to "check out" files, work on them and then "check in" the files to update the source code. The SCM tool manages multiple people working on the same files at the same time and allows everyone to have the most updated version of the code. The other important thing a SCM tool does is to keep a history of all the changes made.  You can use the history to go back to previous versions to see when or why something was changed.  You could roll back a bug fix if it has unintended consequences.  And most importantly, you can go back to your original version to reminisce on what your "baby" looked like in its infancy.

Task number 2 was my first chance to write code in my new occupation.  Most everything here is written in visual basic and uses SQL server.  The program makes requests using sockets for temperature, humidity and dew point from 31 iServer units throughout the county.  It's most important task is then to check and see if those values fall within acceptable limits for each device. If they don't, it sends a notification by email or page to all parties wanting a notification.  This function is not currently working and I was given the task of rewriting it.  The program's original author, Gary was a very nice hippie looking gentleman with a well styled pony tail. He was on the tonight show in his youth in a 1960's version of a boy band.  He also received commendations for his work on writing a management program for the local veterans agency. For all his wonderful qualities, I'm not sure Gary thought too much about someone else having to figure out his code later on. I must say, though, that it was a good learning opportunity as I had to work through following his code line by line and looking up things I didn't understand as I went.  Although Gary's code uses classes, it feels to have been written in more of a linear fashion.  I have been trying to rewrite it following object oriented standards.  I took all the code to access the database and put it in a separate class. There is a class for each of the iServers, one for the measurements for each device (temperature and humidity) and one for the notifications.  The data class populates all the data for the servers, measurements and notifications and then the server class takes over getting readings and sending out notifications.  I do feel like it has been a bit of slow go for me, as I still have the notification of the users to write.  The program originally used a lot of threads, which is where my boss believes the problem stems from.  I can see why Gary used threads, though.  Making request to the sockets is very time intensive and keeps the program from doing anything else while it waits for the requests to come back.  Right now, requesting temperature and humidity from all 31 servers takes just over 7 minutes.  Gary had written another program which showed all the readings in near real time and it would only take about 10-30 seconds to get all the readings.  So, we shall see if my program works.  In the future I would like to learn how to write it using async and await, but I think that will have to wait until we are using Visual Studio 2012 or higher.





Thursday, June 12, 2014

I start my first programming position July 7, 2014.  After having seen Kim Philpot's co-op journal blog, I am going to try and do the same.  Thanks for the inspiration Kim!