I have 8 list boxes and i need to compare values stored in them, i need to find the first non-numerical character in each line in each listbox and then compare between listboxes does anyone have any ides how to do this?
cheers
Black box
16 12046
I have 8 list boxes and i need to compare values stored in them, i need to find the first non-numerical character in each line in each listbox and then compare between listboxes does anyone have any ides how to do this?
cheers
Black box
hi
dim lstbLine(7)
'find first non-numerical chr is line of listbox and remember
'assumed listboxes are put into an array
'lstb is counter for listboxes
'ndx is counter for non-numerical line
for lstb=0 to 7
for ndx=0 to ListBox(lstb).ListCount-1
if asc(left(ListBox(lstb).List(ndx),1)) > 64 then
lstbLine(lstb)=ndx
exit for
end if
next ndx
next lstb
'compare different listbox lines
for lstb=0 to 6
for lstb1=lstb+1 to 7
if lstbLine(lstb)=lstbLine(lstb1) then
msgbox "Listbox " & lstb & " has same value as Listbox " & lstb1
end if
next lstb1
next lstb
for lstb=0 to 7
for ndx=0 to ListBox(lstb).ListCount-1
if asc(left(ListBox(lstb).List(ndx),1)) > 64 then
lstbLine(lstb)=ndx
exit for
end if
next ndx
next lstb
This doesn't actually match the spec. The request was to find the "first non-numeric character in each line". I believe this code will find the first line which starts with a non-numneric. You might actually need to use a third nested loop to run through each character in ListBox(lstb).List(ndx), and do something with the character you find, then Exit For.
Just in case you're interested, the Left() function in the above code is unnecessary; the ASC() function will only return the ASCII value of the first character anyway.
P.S. Sorry if I sounded somewhat brusque, just very busy at work right now.
Ok, I've had time to go over this one a little. Here's the code I've come up with - I've just expanded a little on albertw's code. Note that while this was written in VB6, it has not been tested. -
' Find first non-numerical chr in each line of listbox.
-
' Assumptions:
-
' 1) listboxes are in an array ListBox(0 to 7)
-
' 2) Maximum entries in any listbox: 100
-
-
' lstb is counter for listboxes
-
' ndx is counter for line within listbox
-
' char is count for charater within line
-
-
' Array to hold first non-numeric char for each line in each
-
' listbox...
-
Dim FirstChar(0 To 7, 1 To 100) As String
-
-
Dim lstb As Long, ndx As Long, chnum As Long
-
Dim Char As String
-
Dim MaxLine As Long
-
-
-
For lstb = 0 To 7
-
With ListBox(lstb)
-
If .ListCount > MaxLines Then
-
MaxLines = .ListCount
-
End If
-
For ndx = 0 To .ListCount - 1
-
For chnum = 1 To Len(.List(ndx))
-
Char = Mid$(.List(ndx), Char, 1)
-
Select Case Char
-
Case "0" To "9"
-
' Ignore
-
Case Else
-
FirstChar(lstb, ndx) = Char
-
Exit For
-
End Select
-
Next
-
End With
-
Next
-
Next
-
In theory, this should leave you with a two-dimensional array (listboxnum, linenum) giving the character which was found on each line of each listbox. Variable MaxLines should contain the number of lines in the longest list.
I don't know exactly what sort of comparison you want to do between them, but albertw's routine should give you a good base to work from.
Ok, I've had time to go over this one a little. Here's the code I've come up with - I've just expanded a little on albertw's code. Note that while this was written in VB6, it has not been tested. -
' Find first non-numerical chr in each line of listbox.
-
' Assumptions:
-
' 1) listboxes are in an array ListBox(0 to 7)
-
' 2) Maximum entries in any listbox: 100
-
-
' lstb is counter for listboxes
-
' ndx is counter for line within listbox
-
' char is count for charater within line
-
-
' Array to hold first non-numeric char for each line in each
-
' listbox...
-
Dim FirstChar(0 To 7, 1 To 100) As String
-
-
Dim lstb As Long, ndx As Long, chnum As Long
-
Dim Char As String
-
Dim MaxLine As Long
-
-
-
For lstb = 0 To 7
-
With ListBox(lstb)
-
If .ListCount > MaxLines Then
-
MaxLines = .ListCount
-
End If
-
For ndx = 0 To .ListCount - 1
-
For chnum = 1 To Len(.List(ndx))
-
Char = Mid$(.List(ndx), Char, 1)
-
Select Case Char
-
Case "0" To "9"
-
' Ignore
-
Case Else
-
FirstChar(lstb, ndx) = Char
-
Exit For
-
End Select
-
Next
-
End With
-
Next
-
Next
-
In theory, this should leave you with a two-dimensional array (listboxnum, linenum) giving the character which was found on each line of each listbox. Variable MaxLines should contain the number of lines in the longest list.
I don't know exactly what sort of comparison you want to do between them, but albertw's routine should give you a good base to work from.
hi
agree to create a 2dim array
dim lb(num,lin)
for a=0 to 7
for b=1 to lstbox(a).listcount
for i=1 to len(lstbox(a).list(b))
c=mid(lstbox(a).list(b),i,1)
n=instr(1,"0123456789",c)
if n=0 then
lb(a,b)=c
exit for
endif
next i
next b
next a
then compare diff lb's
hi
agree to create a 2dim array - dim lb(num,lin)
-
-
for a=0 to 7
-
for b=1 to lstbox(a).listcount
-
for i=1 to len(lstbox(a).list(b))
-
c=mid(lstbox(a).list(b),i,1)
-
n=instr(1,"0123456789",c)
-
if n=0 then
-
lb(a,b)=c
-
exit for
-
endif
-
next i
-
next b
-
next a
then compare diff lb's
I prefer my version :)
Seriously, you forgot about the zero-base on the "b" loop. You'll get a bad-index error (I forget the specifics, been working in other languages too much).
I prefer my version :)
Seriously, you forgot about the zero-base on the "b" loop. You'll get a bad-index error (I forget the specifics, been working in other languages too much).
yes yr right k
b should start at 0
hate to point it out that my VB doesn't like either of your responses, though they look as if they work in spectacular form it likes neither lstbox(a) (or ListBox(a)) or ListBox(lstb) (or lstbox(lstb))
hate to point it out that my VB doesn't like either of your responses, though they look as if they work in spectacular form it likes neither lstbox(a) (or ListBox(a)) or ListBox(lstb) (or lstbox(lstb))
Well, you have to keep in mind that we are making assumptions and you need to adjust for them. For instance, we have assumed that your listboxes are in an array. This is certainly the most convenient way to deal with them, as you can use a loop to run through them, as albertw and I have been demonstrating.
If they are not an array, then the coding gets rather awkward, as you need to explicitly reference each one. At the simplest level, this may mean writing the same code 8 times, though there are ways you might get around it.
Also, even if they are a control array, you have to use the right name. We just assumed a name of lstbx, or ListBox, or whatever. You need to use your name here, not ours.
If you're not sure, making a control array involves giving controls (of the same type) the same name, and a value in the Index property. If you simply copy a control and paste it back into the same form, it will ask whether you want to make it an array, and if you say yes, will give the original one an Index value of 0. The pasted one will have Index = 1, and so on.
Well, you have to keep in mind that we are making assumptions and you need to adjust for them. For instance, we have assumed that your listboxes are in an array. This is certainly the most convenient way to deal with them, as you can use a loop to run through them, as albertw and I have been demonstrating.
If they are not an array, then the coding gets rather awkward, as you need to explicitly reference each one. At the simplest level, this may mean writing the same code 8 times, though there are ways you might get around it.
Also, even if they are a control array, you have to use the right name. We just assumed a name of lstbx, or ListBox, or whatever. You need to use your name here, not ours.
If you're not sure, making a control array involves giving controls (of the same type) the same name, and a value in the Index property. If you simply copy a control and paste it back into the same form, it will ask whether you want to make it an array, and if you say yes, will give the original one an Index value of 0. The pasted one will have Index = 1, and so on.
sorry if i sounded a little ungrateful on my last post i was a little busy, i think the problem is a misunderstanding between VB6 and VBA and have managed to straighten most of it out there might be a few problems left firstly in the following: -
For Each Thing In UserForm1.Controls ' thing is a control
-
If TypeName(Thing) = "ListBox" Then
-
For lstb = 1 To 8
-
With Thing
-
For ndx = 0 To .ListCount - 1
-
For chnum = 1 To Len(.List(ndx))
-
Char = Mid$(.List(ndx), Char, 1)
-
Select Case Char
-
Case "0" To "9"
-
' Ignore
-
Case Else
-
FirstChar(lstb, ndx) = Char
-
Exit For
-
End Select
-
Next
-
Next
-
End With
-
Next
-
End If
-
Next Thing
-
when it reaches "For ndx = 0 To .ListCount - 1" it skips straight down to "end with" why would it do this? and how can i stop it?
sorry if i sounded a little ungrateful on my last post i was a little busy, i think the problem is a misunderstanding between VB6 and VBA and have managed to straighten most of it out there might be a few problems left firstly in the following: -
For Each Thing In UserForm1.Controls ' thing is a control
-
If TypeName(Thing) = "ListBox" Then
-
For lstb = 1 To 8
-
With Thing
-
For ndx = 0 To .ListCount - 1
-
For chnum = 1 To Len(.List(ndx))
-
Char = Mid$(.List(ndx), Char, 1)
-
Select Case Char
-
Case "0" To "9"
-
' Ignore
-
Case Else
-
FirstChar(lstb, ndx) = Char
-
Exit For
-
End Select
-
Next
-
Next
-
End With
-
Next
-
End If
-
Next Thing
-
when it reaches "For ndx = 0 To .ListCount - 1" it skips straight down to "end with" why would it do this? and how can i stop it?
if there is nothing in the "thing" list, the loop will stop directly
if there is nothing in the "thing" list, the loop will stop directly
the "Thing list" isn't the problem it's the "For ndx = 0 To .ListCount - 1" line. When stepping through the code, it'll run the "with Thing" line, highlight the "For ndx = 0 To .ListCount - 1" and skip straight to "end with" on the next step. no error message it just runs through that same process for each lstb value.
the "Thing list" isn't the problem it's the "For ndx = 0 To .ListCount - 1" line. When stepping through the code, it'll run the "with Thing" line, highlight the "For ndx = 0 To .ListCount - 1" and skip straight to "end with" on the next step. no error message it just runs through that same process for each lstb value.
hi
just what i meant
if the thing.listcount=0 then the procedure will be skipped
the "Thing list" isn't the problem it's the "For ndx = 0 To .ListCount - 1" line. When stepping through the code, it'll run the "with Thing" line, highlight the "For ndx = 0 To .ListCount - 1" and skip straight to "end with" on the next step. no error message it just runs through that same process for each lstb value.
When it gets to the For statement as mentioned here, could you hover over the .ListCount and see what value it shows? (If hovering doesn't work, just select it and do a quick watch.)
hi
just what i meant
if the thing.listcount=0 then the procedure will be skipped
Yes, as albertw points out, if the listcount is 0 the For statement will be set to loop from 0 to -1. In which case, we will never enter the loop.
Yes, as albertw points out, if the listcount is 0 the For statement will be set to loop from 0 to -1. In which case, we will never enter the loop.
my mistake i'd left in the userform1.show above the code, then closed it to run the code underneath and it'd reset the .listcount to 0. works now.
cheers
black box
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: amber |
last post by:
Hello.
Can someone tell me what I may be doing wrong here?
I'm using the code (lboxRP is a listbox):
Dim newRPindex As Integer
newRPindex = Me.lboxRP.FindString(RP)...
|
by: Paul T. Rong |
last post by:
I have a listbox (of product names) control on my form. I want to pass the
selected item (a product name) to a subform, and the product unitprice
should apear automatically next to the product name...
|
by: Melissa Cowan |
last post by:
I am using Access 2000. I have the Developer's handbook and got the
code for the mulit select listbox from there. It sends the selected
value to another listbox, lstselected. What I need to do is...
|
by: Oddball |
last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler.
What I want to draw as the item is another control. I have created a user control that I
would like to list in...
|
by: Chris Leuty |
last post by:
I am populating a multiselect Listbox from a dataset, with the content of
the listbox filled by one table, and the selections determined from another
table. So far, I have been keeping the dataset...
| |
by: George |
last post by:
Sub ExcelToListBox()
Dim xRange As Object
Dim ary
Dim xValue As String
xRange = oXL.Range("A1:A9") 'has letters A-H
ary = xRange.value
xValue = ary(3, 1) 'xValue = C...
|
by: tangokilo |
last post by:
Hello and thanks for your help,
I have the following Listbox created in VisualStudio 2003 designer, desiring
to select multiple entries from that list:
-------------------------------...
|
by: David J |
last post by:
Hi,
I am strugling with the propertygrid and a listbox. I am using the
universaldropdowneditor from the codeproject (code below). However I am
populating the listbox via a datasource. The problem...
|
by: Ali Chambers |
last post by:
Hi,
I have created a listbox called "dtlist1" on my VB.NET form. I call a
procedure as follows:
Private Sub openfile(flname As String)
dtlist1.Items.Clear()
etc..
|
by: Sunray |
last post by:
I have a form called the sales form and i have 2 sets of listboxes
So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |