YuviSense: Codin Kid

Yuvi, a 17 year old wannabe geek from India.
  • rss
  • Blog
  • Photography
  • Indians on Twitter
  • About Me
  • Contact

[Tech]VB.NET Scripting

May 7, 2006 | 7:31 pm
Hi guys. Lately, I’ve been into a number of Late Bound, Dynamically Typed Languages. But, the .NET Framework itself ships with two Dynamic Languages. One is easy to spot, in the form of JScript.NET. But, the other one is much more mainstream and harder to spot: It’s VB.NET. Yes, VB.NET can be turned into a Dynamic Language with just TWO Lines of Code. Well, I know many VBers know this, but for those who don’t here are those 2 lines:Option Strict Off
Option Explicit Off

Well, I know turning them on is considered a good practice, and they are on by default. But, setting them to off lets you do some pretty amazing things, like :

d= 100
console.writeline(d.GetType) 'Prints System.int32

d = 123123123123123
console.writeline(d.GetType) 'Prints System.int64

d = "Hello Guys!"
console.writeline(d.GetType) 'Prints System.String

d = new System.Diagnostics.Process
d.Start("cmd.exe") 'This ACTUALLY starts a new a new Command Window
Console.Writeline(d.GetType) 'Prints System.Diagnostics.Process

So, the type actually changes every time you assign something to it! Well, that's not amazing, since you can just do the same in C#. But, it's elegant, without casts[which I absolutely hate]. So, this is called
Late Binding
.

And, variable d is not declared before. Well, what's the advantage of this ? Well, nothing. Although some people will say that Boxing and Unboxing along with Late Binding will slow down performance, I don't think that will be very noticable unless you're doing some very deep recursion or nesting.

Only catch is, as of now, VS won't offer you complete Intellisense, and Late Binding uses Reflection, which is quite a bit slower. But, VB9 actually goes a really long way into solving these problems. Have a look at the VB Future section at MSDN for some more cools tuff about VB9.

And, what is the use of it ? Well, with this, VB.NET is the most powerful Scripting Language I Know
. How ? Well, the .NET Framework is all encompassing, and I can always call into the Win32 API if I want something not there. And, mostly, whatever I want to do, .NET offers it. So, why learn something new, when I can use a powerful language as my Scripting Language ? And, that too, a language I love:D

So, here’s a small script I wrote, using my previous snippet to get thumbnails of images, to convert a folder of photos into 800×600 size, enough to reduce size without compromizing quality:

Dim s As String = "C:\School Pics\100OLYMP\Edited"

d = New IO.DirectoryInfo(s)
i =Drawing.Image
Console.writeline (d.FullName )
console.WriteLine(d.GetFiles.Length)
Console.ReadKey
For Each f In d.GetFiles

If f.Extension.ToUpper.Contains("JPG") Then
Console.WriteLine ("Processing : " & f.FullName)
i = drawing.Image.FromFile(f.FullName)
i.GetThumbnailImage(800,600, Nothing, System.IntPtr.Zero).save _
(d.FullName & "\Thumb" & f.Name & ".jpeg", _
drawing.Imaging.ImageFormat.Jpeg)
End If
Next
console.ReadKey

Prefix that with a Module and Sub Declaration, and you've got a little neat script that runs fast, and converts everything in the folder I specified to my Size of 800x600. Well, try doing that in, huh, Batch Files, and see the pain....:D

Well, I'm investigating how latebound calls are translated to IL, and I'll post something about it very soon....

Till then, keep coming, and keep commenting:D

And, thanks for reading this rather long article...

Technorati Tags: VB.NET, Dynamic VB, Dynamic Language, VB.NET, Image, Scripting, Thumbnails

Categories
Tech
Comments rss
Comments rss
Trackback
Trackback

« [NetBeans]First Start… Saki-yea…. »

One response

Greets to the webmaster of this wonderful site! Keep up

Anonymous | June 8, 2006 | 7:10 pm

Greets to the webmaster of this wonderful site! Keep up the good work. Thanks.
»

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Contact Me

Email: yuvipanda@gmail.com
IM: yuvipanda@msn.com
GTalk: yuvipanda

My Photos


View my Flickr Page

My Badge


IndiBlogger - Where Indian Blogs Meet

Archives

  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox