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

when to quote variable values?

P: n/a
Is there a rule of thumb for quoting variable values? For example, do I
have to put all string number values in quotes?

strAbc = "3" ?

What about long, int and byte? I assume these are NOT supposed to be quoted

lngID = 4

How about values I get from an unbound textbox?

Me!txtFs = 5 --or-- Me!txtFs = "5"

and what about when using Select Case?

Select Case Me!tabMain
Case 0
Case 1
End Select

--or--

Select Case Me!tabMain
Case "0"
Case "1"
End Select

??
Nov 12 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
This is an important question. You must get the data type correct for Access
to understand your query/code correctly.

For fields, do not use any delimiter for the Number or Currency type fields,
e.g.:
WHERE MyNumber = 9999

Use quote marks as delimiters around text values, e.g.:
WHERE MyText = "xxxx" OR MyText = "9999"

Use # as the delimiter around date values, e.g.
WHERE InvoiceDate = #1/4/2004#

In code, use the corrrect data type. The Value of a tab control is always an
integer, so you would use:
If Me.tabClt0 = 0 Then

You can find the data type by asking Access to give you the typename:
? TypeName(Forms!Form1!TabClt0.Value)

Access type-casts automatically, so it often changes the types to whatever
you need without telling you. In my view, this makes it harder to learn and
understand what is going on, and frequently results in code and queries that
do not work as intended. More info and exmamples:
http://allenbrowne.com/ser-45.html

Regarding your specific question about Select Case with a tab control, this
is probably best as it still works even if you reorder the pages of the tab
control, and it generates a suitable error if you remove or rename pages:
Select Case Me.TabClt0
Case Me.Page1.PageIndex
Case Me.Pagexxx.PageIndex


--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"deko" <dj****@hotmail.com> wrote in message
news:EJ**************@newssvr29.news.prodigy.com.. .
Is there a rule of thumb for quoting variable values? For example, do I
have to put all string number values in quotes?

strAbc = "3" ?

What about long, int and byte? I assume these are NOT supposed to be quoted
lngID = 4

How about values I get from an unbound textbox?

Me!txtFs = 5 --or-- Me!txtFs = "5"

and what about when using Select Case?

Select Case Me!tabMain
Case 0
Case 1
End Select

--or--

Select Case Me!tabMain
Case "0"
Case "1"
End Select

??

Nov 12 '05 #2

P: n/a
The only time you need to use quotes is when the variables needs a string
value.

In the case of un-bound textbox, you should still follow some convention.

If the values in the un-bound text box are fact strings,a nd NOT just
numbers, then in your code, you should use quotes. The reason is that the
text box will take on whatever data type you assign to it. So, if your code
expects strings, then use quotes.

Further, when reading code.

me!SomeTextBox = "12"

or

me!SomeTextBox = 12

Both of the above will work, but as a developer reading the above code, it
is clear that the first example assumes that the text box can have all kinds
of characters, since it would be silly for the developer to use quotes when
you need a number. And, of course, the reverse is true for the 2nd value.
So, YOU get to decide if you need quotes in the above. If that control is
only supposed to have numbers, then you should not use strings, and should
not use quotes, but just use a number.

What about long, int and byte? I assume these are NOT supposed to be quoted
lngID = 4
The above sounds correct to me.

How about values I get from an unbound textbox?

Me!txtFs = 5 --or-- Me!txtFs = "5"
Well, in the above, you not getting values...but in fact putting in values!
However, ignoring the above minor context mistake, the notes I mention above
still apply.
and what about when using Select Case?

Select Case Me!tabMain
Case 0
Case 1
End Select


Well, it depends on what type of values the tabMain expects. If you are
storing string values into tabMain, the you would use quotes. If you are
storing numbers, then you would NOT use quotes.

So, the answer will depend on what you as the designer needs to store in
that field. In the above example it does look like tabMain is a number value
from a tab control, and thus you of course would use numbers.
--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
No************@msn.com
http://www.attcanada.net/~kallal.msn

Nov 12 '05 #3

P: n/a
hi,
i recall quite awhile back you were asking for games created with access,
if you are still curious i have a dinky horse racing game, its ok but the
odds are entirely bogus. if you want i a can upload it to a page and give
you the link - A97, but it runs fine on AXP, havent tried it on A2K.
later,
dingus
Nov 12 '05 #4

P: n/a
"deko" <dj****@hotmail.com> wrote in message news:<EJ**************@newssvr29.news.prodigy.com> ...
Is there a rule of thumb for quoting variable values? For example, do I
have to put all string number values in quotes?


Real simple. If it's a string value that you're assigning to a
variable, then use quotes.

Dim strWhatever As String
strWhatever = "Something"

Dim dtDate as Date
dtDate = #5/1/2004#

If the field is formatted for the variable type you're using then you
can use

strWhatever = Me!txtWhatever

Numbers - no quotes.
Nov 12 '05 #5

P: n/a
"deko" <dj****@hotmail.com> wrote in message news:<EJ**************@newssvr29.news.prodigy.com> ...
Is there a rule of thumb for quoting variable values? For example, do I
have to put all string number values in quotes?


Real simple. If it's a string value that you're assigning to a
variable, then use quotes.

Dim strWhatever As String
strWhatever = "Something"

Dim dtDate as Date
dtDate = #5/1/2004#

If the field is formatted for the variable type you're using then you
can use

strWhatever = Me!txtWhatever
Nov 12 '05 #6

P: n/a
dingusmcgee <di**********@yahoo.com> wrote:
i recall quite awhile back you were asking for games created with access,
if you are still curious i have a dinky horse racing game, its ok but the
odds are entirely bogus. if you want i a can upload it to a page and give
you the link - A97, but it runs fine on AXP, havent tried it on A2K.


Someone else I know created Frogger game, with jumping frog and moving vehicles, and
the Tower of Hanoi puzzle.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Nov 12 '05 #7

P: n/a
In fact, every year around the Christmas holidays, I being to think my of
quest to create a VERY nice looking game of pong for ms-access. (and
multi-user to boot!). Breakout would also be good.

This year, I had way too much fun during the holidays, and did not do my
usual huge eat pizza and drink gallons of pop to write some cool code thing.
I used to love doing that during the holiday season, and this year that did
not happen!

Gee, I hope I am not getting old!

So, as it stands, thank you kindly, but nope...not looking for games just
yet, and ones that I do look for should be faithful reproductions of
classics (pong, packMan etc).
--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
No************@msn.com
http://www.attcanada.net/~kallal.msn
Nov 12 '05 #8

P: n/a
One of my favourite gifts this year was the Atari Classic 10 games. All
of the games are embedded in a slightly oversized joystick with video
and audio outputs directly to your TV. THis is the original code. My
daughter likes Pong but my favourite is Missile COmmand. I cannot
believe that I still remember the sournds and screen colors for each
level so well from 20 years ago!
:-)
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Albert D. Kallal" <pl********************@msn.com> wrote in message
news:VA0Lb.18265$X%5.8213@pd7tw2no...
In fact, every year around the Christmas holidays, I being to think my of quest to create a VERY nice looking game of pong for ms-access. (and
multi-user to boot!). Breakout would also be good.

This year, I had way too much fun during the holidays, and did not do my usual huge eat pizza and drink gallons of pop to write some cool code thing. I used to love doing that during the holiday season, and this year that did not happen!

Gee, I hope I am not getting old!

So, as it stands, thank you kindly, but nope...not looking for games just yet, and ones that I do look for should be faithful reproductions of
classics (pong, packMan etc).
--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
No************@msn.com
http://www.attcanada.net/~kallal.msn


Nov 12 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.