Hi all,
How can I convert Which from "Lyla" To Lyla Without the " "Code:Lyla = "Good morning Guys/Gals"
Guys = "Good morning Lyla"
Which = Right(Guys, 4) ' ==> "Lyla"
MsgBox which
Thanx.
Printable View
Hi all,
How can I convert Which from "Lyla" To Lyla Without the " "Code:Lyla = "Good morning Guys/Gals"
Guys = "Good morning Lyla"
Which = Right(Guys, 4) ' ==> "Lyla"
MsgBox which
Thanx.
You mean get rid of the extra spaces? Use the Trim$ function.
Code:MyString = Trim$(which)
Sorry Megatron.
I meant How can I convert Which from "Lyla" To Lyla Without the "" Quotes So I can Call the Lyla Var.
Thanx.
Code:Public Function replacestring(strstring As String, strwhat As String, strwith As String) As String
Dim lngpos As Long
Do While InStr(1&, strstring$, strwhat$)
DoEvents
Let lngpos& = InStr(1&, strstring$, strwhat$)
Let strstring$ = Left$(strstring$, (lngpos& - 1&)) & Right$(strstring$, Len(strstring$) - (lngpos& + Len(strwhat$) - 1&))
Loop
Let replacestring$ = strstring$
End Function
Public Function trimchar(strtext As String, strchar As String) As String
trimchar$ = replacestring(strtext$, strchar$, "")
End Function
Lyla2 = trimchar("" & Which & "", "" & Chr$(34) & "")
Thanx Megatron & Matthew Gates.
So that is what you wanted? To remove the quotes?
Yes.
So when I call:
Msgbox which
It would show Good morning Guys/Gals
Thanx again.
Matthew Gates
It didn't work !
I don't understand..works for me.
You say you are trying to Trim(Remove) quotes. Here is an example.
Is that what you wanted? Or did I misunderstand you?Code:Quotes = """Lyla"""
Msgbox "Before: " & Quotes
Lyla2 = trimchar("" & Quotes & "", "" & Chr$(34) & "")
Msgbox "After: " & Lyla2
Dear Matthew Gates,
Run this code in a Form_load:
I want to use the returned value of which WithoutCode:Lyla = "Good morning Guys/Gals"
Guys = "Good morning Lyla"
Which = Right(Guys, 4)
'Toggle a breakpoint in your code
'and chech the value of which ???
MsgBox which ' ==> "Lyla" with Quotes
Quotes ??
Sorry for not being very clear .
Thanx again.
Wow! 70 people !?
Please help? :confused:
I hope this simple example would clear things up ;)
I'm very sorry for being such a pain :)Code:Dim Lyla As String
Dim Guys As String
Dim which As String
Lyla = "Good morning Guys/Gals"
Guys = "Good morning Lyla"
which = Right(Guys, 4) ' ==> "Lyla"
Open file2 For Binary As fnum
Put #fnum, , which
Close fnum
Sorry, but without an explanation of what you are trying to do, I can't help.
Lyla,
maybe a collection of strings comes close to what you are trying to do, although i don't understand why:
'**********************************************************
Private mcolString As New Collection
Private Sub Form_Load()
With mcolString
.Add "Good morning Guys/Gals", "Lyla"
.Add "Good morning Lyla", "Guys"
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set mcolString = Nothing
End Sub
Private Sub Command1_Click()
With mcolString
.Add Right(.Item("Guys"), 4), "which"
MsgBox .Item(.Item("which"))
End With
End Sub
'**********************************************************
best regards
Sascha
Sascha
Good Answer :)
Lyla
I can understand what you are trying to do but you are mixing things which are dynamic (ie the contents of strings) with something that is static (ie the names of variables).
When you do this it is very easy to become not only confused but also very lost... hence the reason people didn't understant what you were attempting to do.
I would say the best solution is that which Sascha gave you althought I would include error checking just in case the string you are searching for does not exist in the collection.
Using this method you can have several key "phrases" that you can then assign strings to be replaced with and could do it on the fly.
The use of the word Lyla as a variable simply says that it is a pointer to a string and it could be called Beetlejuice as far as anyone is concerned. When you compile your application the word Lyla is completely removed as it only has meaning when you are coding it.
That is why we can basically use anything for a variable name... because all of those names are collected up and thrown out the window when it is compiled to be replaced with pointers that still do the job.... the name only has meaning to the programmer and that is why you really shouldn't and wouldn't use it inside your code as you were trying to do.
Sascha. That's IT :):):):):)
Thank you all for helping.
my guess...
Lyla is printing the string to a file
and then reading the file for display, but
when she does she is getting the file
delimiters imposed on the string.
this is not your answer but it will show you
one way to get rid of the delimiter...
Print statement instead of write..Private Sub Command1_Click()
Lyla = "Good morning Guys/Gals"
Guys = "Good morning Lyla"
which = Right(Guys, 4)
'Toggle a breakpoint in your code
'and chech the value of which ???
MsgBox which ' ==> "Lyla" with Quotes
Dim file2
file2 = "c:\a\a.txt"
Dim fnum As Integer
fnum = FreeFile
Open file2 For Output As fnum
Print #fnum, which
Close fnum
Open file2 For Input As fnum
Input #fnum, which
MsgBox which
Close
End Sub