By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,558 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,558 IT Pros & Developers. It's quick & easy.

Teaching/Trying to teach myself VBScript, what is a literal

P: 4
Books I'm reading say it is the opposite of a variable, and something that doesn't change. I get the wording, and but I don't get it from the examples being used. Any one have a good analogy for this. Please don't use too many technical terms if you can avoid it. I really am a scripting dummy. Any suggestions from people about how to pick it up on my own? Courses, books, advice.


Thank you!!!
Oct 30 '06 #1
Share this Question
Share on Google+
9 Replies


100+
P: 1,646
Books I'm reading say it is the opposite of a variable, and something that doesn't change. I get the wording, and but I don't get it from the examples being used. Any one have a good analogy for this. Please don't use too many technical terms if you can avoid it. I really am a scripting dummy. Any suggestions from people about how to pick it up on my own? Courses, books, advice.


Thank you!!!
A literal value means the value is 'literally' what it says

Debug.Print "Hello World" (gives you Hello World)


Debug.Print 12345 (give you 12345)

A variable is a place to store this information and the value stored in the variable can be changed at any time. That is why it is called a variable :)

MyString = "Hello World"

Debug.Print MyString (gives you Hello World)

MyString = "Goodbye World" (changing the value stored in MyString)

Debug.Print MyString (gives you Goodbye World)

MyString = "Hello World" (reassigning the same value as at the beginning)

Debug.Print MyString (Hello World is back again)
Oct 30 '06 #2

Expert 5K+
P: 8,434
A literal value means ...
It might help to simplify it even more. A literal is an actual value, like 3 or "Hello", which is specified in your code at "design time" (when you write the code).
Oct 30 '06 #3

P: 4
Ok, I have my deer in healights look going. I understand the discussion point that a literal is something that does not change. Part of what is throwing me off is that it appears to be called like a variable. So...is it the programmers choice to write something like

Dim somevariable
Somevariable = "John is a scripting dummy"

Now that I have declared what Somevariable is, as the developer do I just decide that this is a literal?

thanks again
Oct 30 '06 #4

Expert 5K+
P: 8,434
Somevariable = "John is a scripting dummy"
I don't know whether this will help. But in your example, somevariable is a variable. "John is a scripting dummy" is a literal. (In this case, a string literal.)


A literal value is one which you actually, literally, write there in your code - like this "John..." example. If you say to print "John" you are saying to literally print "John" - exactly (once again, literally) what you told it. If you say to print somevariable, it will print whatever value happens to be stored in that variable. A variable is just a name for a place where something is stored.

To take an example from simple algebra, in the expression x = 3 the x is a variable, while 3 is a literal value.
Oct 30 '06 #5

Expert 5K+
P: 8,434
Another point - don't get hung up on the "doesn't change" point - it will confuse you later. There are other things which can't/don't change. While it's true that a literal can't change during execution, but that doesn't define what it is.
Oct 30 '06 #6

P: 4
I think your advice is good, and I won't get hung up on it. Is there a good simple explanation for what the frick it is then?
Oct 30 '06 #7

100+
P: 1,646
I think your advice is good, and I won't get hung up on it. Is there a good simple explanation for what the frick it is then?
Understanding variables and literals is conceptually difficult for most people. Sadly, it is fundamental to writing code. :(

A variable is a bag or container to hold some value or other. I can give you a bag and you can put a piece of candy in it. Then we can go and play a game with the bag. Sometimes we can look inside just to check what the piece of candy is. Sometimes we can change it for a different piece or add lots more so there are several pieces. It is the candy bag with variable amounts of candy in it. We can send it on a journey through different processes that take out and put in different amounts of candy and at the end we can see what is in the bag.

If we just play with a single piece of candy then that is all we have and it never changes so we can't do any testing or processes with it. We need a bag so that we can 'vary' the type and amount of candy in it. Candy is literally candy. The bag holds variable amounts of candy so we can't call it literally candy. We call it a container holding a variable amount of candy or variable for short.

You are correct in that the programmer can decide what literal value to put in the bag or variable. In programming we need to allow for different values so that the code we write is not too limited to one calculation. If we write:

1 + 1 = 2

It is correct and not very useful.

Dim bag1, bag2, result
bag1 = 1
bag2 = 2

result = bag1 + bag2

Display result somewhere. The value stored in result is 3

Now we can take the values for bag1 and bag2 from text boxes on a form with user input so if they enter 3 in box 1 and 6 in box 2 we can take those values and stick them in the bags.

bag1 = box1
bag2 = box2

result = bag1 + bag2

box3 = result

so now the user will see the value 9 in box 3 and there are no literals in our code. :)
Oct 31 '06 #8

P: 4
Thank you for your time. I'm not a dummy, but the concepts are difficult right now. Guess the old adage "fake it till you make it" is going to hold true. Not sure I would recognize a literal if I saw one, but I'll just keep wading through it.
Oct 31 '06 #9

100+
P: 1,646
Thank you for your time. I'm not a dummy, but the concepts are difficult right now. Guess the old adage "fake it till you make it" is going to hold true. Not sure I would recognize a literal if I saw one, but I'll just keep wading through it.
Write a little bit of code, see what it does
Repeat the above again and again

Nothing works better. This is how I learned and continue to learn.
My philosophy is: If somebody else has already done it then I can do it.

Just wish that applied to the lottery :)
Oct 31 '06 #10

Post your reply

Sign in to post your reply or Sign up for a free account.