This is the first in a series of posts on VB. Net observations. It’s not formal; it’s just an online journal of things I found cool and weird coming from a VFP developer with 20 years of database language experience.
One of my tasks this past several weeks was to transfer product tests from a VFP application to a database in use by the rest of the Developer Division. I could have easily done this in VFP; as we Fox guys know, VFP is great for tossing data around.
However, I saw this as an excellent opportunity to get more comfortable with VS. Net and, specifically, VB .Net, which is the primary language the VS Data write tests in. I’d done some ad-hoc stuff up until now, and – of course – a lot of debugger work grabbing call stacks when VFP blew a rod. But to do this right, I was going to have to become very familiar with .Net classes and objects and the means of data access in .Net
It has always seemed to me that to understand a new programming language, one must first embrace the paradigms of the language – everything else is just grammar and syntax. So I started to play…..
One of the strangest things (to me) to get my brain wrapped around is that all variables are objects of various classes and have to be declared before they can be used. For example, in VFP we go:
nAmount = 17.50
And then we’re on our merry way….in VB. Net, we can do this two ways:
Dim nAmount As New Double
nAmount = 17.50
Dim nAmount As Double = 17.50
Easy, huh? Now suppose you want to store that to a character variable (String in VB). In VFP:
cAmount = STR(nAmount)
We use the STR function to transform nAmount into a string and store in to cAmount. In VB we can do it two ways. The new .Net way is:
Dim cAmount As String = nAmount.ToString
You see? ToString is a method intrinsic to the Number Object. Kind of like when we want to refresh a Form object in VFP, we use frmMyForm.Refresh. The other way is to use the CSTR function, which has been around the language for a while:
Dim cAmount As String = CSTR(nAmount)
Anyway, there’s a lot more to learn and more cool things to try. I’ll post again in a few days with more observations.