Secondly Again, I don't know why you have to dimension those elements and not simply use the names of the elements themselves along the way,
It's a very good question. The short answer is: you don't have to. You could just use the names, just by removing the line Option Explicit at the top. Then you could get rid of all the Dim statements. Why bother requiring Dim statements? Another short answer: to help us find small mistakes, in mispelling a variable name, or using an old variable name somewhere when we've changed it everywhere else to a new name, or similar things. These mistakes are easy to make, and if there is no error message, extremely difficult to find. This is especially important in VBScript, because if you use the looser approach (without Option Explicit), VBScript lets you you any name anywhere, misspelled, misused, anything. Very often this sort of coding error will silently produce results that are wrong. Everything seems fine, until it isn't, and then you notice that half your data is missing, or has moved 5 metres, or been sent to the client with attributes missing, whatever. It's a downside of VBScript (and to a slightly lesser extent, JScript and JavaScript) that it lets you do almost anything with very few checks. A similar issue in both languages is that variables are not strongly typed--usually not typed at all, everything is just a "var", a variable, which can refer to a number one minute, a string the next, and so on, anything. That is very flexible and simple, but there's the same downside as with unchecked variable names: it is very easy to make a subtle coding error that raises no alarm bells, but only later turns out to be critical (and then is extremely hard to find). These considerations are important for choosing a language. It's a balance of safety and convenience, and partly a matter of taste. For example, I dislike C# because I find there is so much text devoted to safety that I can hardly see what I'm doing (which isn't actually very safe, either). If you want to learn scripting in just one scripting language, for the long term, you could also consider Python (for Manifold that means IronPython). You don't have to use cruft to be safe. There are other mechanisms to keep you from shooting yourself in the foot that work really well in practice, without getting in the way of coding. Python is even simpler than VBScript (especially if you need to do something complex!). But there's nothing wrong with sticking with VBScript, if that works for you, or moving to Visual Basic .NET later.
|