Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Syntax to extract individual characters from VBA string

Posted on 2008-10-30
3
Medium Priority
?
1,632 Views
Last Modified: 2012-05-05
Probably an easy question, but how do I reference the individual characters of a string?  For example in order to extract each character one after another I thought it would be something like this:

Dim MyString As String
Dim MyChar As String

MyString = "abcd"

For index = 0 to Len MyString
    MyChar = MyString[index]   'this syntax is incorrect
Next index


Thanks.
0
Comment
Question by:JohnSantaFe
  • 2
3 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 22842558
MyChar = Mid(MySTring, index, 1)
0
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 total points
ID: 22842562
For index = 1 to Len(MyString)
    MyChar = Mid(MyString, index, 1)   'this syntax is incorrect
Next index
0
 

Author Comment

by:JohnSantaFe
ID: 22843206
Thank you.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

963 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