[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to get a word between 2 Certain words in textbox

Posted on 2004-09-22
7
Medium Priority
?
193 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
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
Industry Leaders: 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
Suggested Courses
Course of the Month17 days, 15 hours left to enroll

829 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