Solved

how to get a word between 2 Certain words in textbox

Posted on 2004-09-22
7
187 Views
Last Modified: 2010-05-02
i have text file contain info like this
======================
1|word1 web
2|word2 web
3|word2 web
.
.
.
.etc
====================
how to get the word between the (|).... and (web) in this text
0
Comment
Question by:dmxzx27
[X]
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
7 Comments
 
LVL 4

Expert Comment

by:cachedVB
ID: 12127775
an option is
'''''''''''''''''''''''''''''''''''''''''''
dim firstsplit
dim secondsplit
dim midword as string

firstsplit = split(text1.text, "|")
secondsplit = split(firstsplit, " ")
midword = secondsplit(0)
''''''''''''''''''''''''''''''''''''''''''
midword = either word1 or word2 in this case.

Cheers :)
0
 
LVL 1

Expert Comment

by:rickyman35
ID: 12127804
MsgBox Mid("1|word1 web", 3, 5)
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 12128254
Or this:

    sVal = "1|word1 web"
   
    iStart = InStr(sVal, "|")
    sWord = Mid(sVal, iStart + 1, InStrRev(sVal, " web") - iStart)


Same principle as rickman35's solution, but a bit more flexible.

Hope this helps.
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12128639
Private Sub Command1_Click()
    Dim word As String
    word = getWord("1|word1 web")
    If word <> "" Then
        MsgBox word
    End If
End Sub

Private Function getWord(ByVal strInput As String) As String
    Dim pipePos As Long
    Dim spacePos As Long
   
    pipePos = InStr(strInput, "|")
    If pipePos > 0 Then
        spacePos = InStr(pipePos, strInput, " ")
        If spacePos > 0 Then
            getWord = Mid(strInput, pipePos + 1, spacePos - pipePos - 1)
        Else
            MsgBox strInput, vbCritical, "Invalid Input"
        End If
    Else
        MsgBox strInput, vbCritical, "Invalid Input"
    End If
End Function
0
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 12130185
Try this:

strW = "1|word1 web"

Trim(Split(Mid(strW, Instr(1, strW, "|") + 1), " ")(0))
0
 
LVL 3

Accepted Solution

by:
sgayatri earned 50 total points
ID: 12130802
Add Project >> References >> Microsoft scripting runtime  to yur project

The followingcode will read a txt file called abc.log and print the words as required by you.
abc.log file should contain your txt as mentioned in your question


Dim fso As New FileSystemObject
    Dim fil1 As File, ts As TextStream
    If fso.FileExists("c:\windows\desktop\abc.log") Then
        Set fil1 = fso.GetFile("c:\windows\desktop\abc.log")
        Set ts = fil1.OpenAsTextStream(ForReading)
           
        While ts.AtEndOfStream = False
          str1 = ts.ReadLine
          MsgBox Trim(Split(Mid(str1, InStr(1, str1, "|") + 1), " ")(0))
         
        Wend
   Else
       MsgBox "File abc.log does not exist!"
   End If
0
 
LVL 1

Expert Comment

by:crjor
ID: 12138410
Try this

Plase a RichTextBox on your form. (if it is not part of component list add it - Ctrl+T)
I use this to quickly open a text file, you can also use open or the file object)

Private Sub Command1_Click()

  Dim str As String
  Dim a As Variant
  Dim i As Integer
  Dim sTmp As String
  Dim sFirst As String
  Dim sSecond As String

  RichTextBox1.LoadFile "g:\MyFile.txt"

  str = RichTextBox1.Text
  sFirst = "|"
  sSecond = "web"
 
  a = Split(str, vbCrLf)
  For i = 0 To UBound(a)
    sTmp = sTmp & Mid(a(i), _
            InStr(1, a(i), sFirst) + Len(sFirst), _
            InStrRev(a(i), sSecond) - Len(sSecond)) & vbCrLf
 
  Next i
 
  set a = nothing  
  MsgBox sTmp
 
End Sub

cya!
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

729 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