Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to get a word between 2 Certain words in textbox

Posted on 2004-09-22
7
Medium Priority
?
191 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
Technology Partners: 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 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 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

650 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