Home All Groups Group Topic Archive Search About

Problem populating a combobox if cases differ

Author
25 Feb 2007 11:11 PM
Saucer Man
I am trying to populate a combobox with all files in  a certain folder with
a .png extension.  Hers what i have...

             Dim strFileName As String
620       frmMain.cboEffect.AddItem "None"

630       strFileName = Dir$(strShortPath & "\*.png")
640       strFileName = Replace(strFileName, ".png", "")
650       strFileName = StrConv(strFileName, vbProperCase)
660       While strFileName <> ""
670           frmMain.cboEffect.AddItem strFileName
680           strFileName = Replace(Dir$, ".png", "")
690           strFileName = StrConv(strFileName, vbProperCase)
700       Wend

I want to remove the .png extension in the combobox.  The problem is, if the
..png is .PNG, it is not working.  How do i correct this?

--

Thanks.

Author
25 Feb 2007 11:36 PM
Paul Lambert
Saucer Man wrote:
Show quoteHide quote
> I am trying to populate a combobox with all files in  a certain folder with
> a .png extension.  Hers what i have...
>
>              Dim strFileName As String
> 620       frmMain.cboEffect.AddItem "None"
>
> 630       strFileName = Dir$(strShortPath & "\*.png")
> 640       strFileName = Replace(strFileName, ".png", "")
> 650       strFileName = StrConv(strFileName, vbProperCase)
> 660       While strFileName <> ""
> 670           frmMain.cboEffect.AddItem strFileName
> 680           strFileName = Replace(Dir$, ".png", "")
> 690           strFileName = StrConv(strFileName, vbProperCase)
> 700       Wend
>
> I want to remove the .png extension in the combobox.  The problem is, if the
> .png is .PNG, it is not working.  How do i correct this?
>

Try :

strFileName = Replace(strFileName, ".png", "",,vbTextCompare)

Regards,
Paul.

--
Posted via a free Usenet account from http://www.teranews.com
Author
25 Feb 2007 11:53 PM
Saucer Man
That didn't work.  I think the problem is in line 680.  The DIR$ is getting
the next file but it is an uppercase PNG.  The replace is not working as
when the program flows to line 690, strFileName still has the uppercase
..PNG.

--

Thanks.


Show quoteHide quote
"Paul Lambert" <paul.lamb***@autoledgers.com.au> wrote in message
news:45E21D62.6070102@autoledgers.com.au...
> Saucer Man wrote:
>> I am trying to populate a combobox with all files in  a certain folder
>> with a .png extension.  Hers what i have...
>>
>>              Dim strFileName As String
>> 620       frmMain.cboEffect.AddItem "None"
>>
>> 630       strFileName = Dir$(strShortPath & "\*.png")
>> 640       strFileName = Replace(strFileName, ".png", "")
>> 650       strFileName = StrConv(strFileName, vbProperCase)
>> 660       While strFileName <> ""
>> 670           frmMain.cboEffect.AddItem strFileName
>> 680           strFileName = Replace(Dir$, ".png", "")
>> 690           strFileName = StrConv(strFileName, vbProperCase)
>> 700       Wend
>>
>> I want to remove the .png extension in the combobox.  The problem is, if
>> the .png is .PNG, it is not working.  How do i correct this?
>>
>
> Try :
>
> strFileName = Replace(strFileName, ".png", "",,vbTextCompare)
>
> Regards,
> Paul.
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>
Author
26 Feb 2007 12:20 AM
Paul Lambert
Saucer Man wrote:
> That didn't work.  I think the problem is in line 680.  The DIR$ is getting
> the next file but it is an uppercase PNG.  The replace is not working as
> when the program flows to line 690, strFileName still has the uppercase
> .PNG.
>
  Do the same thing to line 680 as well.

I.e. adding the ,,vbTextCompare to the end of your replace function call.

--
Posted via a free Usenet account from http://www.teranews.com
Author
26 Feb 2007 12:34 AM
Saucer Man
I did.  I replaced both instances but it doesn't work.

--

Thanks.


Show quoteHide quote
"Paul Lambert" <paul.lamb***@autoledgers.com.au> wrote in message
news:45E227D4.2000006@autoledgers.com.au...
> Saucer Man wrote:
>> That didn't work.  I think the problem is in line 680.  The DIR$ is
>> getting the next file but it is an uppercase PNG.  The replace is not
>> working as when the program flows to line 690, strFileName still has the
>> uppercase .PNG.
>>
>  Do the same thing to line 680 as well.
>
> I.e. adding the ,,vbTextCompare to the end of your replace function call.
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>
Author
26 Feb 2007 12:24 AM
Larry Serflaten
"Saucer Man" <saucerman@nospam.net> wrote in message news:IjpEh.41719$19.33892@bignews3.bellsouth.net...
> That didn't work.  I think the problem is in line 680.  The DIR$ is getting
> the next file but it is an uppercase PNG.  The replace is not working as
> when the program flows to line 690, strFileName still has the uppercase
> .PNG.
>


Function ProperName(FileName As String) As String
Dim pos As Long
  pos = InStr(LCase$(FileName), ".png")
  If pos > 0 Then
    ProperName = StrConv(Left$(FileName, pos - 1), vbProperCase)
  End If
End Function

LFS
Author
26 Feb 2007 12:36 AM
Saucer Man
Larry, does this function replace any case combination of "png" with ""?
That's what I am trying to accomplish.

--

Thanks.


Show quoteHide quote
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:u8S6GyTWHHA.4844@TK2MSFTNGP03.phx.gbl...
>
> "Saucer Man" <saucerman@nospam.net> wrote in message
> news:IjpEh.41719$19.33892@bignews3.bellsouth.net...
>> That didn't work.  I think the problem is in line 680.  The DIR$ is
>> getting
>> the next file but it is an uppercase PNG.  The replace is not working as
>> when the program flows to line 690, strFileName still has the uppercase
>> .PNG.
>>
>
>
> Function ProperName(FileName As String) As String
> Dim pos As Long
>  pos = InStr(LCase$(FileName), ".png")
>  If pos > 0 Then
>    ProperName = StrConv(Left$(FileName, pos - 1), vbProperCase)
>  End If
> End Function
>
> LFS
>
>
Author
26 Feb 2007 12:57 AM
Rick Rothstein (MVP - VB)
> Larry, does this function replace any case combination of "png" with ""?
> That's what I am trying to accomplish.

Larry's code doesn't replace any text; what it does is find the ".png" (with
any initial case), and then truncates the text (that's what the Left$
function does) in front of its dot (and, afterward, proper cases the
result).

Rick
Author
26 Feb 2007 2:26 AM
Larry Serflaten
"Saucer Man" <saucerman@nospam.net> wrote
> Larry, does this function replace any case combination of "png" with ""?
> That's what I am trying to accomplish.

It doesn't use Replace.  It removes those characters (and any following) from
the string.

You'd use it something like:

strFileName = Dir$(strShortPath & "\*.png")
strFileName = ProperName(strFileName)
While Len(strFileName) > 0
    frmMain.cboEffect.AddItem strFileName
    strFileName = ProperName(Dir())
Wend

LFS
Author
25 Feb 2007 11:56 PM
Michael C
Show quote Hide quote
"Saucer Man" <saucerman@nospam.net> wrote in message
news:eIoEh.44789$I8.351@bignews8.bellsouth.net...
>I am trying to populate a combobox with all files in  a certain folder with
>a .png extension.  Hers what i have...
>
>             Dim strFileName As String
> 620       frmMain.cboEffect.AddItem "None"
>
> 630       strFileName = Dir$(strShortPath & "\*.png")
> 640       strFileName = Replace(strFileName, ".png", "")
> 650       strFileName = StrConv(strFileName, vbProperCase)
> 660       While strFileName <> ""
> 670           frmMain.cboEffect.AddItem strFileName
> 680           strFileName = Replace(Dir$, ".png", "")
> 690           strFileName = StrConv(strFileName, vbProperCase)
> 700       Wend

VB doesn't need line numbers.

Michael
Author
26 Feb 2007 12:34 AM
Saucer Man
I know.  I use line numbers for error trapping.

--

Thanks.


Show quoteHide quote
"Michael C" <nospam@nospam.com> wrote in message
news:%23sreMfTWHHA.5108@TK2MSFTNGP06.phx.gbl...
> "Saucer Man" <saucerman@nospam.net> wrote in message
> news:eIoEh.44789$I8.351@bignews8.bellsouth.net...
>>I am trying to populate a combobox with all files in  a certain folder
>>with a .png extension.  Hers what i have...
>>
>>             Dim strFileName As String
>> 620       frmMain.cboEffect.AddItem "None"
>>
>> 630       strFileName = Dir$(strShortPath & "\*.png")
>> 640       strFileName = Replace(strFileName, ".png", "")
>> 650       strFileName = StrConv(strFileName, vbProperCase)
>> 660       While strFileName <> ""
>> 670           frmMain.cboEffect.AddItem strFileName
>> 680           strFileName = Replace(Dir$, ".png", "")
>> 690           strFileName = StrConv(strFileName, vbProperCase)
>> 700       Wend
>
> VB doesn't need line numbers.
>
> Michael
>
Author
26 Feb 2007 2:42 AM
Michael C
"Saucer Man" <saucerman@nospam.net> wrote in message
news:%VpEh.11635$e8.765@bignews1.bellsouth.net...
>I know.  I use line numbers for error trapping.

So do I but I have an addin that does them sequentially for each line
starting at 1 for each routine. It also skips lines that cannot error such
as End If.

Michael
Author
26 Feb 2007 4:20 PM
Saucer Man
I'm using an add-on also.

--

Thanks.


Show quoteHide quote
"Michael C" <nospam@nospam.com> wrote in message
news:ucbhT8UWHHA.1120@TK2MSFTNGP02.phx.gbl...
> "Saucer Man" <saucerman@nospam.net> wrote in message
> news:%VpEh.11635$e8.765@bignews1.bellsouth.net...
>>I know.  I use line numbers for error trapping.
>
> So do I but I have an addin that does them sequentially for each line
> starting at 1 for each routine. It also skips lines that cannot error such
> as End If.
>
> Michael
>
Author
26 Feb 2007 10:50 PM
Michael C
"Saucer Man" <saucerman@nospam.net> wrote in message
news:lNDEh.21932$m7.7672@bignews5.bellsouth.net...
> I'm using an add-on also.

Why does it increment by 10 then?

Michael
Author
26 Feb 2007 11:06 PM
Saucer Man
Probably because thats what the add-on is set for by default.  I didn't
change it.

--

Thanks.


Show quoteHide quote
"Michael C" <nospam@nospam.com> wrote in message
news:OIkGPffWHHA.480@TK2MSFTNGP02.phx.gbl...
> "Saucer Man" <saucerman@nospam.net> wrote in message
> news:lNDEh.21932$m7.7672@bignews5.bellsouth.net...
>> I'm using an add-on also.
>
> Why does it increment by 10 then?
>
> Michael
>
Author
26 Feb 2007 12:42 AM
Bob Butler
"Saucer Man" <saucerman@nospam.net> wrote in message
news:eIoEh.44789$I8.351@bignews8.bellsouth.net
> I am trying to populate a combobox with all files in  a certain
> folder with a .png extension.  Hers what i have...
>
>              Dim strFileName As String
> 620       frmMain.cboEffect.AddItem "None"
>
> 630       strFileName = Dir$(strShortPath & "\*.png")
> 640       strFileName = Replace(strFileName, ".png", "")
> 650       strFileName = StrConv(strFileName, vbProperCase)

If you reverse those two lines you'll know that the .png is lower case in
the filename.

> 660       While strFileName <> ""
> 670           frmMain.cboEffect.AddItem strFileName
> 680           strFileName = Replace(Dir$, ".png", "")
> 690           strFileName = StrConv(strFileName, vbProperCase)

invert those two as well

> 700       Wend
>
> I want to remove the .png extension in the combobox.  The problem is,
> if the .png is .PNG, it is not working.  How do i correct this?

Adding the optional vbTextCompare argument should also have worked for you

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
26 Feb 2007 5:18 PM
Saucer Man
I reversed the last two lines in both groups and that didn't work either.
I'm curious why I can't get this work by adding the vbTextCompare.  I am
using SP5.  Is there an issue with that in SP5?

--

Thanks.


Show quoteHide quote
"Bob Butler" <tiredofit@nospam.ever> wrote in message
news:eSz0Q8TWHHA.4832@TK2MSFTNGP04.phx.gbl...
> "Saucer Man" <saucerman@nospam.net> wrote in message
> news:eIoEh.44789$I8.351@bignews8.bellsouth.net
>> I am trying to populate a combobox with all files in  a certain
>> folder with a .png extension.  Hers what i have...
>>
>>              Dim strFileName As String
>> 620       frmMain.cboEffect.AddItem "None"
>>
>> 630       strFileName = Dir$(strShortPath & "\*.png")
>> 640       strFileName = Replace(strFileName, ".png", "")
>> 650       strFileName = StrConv(strFileName, vbProperCase)
>
> If you reverse those two lines you'll know that the .png is lower case in
> the filename.
>
>> 660       While strFileName <> ""
>> 670           frmMain.cboEffect.AddItem strFileName
>> 680           strFileName = Replace(Dir$, ".png", "")
>> 690           strFileName = StrConv(strFileName, vbProperCase)
>
> invert those two as well
>
>> 700       Wend
>>
>> I want to remove the .png extension in the combobox.  The problem is,
>> if the .png is .PNG, it is not working.  How do i correct this?
>
> Adding the optional vbTextCompare argument should also have worked for you
>
> --
> Reply to the group so all can participate
> VB.Net: "Fool me once..."
>
Author
26 Feb 2007 5:31 PM
Saucer Man
Could the . in there be causing the problem with the text compare?

--

Thanks.


Show quoteHide quote
"Saucer Man" <saucerman@nospam.net> wrote in message
news:gDEEh.21947$m7.19212@bignews5.bellsouth.net...
>I reversed the last two lines in both groups and that didn't work either.
>I'm curious why I can't get this work by adding the vbTextCompare.  I am
>using SP5.  Is there an issue with that in SP5?
>
> --
>
> Thanks.
>
>
> "Bob Butler" <tiredofit@nospam.ever> wrote in message
> news:eSz0Q8TWHHA.4832@TK2MSFTNGP04.phx.gbl...
>> "Saucer Man" <saucerman@nospam.net> wrote in message
>> news:eIoEh.44789$I8.351@bignews8.bellsouth.net
>>> I am trying to populate a combobox with all files in  a certain
>>> folder with a .png extension.  Hers what i have...
>>>
>>>              Dim strFileName As String
>>> 620       frmMain.cboEffect.AddItem "None"
>>>
>>> 630       strFileName = Dir$(strShortPath & "\*.png")
>>> 640       strFileName = Replace(strFileName, ".png", "")
>>> 650       strFileName = StrConv(strFileName, vbProperCase)
>>
>> If you reverse those two lines you'll know that the .png is lower case in
>> the filename.
>>
>>> 660       While strFileName <> ""
>>> 670           frmMain.cboEffect.AddItem strFileName
>>> 680           strFileName = Replace(Dir$, ".png", "")
>>> 690           strFileName = StrConv(strFileName, vbProperCase)
>>
>> invert those two as well
>>
>>> 700       Wend
>>>
>>> I want to remove the .png extension in the combobox.  The problem is,
>>> if the .png is .PNG, it is not working.  How do i correct this?
>>
>> Adding the optional vbTextCompare argument should also have worked for
>> you
>>
>> --
>> Reply to the group so all can participate
>> VB.Net: "Fool me once..."
>>
>
>
Author
26 Feb 2007 5:41 PM
Saucer Man
Ok...it wasn't working because I need 3 commas before the vbTextCompare.  I
only had two.  Now it is working. Thanks again.

--

Thanks.


Show quoteHide quote
"Saucer Man" <saucerman@nospam.net> wrote in message
news:gPEEh.21952$m7.5368@bignews5.bellsouth.net...
> Could the . in there be causing the problem with the text compare?
>
> --
>
> Thanks.
>
>
> "Saucer Man" <saucerman@nospam.net> wrote in message
> news:gDEEh.21947$m7.19212@bignews5.bellsouth.net...
>>I reversed the last two lines in both groups and that didn't work either.
>>I'm curious why I can't get this work by adding the vbTextCompare.  I am
>>using SP5.  Is there an issue with that in SP5?
>>
>> --
>>
>> Thanks.
>>
>>
>> "Bob Butler" <tiredofit@nospam.ever> wrote in message
>> news:eSz0Q8TWHHA.4832@TK2MSFTNGP04.phx.gbl...
>>> "Saucer Man" <saucerman@nospam.net> wrote in message
>>> news:eIoEh.44789$I8.351@bignews8.bellsouth.net
>>>> I am trying to populate a combobox with all files in  a certain
>>>> folder with a .png extension.  Hers what i have...
>>>>
>>>>              Dim strFileName As String
>>>> 620       frmMain.cboEffect.AddItem "None"
>>>>
>>>> 630       strFileName = Dir$(strShortPath & "\*.png")
>>>> 640       strFileName = Replace(strFileName, ".png", "")
>>>> 650       strFileName = StrConv(strFileName, vbProperCase)
>>>
>>> If you reverse those two lines you'll know that the .png is lower case
>>> in
>>> the filename.
>>>
>>>> 660       While strFileName <> ""
>>>> 670           frmMain.cboEffect.AddItem strFileName
>>>> 680           strFileName = Replace(Dir$, ".png", "")
>>>> 690           strFileName = StrConv(strFileName, vbProperCase)
>>>
>>> invert those two as well
>>>
>>>> 700       Wend
>>>>
>>>> I want to remove the .png extension in the combobox.  The problem is,
>>>> if the .png is .PNG, it is not working.  How do i correct this?
>>>
>>> Adding the optional vbTextCompare argument should also have worked for
>>> you
>>>
>>> --
>>> Reply to the group so all can participate
>>> VB.Net: "Fool me once..."
>>>
>>
>>
>
>
Author
26 Feb 2007 5:47 PM
Bob Butler
"Saucer Man" <saucerman@nospam.net> wrote in message
news:gPEEh.21952$m7.5368@bignews5.bellsouth.net
> Could the . in there be causing the problem with the text compare?

No; I think you need to post your revised code because something is not
being done correctly.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
26 Feb 2007 11:03 AM
Dave O.
For fear of stating the obvious, as you know all the files will end ".PNG",.
why not just chop off the last 4 characters?

Regards
Dave O.

Show quoteHide quote
"Saucer Man" <saucerman@nospam.net> wrote in message
news:eIoEh.44789$I8.351@bignews8.bellsouth.net...
>I am trying to populate a combobox with all files in  a certain folder with
>a .png extension.  Hers what i have...
>
>             Dim strFileName As String
> 620       frmMain.cboEffect.AddItem "None"
>
> 630       strFileName = Dir$(strShortPath & "\*.png")
> 640       strFileName = Replace(strFileName, ".png", "")
> 650       strFileName = StrConv(strFileName, vbProperCase)
> 660       While strFileName <> ""
> 670           frmMain.cboEffect.AddItem strFileName
> 680           strFileName = Replace(Dir$, ".png", "")
> 690           strFileName = StrConv(strFileName, vbProperCase)
> 700       Wend
>
> I want to remove the .png extension in the combobox.  The problem is, if
> the .png is .PNG, it is not working.  How do i correct this?
>
> --
>
> Thanks.
>
>
>
Author
26 Feb 2007 4:49 PM
Saucer Man
How do you do that?

--

Thanks.


Show quoteHide quote
"Dave O." <nob***@nowhere.com> wrote in message
news:ecYq7WZWHHA.4964@TK2MSFTNGP06.phx.gbl...
> For fear of stating the obvious, as you know all the files will end
> ".PNG",. why not just chop off the last 4 characters?
>
> Regards
> Dave O.
>
> "Saucer Man" <saucerman@nospam.net> wrote in message
> news:eIoEh.44789$I8.351@bignews8.bellsouth.net...
>>I am trying to populate a combobox with all files in  a certain folder
>>with a .png extension.  Hers what i have...
>>
>>             Dim strFileName As String
>> 620       frmMain.cboEffect.AddItem "None"
>>
>> 630       strFileName = Dir$(strShortPath & "\*.png")
>> 640       strFileName = Replace(strFileName, ".png", "")
>> 650       strFileName = StrConv(strFileName, vbProperCase)
>> 660       While strFileName <> ""
>> 670           frmMain.cboEffect.AddItem strFileName
>> 680           strFileName = Replace(Dir$, ".png", "")
>> 690           strFileName = StrConv(strFileName, vbProperCase)
>> 700       Wend
>>
>> I want to remove the .png extension in the combobox.  The problem is, if
>> the .png is .PNG, it is not working.  How do i correct this?
>>
>> --
>>
>> Thanks.
>>
>>
>>
>
>
Author
26 Feb 2007 5:27 PM
Rick Rothstein (MVP - VB)
Show quote Hide quote
>>>I am trying to populate a combobox with all files in  a certain folder
>>>with a .png extension.  Hers what i have...
>>>
>>>             Dim strFileName As String
>>> 620       frmMain.cboEffect.AddItem "None"
>>>
>>> 630       strFileName = Dir$(strShortPath & "\*.png")
>>> 640       strFileName = Replace(strFileName, ".png", "")
>>> 650       strFileName = StrConv(strFileName, vbProperCase)
>>> 660       While strFileName <> ""
>>> 670           frmMain.cboEffect.AddItem strFileName
>>> 680           strFileName = Replace(Dir$, ".png", "")
>>> 690           strFileName = StrConv(strFileName, vbProperCase)
>>> 700       Wend
>>>
>>> I want to remove the .png extension in the combobox.  The problem is, if
>>> the .png is .PNG, it is not working.  How do i correct this?
>>>
>> For fear of stating the obvious, as you know all the files will end
>> ".PNG",. why not just chop off the last 4 characters?
>>
> How do you do that?

Where you have this...

     strFileName = Replace(Dir$, ".png", "")

replace it with this...

     strTemp = Dir$
     strFileName = Left$(strTemp, Len(strTemp) - 4)

remembering to add the Dim statement for the strTemp variable, of course.

Rick
Author
26 Feb 2007 5:42 PM
Saucer Man
Thanks for all the help everyone!!!

--

Thanks.


Show quoteHide quote
"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message news:%23w7KcwcWHHA.5068@TK2MSFTNGP03.phx.gbl...
>>>>I am trying to populate a combobox with all files in  a certain folder
>>>>with a .png extension.  Hers what i have...
>>>>
>>>>             Dim strFileName As String
>>>> 620       frmMain.cboEffect.AddItem "None"
>>>>
>>>> 630       strFileName = Dir$(strShortPath & "\*.png")
>>>> 640       strFileName = Replace(strFileName, ".png", "")
>>>> 650       strFileName = StrConv(strFileName, vbProperCase)
>>>> 660       While strFileName <> ""
>>>> 670           frmMain.cboEffect.AddItem strFileName
>>>> 680           strFileName = Replace(Dir$, ".png", "")
>>>> 690           strFileName = StrConv(strFileName, vbProperCase)
>>>> 700       Wend
>>>>
>>>> I want to remove the .png extension in the combobox.  The problem is,
>>>> if the .png is .PNG, it is not working.  How do i correct this?
>>>>
>>> For fear of stating the obvious, as you know all the files will end
>>> ".PNG",. why not just chop off the last 4 characters?
>>>
>> How do you do that?
>
> Where you have this...
>
>     strFileName = Replace(Dir$, ".png", "")
>
> replace it with this...
>
>     strTemp = Dir$
>     strFileName = Left$(strTemp, Len(strTemp) - 4)
>
> remembering to add the Dim statement for the strTemp variable, of course.
>
> Rick
>