Stephan Dekker

If you are out to describe the truth, leave elegance to the tailor. (Albert Einstein, 1879 - 1955)

December 2009 - Posts

 

Create your own VBA module in Excel:

Sub exportAllModules()
    
     '  reference to extensibility library
    
    Dim objMyProj As VBProject
    Dim objVBComp As VBComponent
    
    Set objMyProj = Application.VBE.ActiveVBProject
    
    For Each objVBComp In objMyProj.VBComponents
        If objVBComp.Type = vbext_ct_StdModule Then
            objVBComp.Export "C:\temp\" & objVBComp.Name & ".bas"
        End If
    Next
    
End Sub

Add reference to:

Microsoft Visual Basic for Applications Extensibility

Give trust to the macros:

1. Open Excel 2007.
2. Click the Office Button (top-left most button in the window)
3. Click the Excel Options button.
4. Click Trust Center in the menu on the left.
5. Click Trust Center Settings in the window on the right.
6. In the new window that opens click Macros in the menu on the left.
7. Check the box next to Trust Access to the VBA project object model.
8. Click OK.
9. Click OK.
10. Close all Office applications and try your project again.

 

Happy days!

Posted by Stephan Dekker
Filed under:

For one of my customers I needed to run a financial risk calculation on a Solaris box. The original app is written in C# .NET and targeted for Windows usage. Given my 2 previous posts, it shouldn’t come as a surprise that I choose to use Mono to run the app on Solaris. The whitepaper said I could, so sure it will work.

As said, I created a Ubuntu VM in about an hour(!), configured it in another hour and was ready to do the actual Mono work. Ubuntu has Mono installed by default, so all I had to do is compile the app (and run DotFuscator, just for good practice) , copy it to the linux box via a fileshare on my physical machine and copy it to a folder on the linux box. Happy days, it all works fine.

With that POC working, I ticked the box for managing risk around running the app with Mono and running Mono on Linux. The latter was actually only ticked half, as it was pre-installed, but being a poor dev and not sticking to proper Agile practices, I ticked the box anyway J

I got the login details of the SUN box, which I didn’t have to install and configure luckily. What I read and have heard, Solaris is a whole different installation experience as opposed to Ubuntu. I’m not sure if SUN has the ability to download a Solaris box as a VM, but I had the real thing and a powerfull one as well, so why bother with VMs.

Another happy moment, was when I got the choice of logging in with console or through the XWindows. XWindows please, thank you! J

First thing after logging in was to open a console and try “mono -?” Doohh!!!! No Mono!!!

Off to the Mono-project website to see what they are saying about this topic:

http://www.mono-project.com/Other_Downloads

Basically you need to install a tool to install other packages, so it’s sort of the open source “Windows installer” tool. The installer tool uses the underlying “pkg-get” (The “Windows installer service”) to actually install the packages (MSIs). The difference is that the unix tool uses a list of packages you can install. In our case you can invoke it like: “TheInstallTool –i mono” and it will install mono.

The tool is called “pkgutil” and can be found on: http://www.blastwave.org/. On the first page there is a little bit hidden link, called “READ THE HOWTO”. CLICK ON THAT!!! This will take you to a page of instructions.

Step 1: Be Patched Up To Date

I didn’t know: A) how to do this, B) wether I was or needed to do it in the first place. So I assumed I was up to date and soldiered on...

Step 2: Install pkgutil

That’s the tool we need to install. Make sure you’ve got the correct version of the script, but in my case I ran the following commands:

·         uname –a

·         cat /etc/release

·         pkgadd -d http://blastwave.network.com/csw/pkgutil_`/sbin/uname -p`.pkg

·         mkdir /etc/opt/csw

·         cp -p /opt/csw/etc/pkgutil.conf.CSW /etc/opt/csw/pkgutil.conf

You should end up with an exact copy of the log up on the blastwave website. I actually had one error/warning that the /etc/opt/csw already existed, but that did stop me from continuing.

Step 3: Fetch the Software catalog

Makes sense doesn’t it? When you have an app that can install from a catalog, to download it?

/opt/csw/bin/pkgutil --catalog

Step 4: Security First!

Yeah right, on to step 5...

Step 5: Before you proceed...

Don’t mess with the root account... yadda, yadda, yadda... Ok, I’m done.

Well, as it turned out. I wasn’t. The very important bit is in the second last paragraph, to set the path: PATH=/opt/csw/bin:/usr/sbin:/usr/bin:/usr/dt/bin:/usr/openwin/bin:/usr/ccs/bin

That took me an hour to figure out where the bloody hell Solaris installs the files. Hiding details is great until stuff goes pear shaped. Also RTFM applied, very true. Let’s call it a draw.

At that stage my “mono –?” did return me something! Not sure anymore wether it showed me the Man page or complained about incorrect commands, but the mono command was found and that meant: On to the next stage!

I copied the DotFuscated, on windows compiled to the “All CPU” target,executable (the bin/debug/MyRiskConsoleApp.exe"/ to a filer in the cloud. Went back to the SUN box, opened Firefox and copied it from the filer to the machine.

I’m sure you can imagine that I was very excited when the command: “mono /users/sdekker/Desktop/MyRiskConsoleApp.exe 1000 2” didn’t came back with errors, but with the calculated results!

I explained the coolness to my wife, but I don’t think she really grasped my excitement of it all... J

Another job well done, Stef!!

Posted by Stephan Dekker
Filed under: , ,

I already figured it out from the website, but it's nice when the website is actaully correct: Ubuntu comes with Mono installed. Some apps, F-Spot for instance, need it, so it's installed out of the box.

I just compiled a hello world, console app, copied it to my virtual Linux box (Share on my Win box asVirtual PC doesn't allow higher resolutions than 800x600 for some reason and that makes the Ok button for the "Sharing permissions" window, drop out of reach) Browsing to my local box btw is a pretty awesomeexperience. Not as awesome as, let say, diving with whales, but still.... You open up the "Windows Network" folder, the machine then goes off and finds you all the domains on the network, which is, in my case, My own AD domain at home, My company AD domain as I'm using my work laptop, Workspace and another insignificant one. Probably my router come to think of it... So you'll double click on the domain you need and it go out and find all the machines on that domain. If you then double click on the machine it asks you to login, so I punched in the username, domain and password and Bang! I'm in!!

Sorry, focus....

So compiled my hello world console app, opened linux pulled it from a share on my windows host OS and copied it into a folder under my user account. Don't know if that matters, but just to be safe. Double clicked.....   Error.... Damn....   Double clicked again.....  Error again.... Bloody computers, allways so consistent....

What you need to do is run it with mono. (Mind the lower case btw.) So open a console window and use:

mono DotNetHelloWorldApp.exe

And capow!!! a nice hello world message is staring right in the face!

I haven't tried any fancy stuff, but I have seen windows and other trivial .NET features being used, so it shouldn't give me a lot of grief.

Take care!

 

Posted by Stephan Dekker | with no comments
Filed under: ,

I last worked with Linux ages ago and now need to run a couple of tests with Mono on a Linux box. I'm not counting a couple of Cygwin incidents during my working days at “Vrije Universiteit”, as that's not Linux, that's actually sort of cheating. :-)

So, to brush up my skills I took it upon myself to finally try Ubuntu Linux. I downloaded 9.10 and apparently they are now naming the versions. This version is labelled "Karmic Koala" which seems too much of a coincidence (I live Down Under for a couple of years)

Anyway: Downloaded the ISO, fired up a fresh Virtual PC, mounted the CD and choose Install from the boot menu. Waited for 30 min and Happy Days! The machine comes up with a nice brownish background and starts asking about time zones, keyboard layout, etc. I punch in all the details, give a username and password and all done!

It works fantastic. I must say that Linux has come a long way as an OS. It’s slick, no driver nonsense, all goodness.

I’m now setting up file sharing, which means installing and running Samba if I remember correctly and that did give me some grief. Apparently if you choose DHCP, that doesn’t include the default gateway settings, so you need to set that yourself through the console:

route add default gw 10.0.0.138

But if you try that, you’ll get an error stating that you do not have the permissions. You need to be Root to do that, which your not. Even though you are in the admin group by default, that is not the same as root. The root password btw is set to a Hash at installation and the idea is that the root account should not be used at all. You could, if you really wanted do that by setting the password to a known one, but as it’s against guidelines, let’s not.

Instead, we need to raise our own level of authority to the root level with the following command:

sudo -i

Ubuntu does that a lot btw. You’ll get a dialog, very familiar from Vista or Win7, asking you to punch in the password to raise the level. In this case, as we are running it in a console, we need to do it with a command.

Anyway: Now we have internet access, lets run the updates. Holy crap! 158 updates!! That will take me all night!!

Pfew, this is Linux land and not Bill domain. An update is in average 0.5 MB, so running the updater takes as long as for me to type this blog! J

Hopefully, I can now set up file sharing and do the POC with Mono. Exciting stuff!

Posted by Stephan Dekker | 2 comment(s)
Filed under: ,