Home All Groups Group Topic Archive Search About
Author
23 Feb 2009 9:01 AM
LondonLad
Hi
I store file extensions in a flat file and at run time add these extensions
to a combobox, the user can Add or Delete any extension during run time and
the combobox is saved in the flat file on shut down for next time. this works
OK

But I can get duplicates and I want to stop that, how can I search the
combobox to ensure the extension the user is wanting to Add does not already
exsist?

Can you help please explain with some detail as I am not an expert, thank you.

Ron

Author
23 Feb 2009 9:54 AM
Bill McCarthy
Hi Ron,

If you set the combo's text, it should give a >=0 index if the value is
already in it.
Alternatively you could use the CB_FINDSTRINGEXACT with SendMessage, but the
combo should already do that as above. The issue you will likely have though
is with case sensitivity. As these are all file extensions I would
standardize them all to the same case, either all upper or all lower case.



Show quoteHide quote
"LondonLad" <London***@discussions.microsoft.com> wrote in message
news:57118E9F-47A2-4F2B-A4D5-C3CA0384C613@microsoft.com...
> Hi
> I store file extensions in a flat file and at run time add these
> extensions
> to a combobox, the user can Add or Delete any extension during run time
> and
> the combobox is saved in the flat file on shut down for next time. this
> works
> OK
>
> But I can get duplicates and I want to stop that, how can I search the
> combobox to ensure the extension the user is wanting to Add does not
> already
> exsist?
>
> Can you help please explain with some detail as I am not an expert, thank
> you.
>
> Ron
Author
23 Feb 2009 10:03 AM
Dave O.
Show quote Hide quote
"LondonLad" <London***@discussions.microsoft.com> wrote in message
news:57118E9F-47A2-4F2B-A4D5-C3CA0384C613@microsoft.com...
> Hi
> I store file extensions in a flat file and at run time add these
> extensions
> to a combobox, the user can Add or Delete any extension during run time
> and
> the combobox is saved in the flat file on shut down for next time. this
> works
> OK
>
> But I can get duplicates and I want to stop that, how can I search the
> combobox to ensure the extension the user is wanting to Add does not
> already
> exsist?
>
> Can you help please explain with some detail as I am not an expert, thank
> you.
>
> Ron

There are a number of ways, the fastest is to use the SendMessage API with
the CB_FINDSTRINGEXACT or CB_FINDSTRING messages but that is a bit
complicated for a beginner, the easier way is to iterate through the list
thus: (untested code off the top of my head!)

Private sub AddToCombo(NewEntry as String)
dim n as Long
for n = 0 to SomeCombo.ListCount -1
  if SomeCombo.List(n) = NewEntry then n = 10000000
next
if n < 10000000 then someCombo.AddItem NewEntry
End Sub

Or if you have duplicates in different cases

Private sub AddToCombo(NewEntry as String)
dim n as Long
dim t as String
t = UCase$(NewEntry)
for n = 0 to SomeCombo.ListCount -1
  if UCase$(SomeCombo.List(n)) = t then n = 10000000
next
if n < 10000000 then someCombo.AddItem NewEntry
End Sub

Or you may want to force all entries to be upper case thus:

Private sub AddToCombo(NewEntry as String)
dim n as Long
dim t as String
t = UCase$(NewEntry)
for n = 0 to SomeCombo.ListCount -1
  if SomeCombo.List(n) = t then n = 10000000
next
if n < 10000000 then someCombo.AddItem t
End Sub

If you want to use the same for multiple combo boxes change the declaration
to:
Private sub AddToCombo(NewEntry as String, SomeCombo as ComboBox)
and call with the name of the relevant combo box.
If you really want it I could put together the API code but I'd want to test
that first.

Regards
Dave O.
Author
23 Feb 2009 2:31 PM
LondonLad
Thank you Bill McCarthy and DaveO
All sorted I decided to go with the API but your posts helped me understand
how the Findstrinexact worked

regards

Ron

Show quoteHide quote
"LondonLad" wrote:

> Hi
> I store file extensions in a flat file and at run time add these extensions
> to a combobox, the user can Add or Delete any extension during run time and
> the combobox is saved in the flat file on shut down for next time. this works
> OK
>
> But I can get duplicates and I want to stop that, how can I search the
> combobox to ensure the extension the user is wanting to Add does not already
> exsist?
>
> Can you help please explain with some detail as I am not an expert, thank you.
>
> Ron
Author
23 Feb 2009 4:43 PM
jpBless
Just curious...
which API did you use.. do you mind sharing?

Show quoteHide quote
"LondonLad" <London***@discussions.microsoft.com> wrote in message
news:D89871A3-2864-41BE-AB6E-E1117F91431F@microsoft.com...
> Thank you Bill McCarthy and DaveO
> All sorted I decided to go with the API but your posts helped me
> understand
> how the Findstrinexact worked
>
> regards
>
> Ron
>
> "LondonLad" wrote:
>
>> Hi
>> I store file extensions in a flat file and at run time add these
>> extensions
>> to a combobox, the user can Add or Delete any extension during run time
>> and
>> the combobox is saved in the flat file on shut down for next time. this
>> works
>> OK
>>
>> But I can get duplicates and I want to stop that, how can I search the
>> combobox to ensure the extension the user is wanting to Add does not
>> already
>> exsist?
>>
>> Can you help please explain with some detail as I am not an expert, thank
>> you.
>>
>> Ron
Author
23 Feb 2009 11:24 PM
MikeD
"jpBless" <jp3blessNoSpam@hotmail.com> wrote in message
news:eQkznXdlJHA.1168@TK2MSFTNGP05.phx.gbl...
> Just curious...
> which API did you use.. do you mind sharing?

It was already shared.  See Dave's post.

--
Mike
Author
23 Feb 2009 11:37 PM
C Kevin Provance
"jpBless" <jp3blessNoSpam@hotmail.com> wrote in message
news:eQkznXdlJHA.1168@TK2MSFTNGP05.phx.gbl...
| Just curious...
| which API did you use.. do you mind sharing?

Uh...which part about CB_FINDSTRINGEXACT and SendMessage was not clear?
Author
24 Feb 2009 3:04 AM
jpBless
Got it, Thanks Mike, Kevin

Show quoteHide quote
"C Kevin Provance" <BillMRapedMySh***@.netblows.ms> wrote in message
news:OAeYx%23glJHA.3644@TK2MSFTNGP03.phx.gbl...
>
> "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message
> news:eQkznXdlJHA.1168@TK2MSFTNGP05.phx.gbl...
> | Just curious...
> | which API did you use.. do you mind sharing?
>
> Uh...which part about CB_FINDSTRINGEXACT and SendMessage was not clear?
>
>
Author
25 Feb 2009 1:35 PM
LondonLad
Hi to all
Yes i am quite happy to share what I have done on this, not all my work as I
have had help.
Module
'Declarations

Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" _
         (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As _
         Integer, ByVal lParam As Any) As Long

'********************
'Constants for User32
Public Const CB_FINDSTRING = &H14C
Public Const CB_FINDSTRINGEXACT = &H158

Public Function GetComboBoxIndex(hWnd As Long, SearchKey As String, Optional
FindExactMatch As Boolean = True) As Long
'Function to FindExactMatch in the ComboBox
    If FindExactMatch Then
        GetComboBoxIndex = SendMessage(hWnd, CB_FINDSTRINGEXACT, -1, ByVal
SearchKey)
    Else
        GetComboBoxIndex = SendMessage(hWnd, CB_FINDSTRING, -1, ByVal
SearchKey)
    End If

End Function

sorry its a bit late with a reply been away, anyway hope it helps.

Ron

Show quoteHide quote
"jpBless" wrote:

> Just curious...
> which API did you use.. do you mind sharing?
>
> "LondonLad" <London***@discussions.microsoft.com> wrote in message
> news:D89871A3-2864-41BE-AB6E-E1117F91431F@microsoft.com...
> > Thank you Bill McCarthy and DaveO
> > All sorted I decided to go with the API but your posts helped me
> > understand
> > how the Findstrinexact worked
> >
> > regards
> >
> > Ron
> >
> > "LondonLad" wrote:
> >
> >> Hi
> >> I store file extensions in a flat file and at run time add these
> >> extensions
> >> to a combobox, the user can Add or Delete any extension during run time
> >> and
> >> the combobox is saved in the flat file on shut down for next time. this
> >> works
> >> OK
> >>
> >> But I can get duplicates and I want to stop that, how can I search the
> >> combobox to ensure the extension the user is wanting to Add does not
> >> already
> >> exsist?
> >>
> >> Can you help please explain with some detail as I am not an expert, thank
> >> you.
> >>
> >> Ron
>
>
>
Author
25 Feb 2009 2:39 PM
jpBless
Got it, thank you
Show quoteHide quote
"LondonLad" <London***@discussions.microsoft.com> wrote in message
news:4A17635E-ADD4-4D4E-811C-9DBB8C393F2A@microsoft.com...
> Hi to all
> Yes i am quite happy to share what I have done on this, not all my work as
> I
> have had help.
> Module
> 'Declarations
>
> Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" _
>         (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As _
>         Integer, ByVal lParam As Any) As Long
>
> '********************
> 'Constants for User32
> Public Const CB_FINDSTRING = &H14C
> Public Const CB_FINDSTRINGEXACT = &H158
>
> Public Function GetComboBoxIndex(hWnd As Long, SearchKey As String,
> Optional
> FindExactMatch As Boolean = True) As Long
> 'Function to FindExactMatch in the ComboBox
>    If FindExactMatch Then
>        GetComboBoxIndex = SendMessage(hWnd, CB_FINDSTRINGEXACT, -1, ByVal
> SearchKey)
>    Else
>        GetComboBoxIndex = SendMessage(hWnd, CB_FINDSTRING, -1, ByVal
> SearchKey)
>    End If
>
> End Function
>
> sorry its a bit late with a reply been away, anyway hope it helps.
>
> Ron
>
> "jpBless" wrote:
>
>> Just curious...
>> which API did you use.. do you mind sharing?
>>
>> "LondonLad" <London***@discussions.microsoft.com> wrote in message
>> news:D89871A3-2864-41BE-AB6E-E1117F91431F@microsoft.com...
>> > Thank you Bill McCarthy and DaveO
>> > All sorted I decided to go with the API but your posts helped me
>> > understand
>> > how the Findstrinexact worked
>> >
>> > regards
>> >
>> > Ron
>> >
>> > "LondonLad" wrote:
>> >
>> >> Hi
>> >> I store file extensions in a flat file and at run time add these
>> >> extensions
>> >> to a combobox, the user can Add or Delete any extension during run
>> >> time
>> >> and
>> >> the combobox is saved in the flat file on shut down for next time.
>> >> this
>> >> works
>> >> OK
>> >>
>> >> But I can get duplicates and I want to stop that, how can I search the
>> >> combobox to ensure the extension the user is wanting to Add does not
>> >> already
>> >> exsist?
>> >>
>> >> Can you help please explain with some detail as I am not an expert,
>> >> thank
>> >> you.
>> >>
>> >> Ron
>>
>>
>>