[BNM] 2 questions of ASP/VB
Hugh Sweeney
hsweeney at pobox.com
Mon Apr 10 20:59:23 BST 2006
Dave Child wrote:
>> 1. Does VB support variable variables, ie using the value of a variable
>> as a variable name?
>
>Yes, using Eval.
>
>firstvar = "fish"
>secondvar = "wife"
>var = Eval(firstvar & secondvar) 'var = fishwife
>
>I think that's right, though it's been a while and my ASP's a bit rusty.
Not quite.
It evaluates the value of the (undeclared) variable named fishwife,
ie a null string. (Same as coding "var = fishwife"). I read the OP as
wanting to assign the VALUE of firstvar or secondvar to var. This snipped
of VB illustrates the difference:
var1 = "fish": var2 = "wife"
Randomize
varvar = "var" & round(rnd()+1)
MsgBox eval(varvar) 'varvar = fish OR wife
>
>> 2. With a ASP/VB to Access via ADO connection setup, is it possible to
>> get the server to auto-truncate the input value of a field - so that if
>> a field is set up as say text / 50 characters long, and the input is
>> longer, it just truncates to 50 chars rather than throw an error? Or do
>> I have to truncate separately before writing to the database?
>
>You can catch errors and hide them, or truncate data. Don't think you can
>do what you want and just add the first 50 chars without truncating before
>inserting.
Glenn Williams wrote:
>Not quite sure I understand your second one but there are many commands to
>truncate strings in many wonderful ways.
I'd certainly recommend this approach, such as:
If len(mytext) > 50 then mytext = left(mytext,50) End If
on grounds of Good Practice. If you don't clean up your data before you
throw at a database you're asking for trouble, particularly if someone in
the future changes the database. Sure, cleaning it up will burn a few extra
CPU megacycles but that'll probably come cheaper than debugging intermittent
failures due to occasional over-length data.
hth
Hugh
--
More information about the BNMList mailing list
BNMList is hosted by Screenlists, a Screen-Play.net service