Monday, June 25, 2012

How to Downcast in VB.NET

Visual Basic (VB) is a computer programming language and integrated development environment (IDE) developed by Microsoft based on the Basic computer language. The .NET version allows programmers to create programs for the .NET Framework. Downcasting, as it refers to programming, is the process of refining a reference from a derived class to its base class. Downcasting is mostly seen in C++, C# and Java programming languages, but it can also be done in VB.NET. In VB.NET, casting is usually automatic once an object has been assigned to a variable. However, you can turn off the automatic casting function and specify the downcasting in the VB.NET code. 

Instructions:

1. Open VB.NET or Visual Basic 2010. The .NET version of the IDE is the first to use the .NET Framework. The 2010 version also allows for programming with the .NET Framework. Choose to open an existing project or start a new one from the Welcome screen.

2. Click on the "View" menu item and then "Code" to open the Code Editor. You can also right-click anywhere on a form and then "View Code" to also open the Code Editor.

3. Change the "Option Strict" property to "On" at the top of the VB.NET code by adding the following line:

"Option Strict On"

This turns off the automatic casting function in VB.NET and ensures that the only casting that will be done will be specified by the programmer.

4. Use the "DirectCast" operator to do explicit casting. Also, use the "GetType" operator to ensure that the object that you are working with is valid for downcasting. For instance, if you want to do downcasting on a text box, the code will be:

"Dim x As System.Type

x = txtExample.GetType()

MessageBox.Show(x.FullName)

If TypeOf x Is TextBox Then

x = DirectCast(txtExample, TextBox)

End If"

5. Click on the "Save" icon to save the changes to the code.

 


 

Thursday, June 7, 2012

Psalm 42:5, 42:11 and 43:5 all say the same thing.

Why are you downcast, O my soul?
Why so disturbed within me?
Put your hope in God,
for I will yet praise him,
my Savior and my God.
I’ve recently be trying to impart wisdom to my teenage daughter. As most of you know, imparting wisdom is a difficult thing for most of us. However, unfortunate or not, most of us have plenty of experience to reach back to which helps us offer up the “life-type” of wisdom. In the end, I guess this type of wisdom is more real than anything else we could use.
If you’ve ever heard my college time stories, then you’ve heard all of the gory detail of how I basically just threw away a 4 Year Air Force scholarship. It was a difficult time in life of going from being a teenager with no real responsibilities to becoming the adult we all have to become whether we want to or not.
During this time, the enemy threw plenty of ideas, philosophies and “new” thoughts on religion my way in order to dissuade me from following the Truth. This came through other people sharing their philosophies with me, through the many new and different churches I tried out, and through fellow college mates. The one thing that seemed to pull me through all of this were the verses mentioned above.

There were times I could not feel God or sense God. I was not experiencing His power or presence. I felt all alone. And the temptation to follow some of the “new” thoughts or paths was there as well. It was then the Holy Spirit gave me these 3 verses. If you will notice, they all say the same thing. And God said it to me 3 times that day so I would hear what He was trying to say.

No matter what I was going through, no matter how bleak things seemed, no matter how confused I was or lost I seemed … I only had to look back on my life and remember the times where God was more real than ever … and this enabled me to remember and believe those times would once again be true in my life.

I will YET praise HIM …
Things will always get bad at times in life. Ours is to remember that God is God during the bad times just as well as the good times. Ours is to be faithful to Him no matter what.