Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 21st, 2008, 07:31 AM
Registered User
 
Join Date: Aug 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Illegal Assignment

I'm trying to concatenate a string in a for loop, which sounds quite simple in principle, but I'm getting the following error:

Microsoft VBScript runtime error '800a01f5'
Illegal assignment: 'I'

This is the code that I'm running:

tmpString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ1234567890"
numSaltChars = 10
sSalt = ""
i = 0
for i = 1 to numSaltChars
    Randomize
    pos = Round(Rnd * Len(tmpString)) + 1
    sSalt = sSalt & tmpString.substring(pos,1)
next

I can't see what's wrong with the code. Any help would be appreciated.

 
Old August 21st, 2008, 01:18 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

VBScript does *NOT* support METHODS on strings.

    tmpString.substring(pos,1)

You are trying to use a substring method, but that's only available in JavaScript and in the .NET languages (and Java, I guess).

Strings are *NOT* objects in VBScript. They are primitive types. So you have to use built in functions.

**********

Various other goofs in your code:

You call RANDOMIZE each time through the loop. That will actually *DESTROY* any attempts to get good random numbers. RANDOMIZE should be called once *PER PAGE* only.

You are using ROUND where you should use INT. ROUND *could* give you a number that is one greater than the length of your string, so you would get an "out of bounds" error!

Finally, you set i=0 for no reason at all, since the very next line will throw away that value.

********************

SO:

Code:
CONST numSaltChars = 10
Randomize ' remember, once PER PAGE!

tmpString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
sLen = Len(tmpString)
sSalt = ""

for i = 1 to numSaltChars
    sSalt = sSalt & Mid( tmpString, 1 + INT(sLen * RND()), 1 )
next
 
Old August 22nd, 2008, 06:21 AM
Registered User
 
Join Date: Aug 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great, thanks for the help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR: Illegal characters in path owen_xgy .NET Framework 2.0 8 April 2nd, 2008 10:21 AM
Illegal operation on empty result set. amisrivas JSP Basics 2 February 19th, 2008 11:49 PM
Illegal assignment: 'adCmdText' jackiew ASP.NET 1.0 and 1.1 Basics 1 August 23rd, 2007 09:29 AM
Illegal key size rnmisrahi BOOK: Beginning Cryptography with Java 3 January 8th, 2007 09:06 PM
ParseException:Illegal character inAxis Webservice manaspanda J2EE 1 February 23rd, 2004 11:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.