PDA

View Full Version : Handling strings.



Lalaji
02-03-2008, 03:37 PM
So this is what I am try to do :
With a textbox user enters a string.
there is a label array which then shows up according to the length of the string (if string = "hello" = 5 characters = 5 labels are visible)
and I only want 1 letter to show up in 1 label. So in the 5 labels visible, it should be ::
Label1.Caption = "h"
Label2.Caption = "e"
Label3.Caption = "l"
Label4.Caption = "l"
Label5.Caption = "o"

Whats the best way/function to do this?

Thank you.

R0b0t1
02-03-2008, 05:39 PM
A string is an array of characters...


string[I] = character

Lalaji
02-03-2008, 05:59 PM
I get an error for that?


For X = 0 To Len(MainPuzzle)
If Not MainPuzzle(X) = " " Then
LPuzz1(X).Visible = True
End If
Next

MainPuzz = String
LPuzz1 = Label Arrar

Is that what you ment?

eurostylz
02-03-2008, 06:08 PM
i believe theres a function label1.text=Mystring(1)
im pretty sure thats how transfer it to label for the rest just make a for loop, i havent done vb in a year so im a bit rusty

Monster Hack
02-03-2008, 08:27 PM
Public Sub ToCharArray(ByVal s As String)
Dim i As Integer
ReDim <ARRAY_FOR_LETTERS>(Len(s))
For i = 1 To Len(s)
<ARRAY_FOR_LETTERS>(i) = Mid(s, i, 1)
Next i
End Sub

I hope it works for you. Use a public string array to replace <ARRAY_FOR_LETTERS> obviously.

-Mh