Some more differences between PHP and VBScript

For anyone who does read the HTMLCenter blog regularly, I must apologize for slacking a little bit lately. Up until a few weeks ago, I had been trying to release a new post every other day. However, recently I’ve been elbow-deep in programming, and haven’t had much energy to make blog posts, resulting in some posts being spaced out three days or more apart from each other. Here’s an update on what I’ve been doing.

First of all, we’ve had a lot of stuff going on at work. I’ve been in meetings pretty much all day each day for the last three or four business days. I attended a conference and worked on a few new initiatives with varied groups of people. I also had to make a presentation at each of our campuses over the last few days.


In the midst of all of that, I’ve been busy debugging a few problem applications I put together in VBScript. It’s very difficult for me to switch back and forth sometimes between VBScript and PHP. For non-programmers out there, using VBScript and PHP at the same time is similar to trying to switch back and forth between French and Spanish. The two languages use similar logic and syntax, so it’s easy to get confused. However, they have very different functions and differing fundamental rules of syntax. For instance, in both languages, it’s possible to write an if…else statement. However, the way you write those statements is drastically different, and if you mix-and-match the two versions, you’ll end up with errors in both. A VBScript if…else statement looks like:
If foo=bar Then
Response.Write("foo is equal to bar")
Else
Response.Write("foo doesn't look like bar to me")
End If

However, an if…else statement in PHP (and javascript for that matter) looks like:
if(foo==bar) {
echo "foo is equal to bar";
}
else {
echo "foo doesn't look like bar to me";
}

As you can probably see, rather than using the explicit “then” and “end” statements in PHP, you simply open and close things with curly brackets.

To make matters worse, all PHP statements have to end with a semi-colon. In javascript, the semi-colons are somewhat optional (if you only want javascript to do one thing inside of a function or statement, you don’t need the semi-colon. However, if you want javascript to perform more than one action in a series, you have to separate those actions with semi-colons). In VBScript, placing a semi-colon at the end of any line will throw an error, causing your script to stop.

Finally, a fundamental difference that’s also shown in the examples above is the use of comparison operators. In VBScript, as long as it’s contained within an “if” statement, the equal sign (=) is a comparison operator, meaning that VBScript will look at the statements on both sides of the symbol and decide if they are the same. However, in PHP and javascript, no matter what context you use it in, the single equal sign (=) is used strictly to assign values to items. In other words, the interpreter will look at the value on the right side of the equal sign and assign that as the value of the item on the left side of the equal sign. In order to compare two items in PHP and javascript, you need to use the double equal sign to determine if they are logically the same or the triple equal sign to determine if they are identical. In other words, the double equal sign will convert the two items that are being compared so that they are of the same type, then it will compare them. A triple equal sign will not convert anything.

So, the statement “0==false” is going to be a true statement because 0 is used universally as a numerical representative of the boolean value “false”. However, the statement “0===false” is not going to evaluate to true because the number 0 is not identical to the boolean value “false”.

So, when trying to switch constantly back and forth between PHP and VBScript, it can become somewhat tedious. Matters in this area have been worse over the last few weeks because I’ve been immersed in an intensive “PHP Certification” course for three hours each day, two days each week. During the rest of my time at work, however, I’ve had to deal with VBScript, being that it is the language currently available on our server.

I did, however, eventually work out what the problem in each of the applications was, and was able to get things working properly again.

In my next installment, I’ll tell you a little about the intensive programming I did last weekend and what I accomplished in doing so. Until then, thanks for reading.

One Response

  • ron hinkley

    Thank you for your well-written description of the some differences between php and vb script. I especially liked the comparison to french and spanish.