• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

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



1 Solution
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.
you can write as follows
   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"
timmy01Author Commented:
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.
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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)
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 ...


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)

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
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)
   strText = "NOT FOUND"
End If

MsgBox strText

my solution is generic it doesn't stick to anything like 't=' only...
The Split function is OK if you are sure there is
no "=" sign inside the quotation marks.
Otherwise, better use your own function:
For example:

While EOF(1) = False
  Line Input #1, a
  If InStr(a, "t =") > 0 Then

   result = Mid(a, InStr(a, "t =") + Len("t ="))

   'Remove quotation marks
   result = LTrim(result)
   If Left(result, 1) = Chr(34) Then
    result = Mid(result, 2)
    If InStr(result, Chr(34)) > 0 Then
       result = Mid(result, 1, InStr(result, Chr(34)) - 1) & Mid(result, InStr(result, Chr(34)) + 1)
    End If
   End If
   MsgBox result
  End If
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...


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now