Board index » Visual Studio » Problem populating a combobox if cases differ

Problem populating a combobox if cases differ

Visual Studio200
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.


-
 

Re:Problem populating a combobox if cases differ

Saucer Man wrote:

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 www.teranews.com">www.teranews.com



-

Re:Problem populating a combobox if cases differ

"Saucer Man" <saucerman@nospam.net>wrote in message

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



VB doesn't need line numbers.



Michael





-

Re:Problem populating a combobox if cases differ

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.





"Paul Lambert" <paul.lambert@autoledgers.com.au>wrote in message

Quote
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 www.teranews.com">www.teranews.com







-

Re:Problem populating a combobox if cases differ

Saucer Man wrote:

Quote
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 www.teranews.com">www.teranews.com



-

Re:Problem populating a combobox if cases differ



"Saucer Man" <saucerman@nospam.net>wrote in message news:IjpEh.41719$19.33892@bignews3.bellsouth.net...

Quote
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





-

Re:Problem populating a combobox if cases differ

I know. I use line numbers for error trapping.



--



Thanks.





"Michael C" <nospam@nospam.com>wrote in message

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







-

Re:Problem populating a combobox if cases differ

I did. I replaced both instances but it doesn't work.



--



Thanks.





"Paul Lambert" <paul.lambert@autoledgers.com.au>wrote in message

Quote
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 www.teranews.com">www.teranews.com







-

Re:Problem populating a combobox if cases differ

Larry, does this function replace any case combination of "png" with ""?

That's what I am trying to accomplish.



--



Thanks.





"Larry Serflaten" <serflaten@usinternet.com>wrote in message

Quote


"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









-

Re:Problem populating a combobox if cases differ

"Saucer Man" <saucerman@nospam.net>wrote in message

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)



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

the filename.



Quote
660 While strFileName <>""

670 frmMain.cboEffect.AddItem strFileName

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

690 strFileName = StrConv(strFileName, vbProperCase)



invert those two as well



Quote
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..."



-

Re:Problem populating a combobox if cases differ

Quote
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





-

Re:Problem populating a combobox if cases differ



"Saucer Man" <saucerman@nospam.net>wrote

Quote
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





-

Re:Problem populating a combobox if cases differ

"Saucer Man" <saucerman@nospam.net>wrote in message

Quote
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





-

Re:Problem populating a combobox if cases differ

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

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?



--



Thanks.











-

Re:Problem populating a combobox if cases differ

I'm using an add-on also.



--



Thanks.





"Michael C" <nospam@nospam.com>wrote in message

Quote
"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







-

Re:Problem populating a combobox if cases differ

How do you do that?



--



Thanks.





"Dave O." <nobody@nowhere.com>wrote in message

Quote
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.

>

>

>









-

Re:Problem populating a combobox if cases differ

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

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)



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..."







-

Re:Problem populating a combobox if cases differ

Could the . in there be causing the problem with the text compare?



--



Thanks.





"Saucer Man" <saucerman@nospam.net>wrote in message

Quote
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..."

>









-

Re:Problem populating a combobox if cases differ

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





-

Re:Problem populating a combobox if cases differ

Ok...it wasn't working because I need 3 commas before the vbTextCompare. I

only had two. Now it is working. Thanks again.



--



Thanks.





"Saucer Man" <saucerman@nospam.net>wrote in message

Quote
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..."

>>

>

>









-

Re:Problem populating a combobox if cases differ

Thanks for all the help everyone!!!



--



Thanks.





"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net>wrote in

message news:%23w7KcwcWHHA.5068@TK2MSFTNGP03.phx.gbl...

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







-

Re:Problem populating a combobox if cases differ

"Saucer Man" <saucerman@nospam.net>wrote in message

Quote
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..."



-

Re:Problem populating a combobox if cases differ

"Saucer Man" <saucerman@nospam.net>wrote in message

Quote
I'm using an add-on also.



Why does it increment by 10 then?



Michael





-

Re:Problem populating a combobox if cases differ

Probably because thats what the add-on is set for by default. I didn't

change it.



--



Thanks.





"Michael C" <nospam@nospam.com>wrote in message

Quote
"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







-