|
-
Aug 13th, 2002, 09:19 AM
#1
Thread Starter
Fanatic Member
Urgent - SOS - working with variables
I have 40 variables:
Var1 = request.form("hid1")
Var2 = request.form("hid2")
Var3 = request.form("hid3")
Var4 = request.form("hid4")
Var5 = request.form("hid5")
Var6 = request.form("hid6")
Var7 = request.form("hid7")
Var8 = request.form("hid8")
etc... up to Var40
I am placing the values of the Variables into one Variable:
sSums = Var1 & "," & Var2 ......
The only problem is that there will be times when some of the variables will not have a value....
Ex:
Var1 = John
Var2 = ""
Var3 = Larry
Var4 = Bob
Var5 = ""
As you can see Var2 and Var5 are empty.....
I want to remove the empty variables from the ONE variable so it looks like this:
sNums = "John, Larry, Bob"
Rather than
sNums = "John, ,Larry, Bob, "
This is an urgent request
-
Aug 13th, 2002, 09:27 AM
#2
does vbscript support replace?
if so
Code:
snums = Replace(sNums, ",,",",")
-
Aug 13th, 2002, 09:34 AM
#3
Thread Starter
Fanatic Member
Yes Replace can be used in vbscript but what do we replace the " " with?
Here is the syntax for the REPLACE within vbscript:
Replace(expression, find, replaceWith[, start[, count[, compare]]])
Example:
'Replace John with Larry
strSaying = Replace(strSaying, "John", "Larry")
-
Aug 13th, 2002, 09:38 AM
#4
i showed you the code to use.
-
Aug 13th, 2002, 09:43 AM
#5
Thread Starter
Fanatic Member
Cander,
Lets work with my example:
sNums = Var1 & "," & Var2 & "," & Var3 & "," & Var4 & "," & Var5
Lets say that Var3 and Var5 are empty then the output will be:
"John, Larry, , Bob, "
I want it to output as :
"John, Larry, Bob"
So you suggest using this as the line of code?
snums = Replace(sNums, ",,",",")
-
Aug 13th, 2002, 09:45 AM
#6
yes you are replacing the double comma and space with a single comma.
-
Aug 13th, 2002, 09:47 AM
#7
Thread Starter
Fanatic Member
Will this also replace the , space at the end of the string? Take a look after Bob there is a , space and then closing "
Code
Lets say that Var3 and Var5 are empty then the output will be:
"John, Larry, , Bob, "
I want it to output as :
"John, Larry, Bob"
So you suggest using this as the line of code?
snums = Replace(sNums, ",,",",")
-
Aug 13th, 2002, 09:52 AM
#8
use the replace..then you can check for , at the end
'remove trailing space and remove double commas
snum = trim(replace(snum,", ,",","))
If right(snum, len(snum)) = "," then snum = left(snum, len(snum) - 1)
-
Aug 13th, 2002, 10:08 AM
#9
Thread Starter
Fanatic Member
I will give this a try thank you..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|