• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 49
  • Last Modified:

select case loop for vb

How do I design a solution to determine how many words in the listbox fall within different ranges as defined below. the steps are,
(1) Loop through each word in the listbox
(2) Using a select case structure in the loop count how many words have lengths in the following ranges:  1-5, 6-10, over 10
(3) Output how many letters fall within each range.
0
bob saget
Asked:
bob saget
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
This would loop through your listbox and use the select case:

For Each itm In YourListBox.Items
  Select Case itm.Length
    Case <= 5
      '/ do something here
    Case <= 10
      '/ do something here
    Case Else
      '/ do something here
  End Select
Next

I'm not sure what you mean by "output how many letters fall in each range". Do you mean you want a count of how many words in the listbox fall into those ranges? If so:
Dim countFive as Integer
Dim countTen as Integer
dim countElse as Integer

For Each itm In YourListBox.Items
  Select Case itm.Length
    Case <= 5
      countFive += 1
    Case <= 10
      countTen += 1
    Case Else
      countElse += 1
  End Select
Next

Msgbox("Five or Less: " & countFive.ToString & ", Ten or Less: " & countTen.ToString & ", Over 10: " & countElse.ToString)
0
 
bob sagetAuthor Commented:
thank you so much, that case statement helped out a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now