Using VBScript to create CSV files. A function to deal with values to make Excel happy

后端 未结 2 2037
臣服心动
臣服心动 2021-01-23 06:45

I would like opinions/suggestions for improvement etc on the following function. It will be wrapped around every value being passed into a CSV file on a classic ASP page. As is

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-23 07:14

    Few things:

    1. This section:

      If "" & txt = "" Then
          insertCSV = ""
      Else
      

      If you just want to return an empty string if txt is empty, you can just do this:

      If Len(txt) = 0 Then Exit Function
      
    2. You don't need to use End If for single-line If statements.

    3. This line:

      if isNumeric(tmp) AND left(tmp, 1) <> "0" then tmp = tmp end if
      

      You're assigning the value back to itself? What purpose does this serve?

    4. Don't you want to replace just the symbol © with ©? The way you have it written, you're replacing the entire text with © (same goes for your other tests). I would think you'd want to do this instead:

      If InStr(tmp, "©") Then tmp = Replace(tmp, "©", "©")
      

    Try making those changes and then post an updated version of your routine and let's see how it looks.

提交回复
热议问题