Results 1 to 9 of 9

Thread: Urgent - SOS - working with variables

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    Hampton Beach
    Posts
    513

    Question 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

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    does vbscript support replace?

    if so
    Code:
    snums = Replace(sNums, ",,",",")
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    Hampton Beach
    Posts
    513
    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")

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    i showed you the code to use.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    Hampton Beach
    Posts
    513
    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, ",,",",")

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    yes you are replacing the double comma and space with a single comma.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    Hampton Beach
    Posts
    513
    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, ",,",",")

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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)
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    Hampton Beach
    Posts
    513
    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
  •  



Click Here to Expand Forum to Full Width