Home All Groups Group Topic Archive Search About
Author
7 Mar 2006 12:17 PM
Ron
Hi
I want to search a string for the first showing of a minus sign eg asc(45)
place all the text to the left of the sign in a textbox1 and all the rest in
textbox2.
can you indicate the best way to do this please

Author
7 Mar 2006 12:46 PM
S. I. Becker
Ron wrote:
> Hi
> I want to search a string for the first showing of a minus sign eg asc(45)
> place all the text to the left of the sign in a textbox1 and all the rest in
> textbox2.
> can you indicate the best way to do this please

Take a look at the InStr, Left, Mid and Right string functions, e.g.

Dim Text As String
Dim pos As Integer

' Read Text in from wherever
' Text = ....

pos = InStr(1, Text, "-")
TextBox1.Text = Left$(Text, pos-1)
TextBox2.Text = Mid$(Text, pos+1)
Author
7 Mar 2006 1:12 PM
Michael C
Show quote Hide quote
"S. I. Becker" <stewart@becker.nospam> wrote in message
news:440D8093.1000005@becker.nospam...
> Ron wrote:
>> Hi I want to search a string for the first showing of a minus sign eg
>> asc(45) place all the text to the left of the sign in a textbox1 and all
>> the rest in textbox2.
>> can you indicate the best way to do this please
>
> Take a look at the InStr, Left, Mid and Right string functions, e.g.
>
> Dim Text As String
> Dim pos As Integer
>
> ' Read Text in from wherever
> ' Text = ....
>
> pos = InStr(1, Text, "-")
> TextBox1.Text = Left$(Text, pos-1)
> TextBox2.Text = Mid$(Text, pos+1)

also check for pos = -1
Author
7 Mar 2006 1:20 PM
Larry Serflaten
"Michael C" <nospam@nospam.com> wrote

> > pos = InStr(1, Text, "-")
>
> also check for pos = -1


Why bother?
Author
7 Mar 2006 1:48 PM
S. I. Becker
Larry Serflaten wrote:
> "Michael C" <nospam@nospam.com> wrote
>
>>> pos = InStr(1, Text, "-")
>> also check for pos = -1
>
>
> Why bother?
>
>
Why bother indeed, when InStr never returns -1.  A "not found" result is
0.  Michael is right in that there should be a test for this though, as
Left$(x, -1) will yield an error, but this was lunch-break code.

Stewart
Author
7 Mar 2006 3:15 PM
Rick Rothstein [MVP - Visual Basic]
> >>> pos = InStr(1, Text, "-")
> >> also check for pos = -1
> >
> > Why bother?
> >
> >
> Why bother indeed, when InStr never returns -1.  A
> "not found" result is 0.  Michael is right in that there
> should be a test for this though, as Left$(x, -1) will
> yield an error, but this was lunch-break code.

You could always use this expression for filling in TextBox1 and eliminate
the separate, external error check...

    TextBox1.Text = Left$(Text, pos + (pos > 0))

Rick
Author
7 Mar 2006 10:50 PM
Michael C
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:OpF9$neQGHA.1868@TK2MSFTNGP09.phx.gbl...
>
> "Michael C" <nospam@nospam.com> wrote
>
>> > pos = InStr(1, Text, "-")
>>
>> also check for pos = -1
>
>
> Why bother?

As becker said to avoid an error, although I was incorrect in saying -1.
Show quoteHide quote
>
>
Author
7 Mar 2006 2:52 PM
Martin Walke
HI,

You can also use the split function

dim tstr as string, arry
'get input string
tstr = ...

arry = split (tstr,"-",2)

then arry(0) contains the part before the first minus and arry(1) conatin
the rest of the string.

HTH
Martin

Show quoteHide quote
"S. I. Becker" <stewart@becker.nospam> wrote in message
news:440D8093.1000005@becker.nospam...
> Ron wrote:
>> Hi I want to search a string for the first showing of a minus sign eg
>> asc(45) place all the text to the left of the sign in a textbox1 and all
>> the rest in textbox2.
>> can you indicate the best way to do this please
>
> Take a look at the InStr, Left, Mid and Right string functions, e.g.
>
> Dim Text As String
> Dim pos As Integer
>
> ' Read Text in from wherever
> ' Text = ....
>
> pos = InStr(1, Text, "-")
> TextBox1.Text = Left$(Text, pos-1)
> TextBox2.Text = Mid$(Text, pos+1)
Author
7 Mar 2006 4:52 PM
Ron
Hi All
I have not tried all your suggested posts as yet, but I have created the
following code and I am getting good results but you may be able to offer
some better options so I post my code here:-

Function myUpdate_Music()
Dim pos, myStop As Integer
Dim myHold, myHold1, myHold2, myHold3 As String

On Error GoTo upDateError
  With mdiMusic
      With List_Input
        myHold = txtTrackName ' txtTrackName contains the string
          'search string with InStr
            pos = InStr(1, myHold, "-")  ' search for asc 45
            myHold1 = Left$(myHold, pos - 1)
            myHold2 = Mid$(myHold, pos + 1)
            myStop = InStr(1, myHold2, "V") ' search for asc 86
            myHold3 = Left$(myHold2, myStop - 2)
          'exit search post data
        Music.strTrackNo = .txtTrackNo
        .txtArtists = myHold3
        .txtTrackName = myHold1
        Music.strArtists = myHold3 '.txtArtists
        Music.strTrackName = myHold1 '.txtTrackName

          If .txtArtists = "" Then
             .txtArtists = InputBox("Enter Artists Name", "Artists Name Not
Shown", , 5000, 3000)
             Music.strArtists = .txtArtists
          End If
      End With
    .adoMusic.Recordset.MoveLast
    .adoMusic.Recordset.AddNew
    .dbgDataBase.Columns(0) = Music.strTrackNo
    .dbgDataBase.Columns(1) = Music.strTrackName
    .dbgDataBase.Columns(2) = Music.strArtists
  End With
  Call Music.Update_Tracks

upDateError:
Exit Function
End Function
'****
I do not see any errors when I run the code, but if I step through the code
the step trip gives the correct answers but then the code loops to *** and
drops out to my error trap why does it loop?
It appears to me that you cannot use asc characters for this search is that
correct?

Show quoteHide quote
"Martin Walke" wrote:

> HI,
>
> You can also use the split function
>
> dim tstr as string, arry
> 'get input string
> tstr = ...
>
> arry = split (tstr,"-",2)
>
> then arry(0) contains the part before the first minus and arry(1) conatin
> the rest of the string.
>
> HTH
> Martin
>
> "S. I. Becker" <stewart@becker.nospam> wrote in message
> news:440D8093.1000005@becker.nospam...
> > Ron wrote:
> >> Hi I want to search a string for the first showing of a minus sign eg
> >> asc(45) place all the text to the left of the sign in a textbox1 and all
> >> the rest in textbox2.
> >> can you indicate the best way to do this please
> >
> > Take a look at the InStr, Left, Mid and Right string functions, e.g.
> >
> > Dim Text As String
> > Dim pos As Integer
> >
> > ' Read Text in from wherever
> > ' Text = ....
> >
> > pos = InStr(1, Text, "-")
> > TextBox1.Text = Left$(Text, pos-1)
> > TextBox2.Text = Mid$(Text, pos+1)
>
>
>
Author
7 Mar 2006 6:47 PM
Lesley Regan
Show quote Hide quote
"Martin Walke" wrote:

> HI,
>
> You can also use the split function
>
> dim tstr as string, arry
> 'get input string
> tstr = ...
>
> arry = split (tstr,"-",2)
>
> then arry(0) contains the part before the first minus and arry(1) conatin
> the rest of the string.
>
> HTH
> Martin
>
> "S. I. Becker" <stewart@becker.nospam> wrote in message
> news:440D8093.1000005@becker.nospam...
> > Ron wrote:
> >> Hi I want to search a string for the first showing of a minus sign eg
> >> asc(45) place all the text to the left of the sign in a textbox1 and all
> >> the rest in textbox2.
> >> can you indicate the best way to do this please
> >
> > Take a look at the InStr, Left, Mid and Right string functions, e.g.
> >
> > Dim Text As String
> > Dim pos As Integer
> >
> > ' Read Text in from wherever
> > ' Text = ....
> >
> > pos = InStr(1, Text, "-")
> > TextBox1.Text = Left$(Text, pos-1)
> > TextBox2.Text = Mid$(Text, pos+1)
>
>
>
"Martin Walke" wrote:

> HI,
>
> You can also use the split function
>
> dim tstr as string, arry
> 'get input string
> tstr = ...
>
> arry = split (tstr,"-",2)
>
> then arry(0) contains the part before the first minus and arry(1) conatin
> the rest of the string.
>
> HTH
> Martin
>
Hi, Ron,

I like "split" and have used it with great success on various strings that
needed parsing into sections.  Once you "split" the string, you can take the
components and manipulate them or store them in many ways.

As long as you know a "-" will always be there, and that's how you want to
divide your string, it's clean, it eliminates the "-" automatically,  and the
code is easy to read.  -- That's my two cents,

Lesley
Author
7 Mar 2006 7:40 PM
Richard Jalbert
On Tue, 7 Mar 2006 10:47:28 -0800, =?Utf-8?B?TGVzbGV5IFJlZ2Fu?=
<regan@miller[donotspam]canfield.com> wrote:

Show quoteHide quote
>"Martin Walke" wrote:
>
>> HI,
>>
>> You can also use the split function
>>
>> dim tstr as string, arry
>> 'get input string
>> tstr = ...
>>
>> arry = split (tstr,"-",2)
>>
>> then arry(0) contains the part before the first minus and arry(1) conatin
>> the rest of the string.
>>
>> HTH
>> Martin
>>
>> "S. I. Becker" <stewart@becker.nospam> wrote in message
>> news:440D8093.1000005@becker.nospam...
>> > Ron wrote:
>> >> Hi I want to search a string for the first showing of a minus sign eg
>> >> asc(45) place all the text to the left of the sign in a textbox1 and all
>> >> the rest in textbox2.
>> >> can you indicate the best way to do this please
>> >
>> > Take a look at the InStr, Left, Mid and Right string functions, e.g.
>> >
>> > Dim Text As String
>> > Dim pos As Integer
>> >
>> > ' Read Text in from wherever
>> > ' Text = ....
>> >
>> > pos = InStr(1, Text, "-")
>> > TextBox1.Text = Left$(Text, pos-1)
>> > TextBox2.Text = Mid$(Text, pos+1)
>>
>>
>>
>"Martin Walke" wrote:
>
>> HI,
>>
>> You can also use the split function
>>
>> dim tstr as string, arry
>> 'get input string
>> tstr = ...
>>
>> arry = split (tstr,"-",2)
>>
>> then arry(0) contains the part before the first minus and arry(1) conatin
>> the rest of the string.
>>
>> HTH
>> Martin
>>
>Hi, Ron,
>
>I like "split" and have used it with great success on various strings that
>needed parsing into sections.  Once you "split" the string, you can take the
>components and manipulate them or store them in many ways.
>
>As long as you know a "-" will always be there, and that's how you want to
>divide your string, it's clean, it eliminates the "-" automatically,  and the
>code is easy to read.  -- That's my two cents,
>
>Lesley

I would check teh LBound and the UBound to see if the number after the
"-" is there.

Brain-fart...Come to think of it if teh "-" is the first character,
the error is compounded.
In this case I would use Mid$ with Trim$ on both fragments.
**********************************************************************
Richm***@sympatico.ca

Dog thinks: they feed me, they take care of me: they are gods.
Cat thinks: they feed me, they take care of me: I am god.
http://www3.sympatico.ca/richmann/
http://www.geocities.com/richmannsoft/
**********************************************************************
Author
8 Mar 2006 7:53 AM
Ron
Hi All
I have not tried all your suggested posts as yet, but I have created the
following code and I am getting good results but you may be able to offer
some better options so I post my code here:-

Function myUpdate_Music()
Dim pos, myStop As Integer
Dim myHold, myHold1, myHold2, myHold3 As String

On Error GoTo upDateError
  With mdiMusic
      With List_Input
        myHold = txtTrackName ' txtTrackName contains the string
          'search string with InStr
            pos = InStr(1, myHold, "-")  ' search for asc 45
            myHold1 = Left$(myHold, pos - 1)
            myHold2 = Mid$(myHold, pos + 1)
            myStop = InStr(1, myHold2, "V") ' search for asc 86
            myHold3 = Left$(myHold2, myStop - 2)
          'exit search post data
        Music.strTrackNo = .txtTrackNo
        .txtArtists = myHold3
        .txtTrackName = myHold1
        Music.strArtists = myHold3 '.txtArtists
        Music.strTrackName = myHold1 '.txtTrackName

          If .txtArtists = "" Then
             .txtArtists = InputBox("Enter Artists Name", "Artists Name Not
Shown", , 5000, 3000)
             Music.strArtists = .txtArtists
          End If
      End With
    .adoMusic.Recordset.MoveLast
    .adoMusic.Recordset.AddNew
    .dbgDataBase.Columns(0) = Music.strTrackNo
    .dbgDataBase.Columns(1) = Music.strTrackName
    .dbgDataBase.Columns(2) = Music.strArtists
  End With
  Call Music.Update_Tracks

upDateError:
Exit Function
End Function
'****
I do not see any errors when I run the code, but if I step through the code
the step trip gives the correct answers but then the code loops to *** and
drops out to my error trap why does it loop?
It appears to me that you cannot use asc characters for this search is that
correct?