Andri Yadi

A geeky technopreneur, trying to do something big with his startup

August 2008 - Posts

  • PLN oh PLN

    Kemarin pagi, 21 Agustus 2008, sekitar pukul 1 dini hari, saat lagi gencar-gencarnya coding untuk mengejar deadline presentasi nanti siang, tiba-tiba aliran listrik dari PLN mati. Server langsung mati (maklum nggak pakai UPS) dan sebagian hasil pekerjaan (terutama database) masih di server. That's s*cks...

    PLN oh PLN..When are you gonna be better? Perusahaan Listrik Negara, sebuah nama yang menyiratkan tanggung jawab yang besar untuk menyuplai listrik kepada negara, tapi ternyata tanggung jawab tersebut belum bisa dipenuhi dengan baik. Tapi ya sudahlah...di posting ini gw gak akan bicara politik, korupsi, inkompetensi, dan incapability element-elemen dalam negara ini, gw yakin lu udah muak denger itu semua.

    Daripada BT dan bingung gak ada kerjaan, akhirnya gw ambil my brand new Canon DSLR EOS 450D dan Lensa Canon EF 50mm f/1.8 II, and start shooting. Berikut hasilnya...Yang mau kritik, be my guest, baru belajar bos..

    IMG_0597_cr

    Foto di atas kira-kira bertema "lampu nggak nyala, lilinpun jadi". Atau bisa juga "Lampu vs. Lilin".

    IMG_0586-er

    "Listrik padam, kerja jalan terus", mungkin kalimat itu yang tepat menggambarkan foto di atas. Model: Mujtahid Abdulhaq, Developer, DyCode. Seseorang di balik laptop adalah Arie, Project Manager, DyCode.

    That's it for now. More photos to come...

    PS: Buat Dondy, sorry Don...gw gak jadi beli kamera lo :) Buat Reza, kapan hunting? Udah beli lensa 50mm-nya belum ;)?

    Share this post: | | | |
  • VBA vs. VSTO

    Several weeks ago, a client asked my company to be involved in a project to develop some kind of customizations for Microsoft Excel using VBA. Visual Basic for Applications or VBA? Hmmm…sounds like an old stuff. I remembered playing with VBA when I was in college. Watching my computational physics professor cracking RSA encryption by only using VBA was impressive. He also visualized Kinematics translations, fractal, and electrical field using VBA. Oh...I missed old days. Just for my nostalgia, here are some captures of physics fun stuffs using VBA.

    image 
    Fractal

    image 
    Electrical Field

    VB veterans or Microsoft Office advanced users should know VBA. It’s the only way you can do some automations or customizations to Microsoft Office products, well at least until 2004. Along came Visual Studio Tools for Office (VSTO) v1 at 2004, introduced another option for doing stuffs like VBA did.

    Back to my client story, I asked them why we don’t use VSTO instead of VBA. Then they asked back, why we should use VSTO. What are VSTO advantages compared to VBA. OK, this blog posting is all about it. Trying to answer many questions to me about VBA vs VSTO, I try to compare them here.

    After reading and compiling from many references, and by adding some experiences using those both technologies, I come up with this list. Since this comparison are meant for everybody, I try to explain as detail and general as possible.

    1. Leverage .NET Framework

    The most fundamental difference between VSTO and VBA is that VSTO based on Microsoft .NET Framework. All .NET developer should know the advantages that .NET framework offers. It includes a large library that cover a large range of programming needs in a number of areas. As part of .NET technology, VSTO inherits that richness. At the very basic level, VSTO has access to .NET Base Class Library (BCL) that includes basic functionality, including Collection, Input Output (IO), Globalization, etc. VSTO also has access to some .NET Framework Class Libraries (FCL), such as XML processing, ADO.NET, LINQ, Windows Forms, WCF, etc.

    The rest of the list are the consequence of this point. If you don’t have time to read, you can stop here :)

    2. Development Productivity

    Despite I’m a coder and my passion about technologies, at the end I’m also an businessman. When it come to business, productivity must be taken into account. Mostly, productivity is all about tool.

    Why on earth using VSTO is more productive that VBA? Well, as its name, developing using VSTO means using world-class IDE, Visual Studio. Compare it to VBA Editor within Microsoft Excel or Word, I think it's just not fair to compare them. More over, Visual Studio seems will be more and more improved by Microsoft in the future, while VBA Editor is not. I’ll talk more about productivity as I go along with this list.

    3. Language features

    Since VSTO is based on .NET framework, it has access to all .NET language features. As we know, coding using .NET means coding using .NET compatible languages, such as VB.NET and C#. Unlike VBA that should be coded using Visual Basic language (which is a procedural language), coding VSTO allows us to code using VB.NET or C# (which are pure Object-oriented Programming language).

    I won’t tell much about OOP advantages compared to procedural language here. Some points I’d like to highlight here are reusability and error/exception handling. As we know, OOP language allows us to achieve reusability through its features, including: inheritance, polymorphism, abstract classes, and interfaces. VBA is failed to perform those stuffs (at least not pure) so it’s quite hard to achieve reusability. In term of error handling, VB.NET and C# also have language construct called try…catch…finally that makes a nice, elegant way to prove your code's infallibility. In VBA, error handling is performed using GoSub, GoTo, or On Error statement, that will lead to frustration as your code grows.

    The latest VB.NET 9.0 and C# 3.0 features are accessible from VSTO, including: Automatically Implemented Properties, Implicitly Typed Local Variables, Extension Methods, Lambda Expressions, Object Initializers, Collection Initializers, Anonymous Types, and Query Expressions. All those new features are the basis of the great technology like Languange-integrated Query (LINQ), that adds SQL-like query capabilities to .NET language for querying array, collection, XML, and RDBMS.

    4. Application level hooks

    VSTO can access many application level functionality, such as Ribbon, Custom Task Panes, etc. Using VSTO, you can develop application level add-in that will always be available regardless opened document. By contrast, VBA customization is document level.

    5. Customization Code Separation

    Unlike VBA, where customization code is stored in the documents file themselves, code written for VSTO are compiled and store in separate .NET Assembly which is associated with the documents by means of custom properties. At runtime, that assembly is loaded on the fly. This separation allows us to easily maintain the customization and apply security constraints (I talk more about this later).

    6. UI Customization

    When it comes to user interface, VSTO provides more complete functionality compared to VBA. VSTO allows us to customize Task Panes that is impossible in VBA. Task Pane is an specialized pane, typically shown on the left, introduced in Office 2003 that can display additional controls or functionality you can do on document. You can drag and drop all Windows Forms controls into Task Panes and use them as you can do in Windows Forms development. You can also use Data-bound controls and Data Sources to easily bind data from DBMS into Task Panes. If you have controls built using Windows Presentation Foundation (WPF) technology, you can host them on Task Panes. All you can do on Task Panes, can also be done on Outlook Form Region, which is a custom form developed to extend Outlook UI.

    It's also easy to customize Ribbon, an UI element introduced in Office 2007. You can use VBA to customize the Ribbon using RibbonX, but VSTO makes it even easier by providing a Ribbon designer that makes adding new tabs, groups, and controls to the Ribbon as intuitive as adding a control to a Windows Form.

    7. Source control

    Like any .NET projects, you can use Source Control server like Team Foundation Server (TFS) to facilitate collaborative development for VSTO-based project. All VSTO project artifacts can be checked in/out to/from TFS server, including Office document (xls, xlsx, doc, docx, etc). As far as I know, there's still no add-in or provider in Excel or Word to control VBA project source code using TFS. However, there does exist some add-in for
    Access/Excel to work with Source Safe to version control the VBA project. For example, here's the add-in for Access 2003: http://www.microsoft.com/downloads/details.aspx?familyid=2ea45ff4-a916-48c5-8f84-44b91fa774bc&displaylang=en 

    8. Distributed System

    When it's first introduced, one of .NET buzzwords is XML Web Services. It introduced the very easy way to develop web services-based application, more generally, service-oriented or distributed application. .NET also introduced Remoting for more native way to implement Remote Procedure Call (RPC). Start from .NET 3.0, all those technologies now converge into one technology called Windows Communication Foundation (WCF).

    Since VSTO is a part of .NET, it inherits all cool technologies like WCF. In other words, it's easy to develop VSTO Add-In to access XML Web Services, for example. It's same as like you do when you access XML Web Services from ASP.NET or Windows Forms, just Add Web Reference (or Add Service in VS 2008) to create proxy classes, and use those classes. And all that functionality is built-in. Compare to VBA that you need certain add-on to be able to access Web Services. You can read more about Calling XML Web Services from VBA.

    9. Deployment

    No matter how well an application runs while it's on development, deployment can be an issue. Deployment is not only about installation on users' computer, it's also about patching, version update, and maintainability. Since VBA application is embedded in the document itself, it's easy to install the application on users' computer by only copying the document. But when it comes to update the code, you have to open the document and change the code manually. Just imagine how that can be done for many users environment.

    On the other hand, as the nature of VSTO, the customization code is stored separately in .NET assembly (*.dll file) that actually linked to the document (for document-level customization) or Office application (for application-level customization). That .NET assembly can be deployed to a central location and all the documents just link to it, that will make updating quite easy. Updating can be configured so it can be checked every time the document is opened, or by specific period (7 days, one month, etc).

    Furthermore, VSTO supports two deployment models

    Also refer to this blog about VSTO v3 Deployment Session.

    10. Security

    Lets face it, it's difficult to trust VBA code, as evidenced by the high number of VBA macro viruses those have been developed. In VBA, there are three basic security options:

    • Set the security settings to high on user machines and digitally sign your code.
    • Let the user decide whether or not to trust the code when presented with the macro virus warning.
    • Set the security to low to allow all code to run (including malicious code). Note that this third option should never be used

    Those security options must be selected and configured by user manually.

    Lets compare to VSTO security model. The VSTO security model involves several technologies: the Visual Studio Tools for Office runtime, ClickOnce, the Trust Center in Microsoft Office, and the Internet Explorer restricted sites zone. During installation, here is the sequence of security check (taken from MSDN Documentation).

    - Microsoft Office security checks

    image

    - Runtime and ClickOnce security checks

    image

    - Runtime inclusion list checks

    image

    If you still don't trust it, then you're so paranoid :)

     

    I think the comparison list is enough for now. But there's possibility that the list will grow as the VSTO will be improved more and more along with .NET update. Currently, VSTO is version 3 or VSTO v3. I assume there're will be v4, v5, etc, following the new release of .NET framework. On the other hand, VBA will no longer be improved, although there's still no plan from Microsoft to retire it.

    By this post, I'm not trying to make a war between VBA and VSTO. It's just a matter of choice. When it comes to choice, it's fair to compare them. Actually, VBA and VSTO can become friend. Many blog posts and articles those talk about interoperability between those two, for example: Extending VBA with VSTO 3.0. The interoperability is only possible by using VSTO v3.

    That's it. Enjoy.

    Share this post: | | | |
    Posted Aug 20 2008, 02:19 PM by andriyadi with 11 comment(s)
    Filed under:
  • 08/08/08 08:08:08

    What happen at that time? Well, nothing special happens for me. At that time, probably I was coding, preparing application and presentation slide for presentation to client later after lunch.

    Look like many couples plan their marriage on this day. Rebecca Dolgin, an executive editor at wedding resource company The Knot, said more than 22,000 couples registered online for Aug. 8, 2008, weddings between TheKnot.com and WeddingChannel.com. An average Friday during the summer wedding season has 5,000.

    In Asian cultures, the number eight is considered a lucky number for building wealth and affluence; hence, the Summer Olympics in Beijing opens on 8/8/08 at 8:08:08 PM.

    In Chinese language and dialects, the number eight sounds similar to words such as wealth and fortune. On a numerological level, the number eight represents the evolution of life. The two perfect circles together are a symbol of learning the lessons of Earth before transcending to a higher spiritual dimension, therefore transforming the material pot of gold to spiritual prosperity. This signifies birth and death with a need of spiritual evolvement and understanding to be able to acquire the riches of the Earthly existence.

    The two circles that make up the number eight, when viewed horizontally, show as a symbol for infinity and eternity. In astrology, it represents the eighth sign of the zodiac, Scorpio, which is a highly passionate and determined star sign, and also represents the cycle of birth and death. It is considered a powerful number - and here are insights into how wealth and money corresponds to each star sign.

    What is my zodiac for 08-08-08?

    ARIES (MARCH 21 - APRIL 19)

    Wealth-creation strategy: Aries star sign people are go-getters who like to have more than one project on the go at once. They don't mind taking a risk to get what they want and feel more comfortable running the show than being a follower. They are best placed when they can initiate the deals, then hand them over to others to fulfill. Excitement and a fast pace is a dream come true for an Arian. However, they do need to be careful of rushing into things. If in too much of a hurry, they could miss out on an even better deal.

    Chinese proverb: To know the road ahead, ask those coming back.
    {Adapted from http://www.nydailynews.com}

    What about you? What do you do at that time?

    Share this post: | | | |
  • Synchronizing Task Pane Visibility State and Toggle Button on Ribbon

    Menjawab pertanyaan, keluhan, dan tantangan dari sdr Dondy :) yang terungkap pada saat ngobrol-ngobrol di acara Heroes Gathering (2 Agustus 2008, di Gunung Putri Bogor), gw posting tulisan ini.

    You know Task Pane in MS Office products right (refer to picture below)? The question is how to control task pane visibility from a toggle button on ribbon. If the toggle button is checked (bevel in), the task pane is visible, and vice versa. What if the task pane is closed by clicking "x" button on it? Then toggle button state must reflect that closing by showing unchecked state. So, the problem is how to sync task pane visibility state with toggle button checked state. How can I do that using VSTO?

    image

    Toggle button is checked --> Task Pane is visible

    image

    Toggle button is unchecked --> Task Pane is not visible

    Here is the workaround using VSTO v3. In this example, I use project template Excel 2007 Add-in.

    1. Create new project Excel 2007 Add-in, name the project whatever you want

    2. Add new Ribbon (Visual Designer), name it whatever, lets say MyRibbon. When Ribbon visual designer is appeared, drag Toggle Button control into the ribbon. Set toggle button's Label to "Task Pane", and set its name to "toggleButton_TaskPane". The result is:

    image

    3. Code the ribbon.

    using System;
    using Microsoft.Office.Tools.Ribbon;
     
    namespace ExcelCustomTaskPane
    {
        public partial class MyRibbon : OfficeRibbon
        {
            public MyRibbon()
            {
                InitializeComponent();
            }
     
            private void MyRibbon_Load(object sender, RibbonUIEventArgs e)
            {
                IsTaskPaneVisible = Globals.ThisAddIn.ctp.Visible;
            }
     
            private bool isTaskPaneVisible;
            public bool IsTaskPaneVisible
            {
                get
                {
                    return isTaskPaneVisible;
                }
                set {
                    isTaskPaneVisible = value;
                    toggleButton_TaskPane.Checked = value;
                }
            }
     
            
        }
    }

    3. Add a User Control to as a content for Task Pane, name it MyTaskPane.cs. For simplicity, I just drag DateTimePicker control into that user control.

    image

    4. Find ThisAddIn.cs in solution explorer, open it, and write this code:

    using System;
    using Microsoft.Office.Tools;
     
    namespace ExcelCustomTaskPane
    {
        public partial class ThisAddIn
        {
            private MyRibbon ribbon;
            internal CustomTaskPane ctp;
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                ribbon = Globals.Ribbons.MyRibbon;
                ctp = this.CustomTaskPanes.Add(new MyTaskPane(), "My Task Pane");
                ctp.Visible = true;
                ctp.VisibleChanged += new EventHandler(ctp_VisibleChanged);
            }
     
            void ctp_VisibleChanged(object sender, EventArgs e)
            {
                ribbon.IsTaskPaneVisible = ctp.Visible;
            }
     
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }
     
        }
    }

    5. Back to our Ribbon. Double click to Toggle Button and write code to handle its click event:

    private void toggleButton_TaskPane_Click(object sender, RibbonControlEventArgs e)

            {
                Globals.ThisAddIn.ctp.Visible = toggleButton_TaskPane.Checked;
            }

    Globals.ThisAddIn.ctp refers to ctp field in ThisAddIn class, which is an instance of CustomTaskPane.

    That's it. Now, you can run the project and see how it works.

    The key here is handling VisibleChanged event of CustomTaskPane. When Task Pane (referred as ctp object in our code) visibility state is changed (visible become not visible, and vice versa), that state should influence toggle button state. On the other hand, toggle button state should influence task pane state.

    If you use Excel 2007 Document or Template project (you are developing Document Level Customization in VSTO), working with Task Pane can be done by using ActionsPane object. Unfortunately, you can't capture VisibleChanged event of ActionsPane (even the event is available). And I still can't figure it out.

    That's it. Find the attachment for complete solution.

    Dondy, gitu kan pertanyaan lu? Kalau bukan, lets discuss it further. Kalau udah solved, berarti Sony DSLR A-300x-nya bisa turun harga lagi dong :) Good luck.

    Share this post: | | | |
    Posted Aug 04 2008, 04:56 PM by andriyadi with 3 comment(s)
    Filed under: