Solved

how to get a word between 2 Certain words in textbox

Posted on 2004-09-22
7
182 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
Comment Utility
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
Comment Utility
MsgBox Mid("1|word1 web", 3, 5)
0
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now