|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Search a ComboboxHi
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 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
Show quote
Hide quote
"LondonLad" <London***@discussions.microsoft.com> wrote in message There are a number of ways, the fastest is to use the SendMessage API with 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 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. 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 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 "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message It was already shared. See Dave's post.news:eQkznXdlJHA.1168@TK2MSFTNGP05.phx.gbl... > Just curious... > which API did you use.. do you mind sharing? -- Mike "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message Uh...which part about CB_FINDSTRINGEXACT and SendMessage was not clear?news:eQkznXdlJHA.1168@TK2MSFTNGP05.phx.gbl... | Just curious... | which API did you use.. do you mind sharing? 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? > > 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 > > > 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 >> >> >>
optional args to a class.Init method
Save Picture Q Anyway to move Image control at runtime Dim WithEvents * As HTMLDocument with an Iframe - access denied!? Recommended IDE for the PocketPC Automatic determine .Rows in MSHFLexgrid Unsigned C long to signed VB5 Long query. Cannot pass a control array ? Remove empty elements from end of array convert Unicode string |
|||||||||||||||||||||||