Link to home
Start Free TrialLog in
Avatar of timmy01
timmy01

asked on

getting text from a textbox

Hi guys

Ok say i have a textbox, the textbox contains the following text

hello there
t = "have a nice day"

now i need some code that could for eg, look through the textbox's text and
if it finds the line "t =" it displays the line in say a msgbox but it only
displays the "have a nice day" (without the quotation marks).....any help on
this would be much appreciated

Thanks

Tim

Avatar of Sethi
Sethi
Flag of India image

With Due respect this seems like a Homework question to me. If yes then EE doesn't solve homework questions. However, if you have put in some effort or have some ideas to acheiev this then we are with you.
Avatar of avya2k
avya2k

you can write as follows
if(instr(1,text1.text,t)>0)then
   msgbox "text found at " & instr(1,text1.text,t)
end if
if your text1.text is "Have a nice day"
and t="Nice Day" then msgbox will be
"text found at 8"
Avatar of timmy01

ASKER

no this is not a homework question mate .....i figure if i can read in 1 line from a textbox i can use it for what i really want it to do ...if you must know, i have a DHTML box and when you insert an image via the ExecCommand DECMD_IMAGE command it puts the following in the html code src="c:\wherever" ..if this line exists i would like to to be able to get it so later on it can be encoded with base64 so it can be fit for an email message ....i simplified this in my first question so as not to confuse anyone.
Option Explicit
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim str4 As String
Dim a As Integer
Dim b As Integer
Dim i As Integer
Dim j As Integer
Private Sub Command1_Click()
str1 = " "
str2 = " "
str3 = " "
str4 = " "
str1 = Text1.Text
a = 1
b = 1
For i = 1 To Len(str1)
If Mid(str1, i, 2) = vbCrLf Then
b = i
str2 = Mid(str1, a, b - a)
a = b
'MsgBox str2
For j = 1 To Len(str2)
If Mid(str2, j, 3) = "t =" Then
str3 = Mid(str2, j + 3, Len(str2) - (j + 2))
'MsgBox str3
If Mid(Trim(str3), 1, 1) = Mid("""", 1, 1) Then
If Mid(Trim(str3), Len(Trim(str3)), 1) = Mid("""", 1, 1) Then
str4 = Mid(Trim(str3), 2, Len(Trim(str3)) - 2)
Else
str4 = Mid(Trim(str3), 2, Len(Trim(str3)))
End If
MsgBox str4
End If
End If
Next j
End If
Next i
End Sub
Oops sorry. You should have provided this detail with the original question. It would have helped to answer. Anyway no hard feelings. ;-)
why do things in such a complicated fashion...

use the SPLIT() function with '=' as a seperator ... this would cause it to return an array of strings ...

eg...

t="have a nice day"


will result in an array of 2 strings (the LEFT portion and the Right portion of the 'EQUATION'!)

1> t
2> "have a nice day"

you select the 2nd string and then removing the 'quotes' is an easy job ...
do this..

dim str as string
'suppose the 2nd string is returned in sec_str

'this will omit the quote on the right side
str = Left(sec_str,Len(sec_str)-1)

'replace
sec_str = str

'this will omit the quote on the left side
str = Right(sec_str,Len(sec_str)-1)

so finally u have the required string in the variable 'str'


hope that helps
cryptosid
Just write the following code in the even you want.


dim strText as String
dim lngStart, lngEnd

If InStr(Text1.Text,"t=")>0 Then
   lngStart = InStr(Text1.Text,"""")
   lngEnd = InStr(lngStart+1,Text1.Text,"""")
   strText = Mid(Text1.Text,lngStart+1,lngEnd - lngStart)
Else
   strText = "NOT FOUND"
End If

MsgBox strText

my solution is generic it doesn't stick to anything like 't=' only...
ASKER CERTIFIED SOLUTION
Avatar of DocM
DocM

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
Point noted DOCm very keen observation!!! and  in that fashion there are infinite possibilities...what timmy01 needs to see is the kind of data he/she is handling...timmy01 its up to u then...

cheers