|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ListBox colorWhat would be the best way to color different lines of a ListBox based on
values? I've tried: If RS!Process = "value1" Then lstUtility.ForeColor = vbBlue ElseIf RS!Process = "value2" Then lstUtility.ForeColor = vbRed Else: lstUtility.ForeColor = vbCyan ' 15 other types End If lstUtility.AddItem RS!Process & Chr$(9) & " " & RS!Success & Chr$(9) & RS!LogDate RS.MoveNext Loop RS.Close But the List Box ends up with all lines the same color. You don't seem to be using VB. ! is not a "legal"
character in a variable. If you're actually somehow using VB then the answer is that you need to subclass the listbox. If you're using VB.Net then you've wandered into the wrong group. For VB.Net you want a group with "dotnet" in the name. Try these: microsoft.public.dotnet.general microsoft.public.dotnet.languages.vb Show quoteHide quote > What would be the best way to color different lines of a ListBox based on > values? > > I've tried: > If RS!Process = "value1" Then > lstUtility.ForeColor = vbBlue > ElseIf RS!Process = "value2" Then > lstUtility.ForeColor = vbRed > Else: lstUtility.ForeColor = vbCyan ' 15 other types > End If > lstUtility.AddItem RS!Process & Chr$(9) & " " & RS!Success & Chr$(9) & > RS!LogDate > RS.MoveNext > Loop > RS.Close > > But the List Box ends up with all lines the same color. > > "mayayana" <mayayaX***@rcXXn.com> wrote in message Wrong. The ! is an indexer identifier.news:%230sUAQ9lJHA.2460@TK2MSFTNGP06.phx.gbl... > > You don't seem to be using VB. ! is not a "legal" > character in a variable. "mayayana" <mayayaX***@rcXXn.com> wrote in message Correct, butnews:%230sUAQ9lJHA.2460@TK2MSFTNGP06.phx.gbl... > You don't seem to be using VB. ! is not a "legal" > character in a variable. >> If RS!Process = "value1" Then RS!Process is not a variable; it's the equivalent of RS("Process").Value. Did your brain just misfire or are you actually not familiar with the (ancient) bang syntax? > RS!Process is not a variable; it's the equivalent of RS("Process").Value. I guess that's from before my time. I've never> Did your brain just misfire or are you actually not familiar with the > (ancient) bang syntax? > run across it. And I don't find it in either "VB and VBA in a Nutshell" or in MSDN. Is it some kind of DOS-era thing that's carried over? Is there a list of those somewhere?
Show quote
Hide quote
"mayayana" <mayayaX***@rcXXn.com> escribió en el mensaje de noticias http://support.microsoft.com/kb/129287/en-usnews:ux6FKgCmJHA.2064@TK2MSFTNGP05.phx.gbl... > >> RS!Process is not a variable; it's the equivalent of RS("Process").Value. >> Did your brain just misfire or are you actually not familiar with the >> (ancient) bang syntax? >> > > I guess that's from before my time. I've never > run across it. And I don't find it in either "VB and VBA > in a Nutshell" or in MSDN. Is it some kind of DOS-era > thing that's carried over? Is there a list of those > somewhere? > -- Regards - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ( ! ) http://groups.google.com/group/microsoft.public.vb.general.discussion ( i ) http://www.microsoft.com/communities/conduct/default.mspx - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "mayayana" <mayayaX***@rcXXn.com> wrote in message You're not missing anything. I despise the syntax myself. I learned it in my news:ux6FKgCmJHA.2064@TK2MSFTNGP05.phx.gbl... >> RS!Process is not a variable; it's the equivalent of RS("Process").Value. >> Did your brain just misfire or are you actually not familiar with the >> (ancient) bang syntax? >> > > I guess that's from before my time. I've never > run across it. Access days. "mayayana" <mayayaX***@rcXXn.com> escribió en el mensaje de noticias Actually it is a valid syntax to access a Collection!Member by its key news:%230sUAQ9lJHA.2460@TK2MSFTNGP06.phx.gbl... > > You don't seem to be using VB. ! is not a "legal" > character in a variable. name. For instance: '****************** Dim col As Collection: Set col = New Collection col.Add "One", "1" col.Add 2, "Second" col.Add Me, "oneForm" col.Add col, "itself" Debug.Print col![1] Debug.Print col!OneForm.Controls!Text1.Text ' "Controls collection" as well col.Remove col!Second ' Removes the index 2 (Variant/Integer member) Debug.Print col!Itself.Count '****************** -- Regards - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ( ! ) http://groups.google.com/group/microsoft.public.vb.general.discussion ( i ) http://www.microsoft.com/communities/conduct/default.mspx - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Thanks. I'd never heard of that. Nor have I ever seen
the square brackets. It's rather confusing. All of these work: Debug.Print col![1] Debug.Print col.Item(1) Debug.Print col.Item("1") Yet this doesn't: Debug.Print col!(1) Show quoteHide quote > Actually it is a valid syntax to access a Collection!Member by its key http://groups.google.com/group/microsoft.public.vb.general.discussion> name. > > For instance: > > '****************** > Dim col As Collection: Set col = New Collection > > col.Add "One", "1" > col.Add 2, "Second" > col.Add Me, "oneForm" > col.Add col, "itself" > > Debug.Print col![1] > Debug.Print col!OneForm.Controls!Text1.Text ' "Controls collection" as well > col.Remove col!Second ' Removes the index 2 (Variant/Integer member) > Debug.Print col!Itself.Count > '****************** > > > > -- > Regards > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > ( ! ) Show quoteHide quote > ( i ) http://www.microsoft.com/communities/conduct/default.mspx > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > >
Show quote
Hide quote
"mayayana" <mayayaX***@rcXXn.com> wrote in message The brackets are mainly for field names that have spaces, so you could donews:ef2HD4CmJHA.504@TK2MSFTNGP06.phx.gbl... > Thanks. I'd never heard of that. Nor have I ever seen > the square brackets. It's rather confusing. > All of these work: > > Debug.Print col![1] > Debug.Print col.Item(1) > Debug.Print col.Item("1") > > Yet this doesn't: > > Debug.Print col!(1) col![Some Date] and apparently they work as an indexer as well. I, too, never knew that.
Show quote
Hide quote
"Jeff Johnson" <i.get@enough.spam> wrote in message The best use is to create hidden enum members...news:Okf00bDmJHA.1288@TK2MSFTNGP02.phx.gbl... > "mayayana" <mayayaX***@rcXXn.com> wrote in message > news:ef2HD4CmJHA.504@TK2MSFTNGP06.phx.gbl... > >> Thanks. I'd never heard of that. Nor have I ever seen >> the square brackets. It's rather confusing. >> All of these work: >> >> Debug.Print col![1] >> Debug.Print col.Item(1) >> Debug.Print col.Item("1") >> >> Yet this doesn't: >> >> Debug.Print col!(1) > > The brackets are mainly for field names that have spaces, so you could do > > col![Some Date] > > and apparently they work as an indexer as well. I, too, never knew that. public enum myvalues [_mintype]=1 type1=1 type2=2 type3=3 [_maxtype]=3 end enum The underscore makes the enum hidden and the brackets make VB accept the underscore. Now you can code limit tests and just update the enum when necessary: if thevalue>=[_mintype] and thevalue<=[_maxtype] then
Show quote
Hide quote
"Bob Butler" <noway@nospam.ever> wrote in message For reference, I was only addressing their use with the bang syntax.news:ORSUPmDmJHA.1172@TK2MSFTNGP04.phx.gbl... >>> Thanks. I'd never heard of that. Nor have I ever seen >>> the square brackets. It's rather confusing. >>> All of these work: >>> >>> Debug.Print col![1] >>> Debug.Print col.Item(1) >>> Debug.Print col.Item("1") >>> >>> Yet this doesn't: >>> >>> Debug.Print col!(1) >> >> The brackets are mainly for field names that have spaces, so you could do >> >> col![Some Date] >> >> and apparently they work as an indexer as well. I, too, never knew that. > > The best use is to create hidden enum members... Hi,
mayayana schrieb: > Thanks. I'd never heard of that. Nor have I ever seen It worked because you had the luck that the entry of value "One" was > the square brackets. It's rather confusing. > All of these work: > > Debug.Print col![1] > Debug.Print col.Item(1) > Debug.Print col.Item("1") > added as first entry (at index 1) into the collection. Col.Item("1") and Col.Item[1] are equivalent and adress under all circumstances the same item, Col.Item(1) is not equivalent because it adresses the item having the numerical index 1. Items in a collection are adressed either by a key string or by a numerical index. Item is a property of the Collection class with one variant parameter named "IndexOrKey" that adresses the item. If the variant parameter's type is of type String, the parameters value is used to adress by key, if it is a numerical type it is used to adress by index. After Set col = New Collection col.Add "First", "2" col.Add "Second", "1" col.Add "Third", "KeyOfThird" you have a collection with three items: the item at index 1 has the value "First" and the key "2", the item at index 2 has the value "Second" and the key "1", the item at index 3 has the value "Third" and the key "KeyOfThird". So col.Item("1") delivers "Second", col.item(1) delivers "First". col.item("2") delivers "First", col.item(2) delivers "Second". col.item("KeyOfThird") and col.item(3) both deliver "Third". When using the shortcut col!<Key> for keys, wether you have to use [] or not depends on the key characters. If the key has characters that are illegal if the key string would be used as an identifier name (eg as variable name), the [] have to be used. So because 1 is not a legal variable name, one has to use col![1]. However KeyOfThird is a legal identifier name and col.KeyOfThird is ok. Show quoteHide quote > Yet this doesn't: > > Debug.Print col!(1) > > >> Actually it is a valid syntax to access a Collection!Member by its key >> name. >> >> For instance: >> >> '****************** >> Dim col As Collection: Set col = New Collection >> >> col.Add "One", "1" >> col.Add 2, "Second" >> col.Add Me, "oneForm" >> col.Add col, "itself" >> >> Debug.Print col![1] >> Debug.Print col!OneForm.Controls!Text1.Text ' "Controls collection" as > well >> col.Remove col!Second ' Removes the index 2 (Variant/Integer member) >> Debug.Print col!Itself.Count >> '****************** >> >> >> >> -- >> Regards >> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >> ( ! ) > http://groups.google.com/group/microsoft.public.vb.general.discussion >> ( i ) http://www.microsoft.com/communities/conduct/default.mspx >> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >> >> > >
Show quote
Hide quote
"mayayana" <mayayaX***@rcXXn.com> wrote in message If I don't use the "!" symbol when referring to an item of a recordset, I news:%230sUAQ9lJHA.2460@TK2MSFTNGP06.phx.gbl... > > You don't seem to be using VB. ! is not a "legal" > character in a variable. If you're actually somehow > using VB then the answer is that you need to > subclass the listbox. If you're using VB.Net then you've > wandered into the wrong group. For VB.Net you want > a group with "dotnet" in the name. Try these: > > microsoft.public.dotnet.general > microsoft.public.dotnet.languages.vb > > >> What would be the best way to color different lines of a ListBox based on >> values? >> >> I've tried: >> If RS!Process = "value1" Then >> lstUtility.ForeColor = vbBlue >> ElseIf RS!Process = "value2" Then >> lstUtility.ForeColor = vbRed >> Else: lstUtility.ForeColor = vbCyan ' 15 other types >> End If >> lstUtility.AddItem RS!Process & Chr$(9) & " " & RS!Success & Chr$(9) >> & >> RS!LogDate >> RS.MoveNext >> Loop >> RS.Close >> >> But the List Box ends up with all lines the same color. >> Mayaya receive a "Method or data member not found" error in VB6. "Edward" <nospam@mail.com> wrote in message Post the syntax you are trying...news:ECzpl.2441$l71.873@newsfe23.iad... > If I don't use the "!" symbol when referring to an item of a recordset, I > receive a "Method or data member not found" error in VB6.
Show quote
Hide quote
"Edward" <nospam@mail.com> skrev i meddelandet Isn't that equal to If RS.Fields("Process").Value = "value1". It's just more news:ECzpl.2441$l71.873@newsfe23.iad... > > "mayayana" <mayayaX***@rcXXn.com> wrote in message > news:%230sUAQ9lJHA.2460@TK2MSFTNGP06.phx.gbl... >> >> You don't seem to be using VB. ! is not a "legal" >> character in a variable. If you're actually somehow >> using VB then the answer is that you need to >> subclass the listbox. If you're using VB.Net then you've >> wandered into the wrong group. For VB.Net you want >> a group with "dotnet" in the name. Try these: >> >> microsoft.public.dotnet.general >> microsoft.public.dotnet.languages.vb >> >> >>> What would be the best way to color different lines of a ListBox based >>> on >>> values? >>> >>> I've tried: >>> If RS!Process = "value1" Then >>> lstUtility.ForeColor = vbBlue >>> ElseIf RS!Process = "value2" Then >>> lstUtility.ForeColor = vbRed >>> Else: lstUtility.ForeColor = vbCyan ' 15 other types >>> End If >>> lstUtility.AddItem RS!Process & Chr$(9) & " " & RS!Success & Chr$(9) >>> & >>> RS!LogDate >>> RS.MoveNext >>> Loop >>> RS.Close >>> >>> But the List Box ends up with all lines the same color. >>> > Mayaya > > If I don't use the "!" symbol when referring to an item of a recordset, I > receive a "Method or data member not found" error in VB6. > > obscure what you mean using '!'. /Henning Edward wrote:
Show quoteHide quote > What would be the best way to color different lines of a ListBox It's complicated.> based on values? > > I've tried: > If RS!Process = "value1" Then > lstUtility.ForeColor = vbBlue > ElseIf RS!Process = "value2" Then > lstUtility.ForeColor = vbRed > Else: lstUtility.ForeColor = vbCyan ' 15 other types > End If > lstUtility.AddItem RS!Process & Chr$(9) & " " & RS!Success & > Chr$(9) & RS!LogDate > RS.MoveNext > Loop > RS.Close > > But the List Box ends up with all lines the same color. Best to find an example of an "owner-drawn listbox" that someone's been kind enough to provide. Maybe you could get help modifying one of these examples: http://www.thescarms.com/vbasic/OwnerDrawn.aspx http://www.vbaccelerator.com/codelib/odcbolst/article.htm HTH For coloring a Listbox see here:
www.jsware.net/jsware/vbcode.php5#lbox You can't do it without subclassing. "mayayana" <mayayaX***@rcXXn.com> wrote in message This example is exactly what I was searching for, different font colors for news:uuRYIhCmJHA.3760@TK2MSFTNGP03.phx.gbl... > For coloring a Listbox see here: > > www.jsware.net/jsware/vbcode.php5#lbox > > You can't do it without subclassing. > Wonderful! different ListBox line items. www.jsware.net/jsware/vbcode.php5#lbox Thanks
Show quote
Hide quote
"Edward" <nospam@mail.com> escribió en el mensaje de noticias If you are using already a reference to MsComCtl.ocx in your project, news:Whopl.16362$Si4.10962@newsfe22.iad... > What would be the best way to color different lines of a ListBox based on > values? > > I've tried: > If RS!Process = "value1" Then > lstUtility.ForeColor = vbBlue > ElseIf RS!Process = "value2" Then > lstUtility.ForeColor = vbRed > Else: lstUtility.ForeColor = vbCyan ' 15 other types > End If > lstUtility.AddItem RS!Process & Chr$(9) & " " & RS!Success & Chr$(9) & > RS!LogDate > RS.MoveNext > Loop > RS.Close > > But the List Box ends up with all lines the same color. you can avoid the subclassing using a TreeView, for example: '************** Dim i As Long With someTreeView .FullRowSelect = True .LabelEdit = tvwManual For i = 1 To 20 With .Nodes.Add(, , , "TV Item " & CStr(i)) .BackColor = QBColor(Int(Rnd * 8)) .ForeColor = QBColor(Int(Rnd * 8)) End With Next End With '************** -- Regards - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ( ! ) http://groups.google.com/group/microsoft.public.vb.general.discussion ( i ) http://www.microsoft.com/communities/conduct/default.mspx - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Vinchenzo vinç" <Vinç@newsgroup.nospam> wrote in message List boxes and tree views are very different controls. I wouldn't news:OkB7VwCmJHA.5656@TK2MSFTNGP02.phx.gbl... > "Edward" <nospam@mail.com> escribió en el mensaje de noticias > news:Whopl.16362$Si4.10962@newsfe22.iad... >> What would be the best way to color different lines of a ListBox based on >> values? > If you are using already a reference to MsComCtl.ocx in your project, > you can avoid the subclassing using a TreeView, for example: arbitrarily swap one for the other.
Printing PictureBox Contents
Stupid Format$ Question OT: Win 3.1 IE menu extension Should Reg-free COM still utilise an installation procedure? Office 2003 installer pops up when loading a project FYI: MS UK VB6 Usage survey/poll - update Reading Stack from VB6 Gradient Windows Update KB960715 blocks MSFLXGRD.OCX!!!!! Any solution ? |
|||||||||||||||||||||||