AcidGoat 03-01-2003, 08:11 PM Ok I found some threads that sort of touched on this, but none that really gave a straight answer. I have a string of characters and I want each of those characters to be a seperate variable. For example, say I have a string that says "Bob". I want one variable for "B", one for "o" and one for "b" So that I can deal with each seperately.
Thanks in advance ;)
--AcidGoat
Kaluriel 03-01-2003, 08:17 PM Ostr is the old string
Nstr is the new string
ReDim Nstr(Len(Ostr))
For i = 1 To Len(Ostr)
Nstr(i) = Mid(Ostr, i, 1)
Next i
Squirm 03-01-2003, 08:21 PM Or..
Dim b() As Byte
b = StrConv(OStr, vbFromUnicode)
Kaluriel 03-01-2003, 08:23 PM **** you, your always one step ahead lol :)
AcidGoat 03-01-2003, 08:29 PM Hmm... maybe I should have mentioned this: the string will always be 12 characters long. I need each character to be its own variable, appropriately named. The first character will be a variable called "char1" the second "char2" etc... Example: say the string is "goatgoatgoat" (excuse the lack of creativity :)). I want this to result: char1 = g, char2 = o, char3 = a, char4 = t, char5 = g, char6 = o, char7 = a, char8 = t, char9 = g, char10 = o, char11 = a, char12 = t.
Is this even possible?
Machaira 03-01-2003, 08:41 PM Sure, but it'll be ugly.
Dim char1 As String
Dim char2 As String
Dim char3 As String
Dim char4 As String
Dim char5 As String
Dim char6 As String
Dim char7 As String
Dim char8 As String
Dim char9 As String
Dim char10 As String
Dim char11 As String
Dim char12 As String
Dim sString As String
Dim iLp As Integer
sString = "goatgoatgoat"
Dim sChar As String
For iLp = 0 To 11
sChar = Mid$(sString, iLp, 1)
Select Case iLp
Case 0
char1 = sChar
Case 1
char2 = sChar
Case 2
char3 = sChar
Case 3
char4 = sChar
Case 4
char5 = sChar
Case 5
char6 = sChar
Case 6
char7 = sChar
Case 7
char8 = sChar
Case 8
char9 = sChar
Case 9
char10 = sChar
Case 10
char11 = sChar
Case 11
char12 = sChar
End Select
Next iLp
AcidGoat 03-01-2003, 08:50 PM Hmmm... I tried that code and got this: Run-time error '5': Invalid procedure call or argument. Upon hitting debug, this line was highlighted: sChar = Mid$(sString, iLp, 1)
Maybe there's somethign I'm missing, but I've never seen code like this before (I haven't been using VB for very long, sorry).
AcidGoat 03-01-2003, 09:16 PM After a bit of tinkering and investigating I was able to get it to work. This is what I used:
sString = "goatgoatgoat"
char1 = Mid$(sString, 1, 1)
char2 = Mid$(sString, 2, 1)
char3 = Mid$(sString, 3, 1)
char4 = Mid$(sString, 4, 1)
char5 = Mid$(sString, 5, 1)
char6 = Mid$(sString, 6, 1)
char7 = Mid$(sString, 7, 1)
char8 = Mid$(sString, 8, 1)
char9 = Mid$(sString, 9, 1)
char10 = Mid$(sString, 10, 1)
char11 = Mid$(sString, 11, 1)
char12 = Mid$(sString, 12, 1)
Kaluriel 03-01-2003, 09:16 PM iLp could be 1 to 12. You can't start a character number 0
diamond_panther 03-01-2003, 11:30 PM why do u want each letter to have its own variable?
isn't this EXACTLY what an array is for?
|