Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple question about Data Types 1

Status
Not open for further replies.

teach314

Technical User
Jul 29, 2011
183
CA
hi to all

Let's say I'm using values... strCat = "A", lngPartFrom = 1200, lngPartTo = 1350 to generate a Table name in code...

strTblOutput = "tbl__Category_" & strCat & "__Part_" & lngPartFrom & "_to_Part_" & lngPartTo & "__OK".

My question is this: Would the expression above always work (it seems to), or should I be wrapping the long variables in CStr()?

Thanks
Teach314
 
If I understand correctly, there is no reason to use cstr(). I can only resolve to a string.

The & Operator (Visual Basic) is defined only for String operands, and it always widens its operands to String, regardless of the setting of Option Strict. The & operator is recommended for string concatenation because it is defined exclusively for strings and reduces your chances of generating an unintended conversion
 
Technically, your two Long variables really ought to be String variables as well.

There is a logical possibility that your PartFrom & PartThru values could have [highlight #FCE94F]leading zeros[/highlight] which would not be possible directly using any numeric variable.
 
MajP - interesting quote. That seems to settle it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top