Solved

VB6 For Loop

Posted on 2007-03-22
6
39,058 Views
Last Modified: 2008-02-01
I have a small routeen that removes all characters from a string but not any digit 0 thru 9. It works fine, but I was wondering if my For Next loop could be modified to be cleaner. Here is my code:

'*********************************************

For i = 0 To 47
MyString = Replace(MyString, Chr(i), "")
Next i

For i = 58 To 127
MyString = Replace(MyString, Chr(i), "")
Next i

'********************************************************
0
Comment
Question by:AmericaFan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 18773570
For i = 0 To 47
  MyString = Replace(MyString, Chr(i), "")
Next i

1. Do you really need to concern yourself with characters less than 32?

2. Is cleaner really your problem, or are you experiencing performance problems?  Your two loops look pretty clean.  You combine these two loops, but wouldn't gain any simplicity or cleanliness.

3. How long are your MyString strings?
0
 

Author Comment

by:AmericaFan
ID: 18773708
My main goal was to see if I could combine the two For Loops into one For Loop and get the same results. I only want 0-9 and any other character has to be removed. I'm validating and any key is possible. Maybe not 0 thru 31, but the rest is not wanted and is on a key board for mistakes. Thanks for you comment aikimark.
0
 
LVL 10

Accepted Solution

by:
Clif earned 50 total points
ID: 18773750
For i = 58 To 127
    MyString = Replace(MyString, Chr(i), "")
    If (i - 58) <= 47 Then
        MyString = Replace(MyString, Chr(i - 58), "")
    End If
Next i
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 10

Expert Comment

by:Clif
ID: 18773997
You can also use regular expressions, which is even more efficient.

You would have to add a reference to "Microsoft VBScript Regular Expressions 5.5" in your project (it's been available since IE 5.5)

0
 

Author Comment

by:AmericaFan
ID: 18774165
Thats what I'm talkin about :) Thanks Clif!
0
 
LVL 10

Expert Comment

by:Clif
ID: 18774253
NP
Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question