getting text from a textbox

Posted on 2003-03-08
Medium Priority
Last Modified: 2010-05-01
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



Question by:timmy01
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 18

Expert Comment

ID: 8093394
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.

Expert Comment

ID: 8093418
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"

Author Comment

ID: 8093428
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.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 13

Expert Comment

ID: 8093429
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
LVL 18

Expert Comment

ID: 8093449
Oops sorry. You should have provided this detail with the original question. It would have helped to answer. Anyway no hard feelings. ;-)

Expert Comment

ID: 8093518
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

Expert Comment

ID: 8093524

Expert Comment

ID: 8093525
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


Expert Comment

ID: 8093583
my solution is generic it doesn't stick to anything like 't=' only...

Accepted Solution

DocM earned 200 total points
ID: 8093893
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

Expert Comment

ID: 8094715
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question