Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Help using strings


Message #1 by "Christopher Cote" <chrscote@9...> on Wed, 23 Oct 2002 02:11:07
I am having problems trying to use the mid command to get a substring of a 
value.  I have saved a string into var1 and am trying to take 2 substrings 
from it.  I check if it has a period (.) in it, and if it does, I want to 
save the value to the left of the period in one variable and whatever is 
to the right of the period in another variable.  Here is what I've done:

var1 = "1.45"    //Not really a constant.  Just used for discussion

PlacePeriod = Instr(var1, ".")
TotalNum = mid(var1, 0, PlacePeriod-1)
PartNum = mid(var1, PlacePeriod+1, var1.length)

Whenever I try to perform these lines, I receive the following error:

      Invalid procedure call or argument: 'mid' 

Can anyone tell me what I'm doing wrong or another way to do what I need?

Thanks in advance,
Chris
Message #2 by Mark Eckeard <meckeard2000@y...> on Tue, 22 Oct 2002 18:36:36 -0700 (PDT)
Try this:

PlacePeriod = Instr(var1, ".")
TotalNum = mid(var1, 0, PlacePeriod-1)
PartNum = mid(var1, PlacePeriod+1, len(var1))


--- Christopher Cote <chrscote@9...> wrote:
> I am having problems trying to use the mid command
> to get a substring of a 
> value.  I have saved a string into var1 and am
> trying to take 2 substrings 
> from it.  I check if it has a period (.) in it, and
> if it does, I want to 
> save the value to the left of the period in one
> variable and whatever is 
> to the right of the period in another variable. 
> Here is what I've done:
> 
> var1 = "1.45"    //Not really a constant.  Just used
> for discussion
> 
> PlacePeriod = Instr(var1, ".")
> TotalNum = mid(var1, 0, PlacePeriod-1)
> PartNum = mid(var1, PlacePeriod+1, var1.length)
> 
> Whenever I try to perform these lines, I receive the
> following error:
> 
>       Invalid procedure call or argument: 'mid' 
> 
> Can anyone tell me what I'm doing wrong or another
> way to do what I need?
> 
> Thanks in advance,
> Chris
> 
> ---
> 
> Improve your web design skills with these new books
> from Glasshaus.
> 
> Usable Web Menus
>
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
> r-20
> Constructing Accessible Web Sites
>
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> r-20
> Practical JavaScript for the Usable Web
>
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> r-20


__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/
Message #3 by "Christopher Cote" <chrscote@9...> on Thu, 24 Oct 2002 01:41:06
Hi Mark,
   I tried this but I am still having an error occurring.  The problem 
actually occurs on the first mid() line.  It says that 'mid' is an invalid 
procedure call or argument.  I understand the problem with the length that 
I had, but I do not understand why the script will not allow mid.  Does 
anyone know how to solve this problem?

Chris Cote

> Try this:

PlacePeriod = Instr(var1, ".")
TotalNum = mid(var1, 0, PlacePeriod-1)
PartNum = mid(var1, PlacePeriod+1, len(var1))

Message #4 by "Ken Schaefer" <ken@a...> on Thu, 24 Oct 2002 13:28:40 +1000
Are you using JScript?
(I notice that your first line uses JScript comments:
var1 = "1.45"    //Not really a constant.  Just used for discussion
)

If so, then Mid() is not a valid method. Mid() is VBScript. JScript using
SubStr():
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/ht
ml/js56jslrfJScriptMethodsTOC.asp?frame=true

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Christopher Cote" <chrscote@9...>
Subject: [asp_web_howto] Re: Help using strings


: Hi Mark,
:    I tried this but I am still having an error occurring.  The problem
: actually occurs on the first mid() line.  It says that 'mid' is an invalid
: procedure call or argument.  I understand the problem with the length that
: I had, but I do not understand why the script will not allow mid.  Does
: anyone know how to solve this problem?
:
: Chris Cote
:
: > Try this:
:
: PlacePeriod = Instr(var1, ".")
: TotalNum = mid(var1, 0, PlacePeriod-1)
: PartNum = mid(var1, PlacePeriod+1, len(var1))
:
:
: ---
:
: Improve your web design skills with these new books from Glasshaus.
:
: Usable Web Menus
: http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
: r-20
: Constructing Accessible Web Sites
: http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
: r-20
: Practical JavaScript for the Usable Web
: http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
: r-20

Message #5 by "cindy zhou" <czhou@w...> on Thu, 24 Oct 2002 19:43:19
Chris:

Your problem is that for mid() function, the first index of the string is 
1, instead of 0. 

So change to 

TotalNum = mid(var1, 1, PlacePeriod-1)

It will work.

Cindy

  Return to Index