problem with mid function

# Thread: problem with mid function

1. Senior Member
Join Date
Dec 1969
Posts
336

## problem with mid function

Has anyone ever run into this error before when using the Mid function and if so, what caused it?<BR><BR>Invalid procedure call or argument: &#039;mid&#039;

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: problem with mid function

You either have malformed syntax or are trying to do a mid on a NULL value.

3. Senior Member
Join Date
Dec 1969
Posts
216

## RE: problem with mid function

Are you sure your in vbscript tags?<BR>Here is an example<BR>&#060;%<BR>Dim rs, rsemail, rsship, cn, poanum, sql, nowd, nowt, urlstr01, sendmail<BR>nowd = Date<BR>nowt = CStr(FormatDateTime(Time,4))<BR>ltime = Mid(nowt, 1, InStr(1, nowt, ":") - 1)<BR>rtime = Mid(nowt, InStr(1, nowt, ":") + 1,2)<BR>ntime = Trim(ltime & rtime)<BR>%&#062;

4. Senior Member
Join Date
Dec 1969
Posts
336

## thanks both of you

But neither suggestion seemed to help. Any other ideas?

5. Senior Member
Join Date
Dec 1969
Posts
336

## here's the code

Basically what I&#039;m trying to do is write a function that determines how many of an item the person has put in their cart. It first figures out if the total number they have is evenly divisible by a value stored in the database called discountnumber. If it is, then it&#039;s supposed to take their total, divide it by that discountnumber and multiply the result against the shipping charge.<BR><BR>If it&#039;s not evenly divisible, then the person gets charged the shipping charge (for each 50) and then .95 for each item over that. So, basically if the person ordered 101 of the same items, it should charge them 32.95 in shipping. I hope I explained that well enough. Thanks.<BR><BR>&#060;%<BR>quantity = 100<BR>discountnumber = 50<BR>shipping = 16<BR><BR>if quantity &#062;= discountnumber then<BR> <BR> boolMod = quantity mod discountnumber<BR> if boolMod then<BR> quant2 = quantity/discountnumber<BR> pricePerQuant2 = quant2 * shipping<BR> DiscountTotal = DiscountTotal + pricePerQuant2<BR> else<BR> quant2 = quantity/discountnumber<BR> quant2 = cstr(quant2)<BR> deci = inStr(quant2,".")<BR> numbFirstHalf = mid(quant2,1,deci-1)<BR> numbLastHalf = mid(quant2,deci)<BR> pricePer50 = numbFirstHalf * shipping<BR> pricePerOne = (numbLastHalf * discountnumber) * .95<BR> pricePerQuant2 = pricePer50 + pricePerOne<BR> DiscountTotal = DiscountTotal + pricePerQuant2<BR> end if<BR>end if<BR>%&#062;

6. Nils Bilhorn Guest

## RE: here's the code

Just a thought. What if quant2 does not contain a dot and you call mid with a length of -1 ?

7. Senior Member
Join Date
Dec 1969
Posts
336

## ah.....I got it

I was mistaken in my understanding of the mod function. I was under the impression that it returned a boolean value. Therefore in my if statement, I said:<BR><BR>if boolMod then<BR><BR>What I should have done is:<BR><BR>if boolMod = 0 then<BR><BR>That took care of it. Thanks guys!!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•