Link to home
Start Free TrialLog in
Avatar of flosoft
flosoft

asked on

Another easy?? String Question

Problem... I want to take text from a textbox out 1 letter at a time...say to put into a list box, but I cannot find anything once again on how to do this...Is there a keyword for any character including spaces in vb?? Something like this would be fine...

Dim myString
Dim i
'X = Any and all characters in the string
myString = "XXXXXXXXXXXXXXXXXXXXX"
myString = Split(myString, "X", -1)
'Then I could add them to a listbox like:

For i = 0 To UBound(myString) - 1
List1.AddItem myString(i)
Next

This should populate the list box with single letters numbers and spaces.

The actual app will output to a Pole display, but adding to a list box is about the exact same thing.

Thanks
Avatar of vinnyd79
vinnyd79

you could do something like this:

Private Sub Command1_Click()
Dim myString As String, mystring1 As String
Dim myString2 As String
Dim i As Integer
List1.Clear
'X = Any and all characters in the string
myString = "XXXXXXXXXXXXXXXXXXXXX"
Do Until Len(myString) = 0
mystring1 = Left$(myString, 1)
myString2 = Mid$(myString, 2)
List1.AddItem mystring1
myString = myString2
Loop

End Sub
ASKER CERTIFIED SOLUTION
Avatar of vinnyd79
vinnyd79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi flosoft,

  Dim MyString As String
  MyString = "Test"
  Dim i As Integer
  For i = 1 To Len(MyString)
    MsgBox Mid(MyString, i, 1)
  Next i

hope this helps
guess i should have read it more closely.

Dim MyString As String
MyString = "Test"
Dim i As Integer
For i = 1 To Len(MyString)
  List1.AddItem Mid(MyString, i, 1)
Next i
Avatar of flosoft

ASKER

Hey Vinny,
Thanks, worked perfect...I am pretty new to working with strings and am constantly running into issues lately with them... I also appreciate all others that answered my question!

Thanks!
what about this


Dim i as long

mySting = "XXXXXXXXXXXX"

for i = 1 to Len(myString)
    List1.AddItem Mid(myString, i, 1)
Next i

Good LUck!
DeAn, I did not copy your code. I had this page open for a while and then submitted, by the time it went through I saw your code.
no worries supunr ;)