Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:31:51+00:00 2026-06-15T19:31:51+00:00

I have this code : ‘ Option Explicit Public Function Clean(Text) On Error Resume

  • 0

I have this code :

' Option Explicit
Public Function Clean(Text)
    On Error Resume Next
    ' Dim Chars As ?????????
    Chars = Array("\", "/", ":", "*", "?", """", "<", ">", "|")
    For Each Replaced In Chars
        Text = Replace(Text, Replaced, "")
    Next
    Clean = CStr(Text)
End Function

But i got an error when use Option Explicit because the Chars is not declared, but what type must i use to dim an array (Dim Chars As ???????)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:31:52+00:00Added an answer on June 15, 2026 at 7:31 pm

    Corrected version:

    Option Explicit
    
    Public Function Clean(ByVal Text As String)
        Dim Chars As Variant
        Dim Replaced As Variant
    
        Chars = Array("\", "/", ":", "*", "?", """", "<", ">", "|")
        For Each Replaced In Chars
            Text = Replace(Text, Replaced, "")
        Next
        Clean = Text
    End Function
    

    Generally better performing version:

    Option Explicit
    
    Public Function Clean(ByVal Text As String)
        Dim Chars As Variant
        Dim RepIndex As Long
    
        Chars = Array("\", "/", ":", "*", "?", """", "<", ">", "|")
        For RepIndex = 0 To UBound(Chars)
            Text = Replace$(Text, Chars(RepIndex), "")
        Next
        Clean = Text
    End Function
    

    Understanding Variants is important, and one should be especially conscious of using the Variant version of string functions instead of the String-typed versions suffixed with the “$” type decoration.

    Most of the time you’ll want to avoid Variants when you can because of performance costs.

    This version probably performs even better:

    Option Explicit
    
    Public Function Clean(ByVal Text As String)
        Const Chars As String = "\/:*?""<>|"
        Dim RepIndex As Long
    
        For RepIndex = 1 To Len(Chars)
            Text = Replace$(Text, Mid$(Chars, RepIndex, 1), "")
        Next
        Clean = Text
    End Function
    

    There is no “Char” type in VB6, nor is there any initialization syntax on variable declaration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: ie1.link(:text, /Exception:/) It is producing an error message which I
I have this code: public function getRecurringEventsByGrouped($grouped){ $query = SELECT * FROM `event` AS
I have this code class PagamentoController extends Zend_Controller_Action { public function init() { /*
I have this code: <div class = content-dir-item> <p>Text input</p> <img src=./images/email.png class =
I have this code in a single file : public class genIntro { public
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have this code: class A { public: A(int _a, int _b = 0)
I have this code: public void replay() { long previous = DateTime.Now.Ticks; for (int
I have this code snippet where we get a collection from COM Dll public
I have this code from an HTML form: <select name=history12> <option value=Gov/Econ>Government &amp; Economics</option>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.