Results 1 to 6 of 6

Thread: Simple Output Help Needed

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    4

    Simple Output Help Needed

    This is my first VB class and I've always struggled with output, and I've been messing around and I can't get the right stuff to display. The code processes a sentence a user enters into an input box to display how many words, conjunctions, prepositions, articles, and other words there are.

    The output list box is supposed to display something like this:

    Sentence: Hello world (user entered example obv)
    Number of words: 2
    Conjunctions: ....... and so forth with "articles" and "other of words"

    Code:
    'Declaration Section
    
    Dim input As String = ""
    
    While input.Length < 1
    
    input = InputBox("Enter Sentence to process", "Loop Fun")
    
    End While
    
    Dim words() As String = input.Split(" ")
    
    Dim wordcount As Integer = words.Length
    
    Dim conjunctions As Integer
    
    Dim prepositions As Integer
    
    Dim articles As Integer
    
    Dim otherwords As Integer
    
    Dim fmtstr As String = "{0,-16} {1,-1}"
    
    'Processing
    
    lstOutput.Items.Clear()
    
    Dim count As Integer
    
    While count < words.Length - 1
    
    count += 1
    
    Select Case words(count)
    
    Case "and"
    
    conjunctions += 1
    
    Case "but"
    
    conjunctions += 1
    
    Case "or"
    
    conjunctions += 1
    
    Case "to"
    
    prepositions += 1
    
    Case "over"
    
    prepositions += 1
    
    Case "above"
    
    prepositions += 1
    
    Case "under"
    
    prepositions += 1
    
    Case "down"
    
    prepositions += 1
    
    Case "up"
    
    prepositions += 1
    
    Case "a"
    
    articles += 1
    
    Case "an"
    
    articles += 1
    
    Case "the"
    
    articles += 1
    
    End Select
    
    End While
    
    otherwords = wordcount - conjunctions - prepositions - articles
    
    'Output??? help!!

  2. #2

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    4

    Re: Simple Output Help Needed

    it's a form application

  3. #3
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Simple Output Help Needed

    A side note. You can create an array:

    Code:
    Dim Prepositions() As String = {"in", "over", "above"} ' add as many as youwant
    And then check whether this array contains the word being checked:
    Code:
    If Prepositions.Contains(words(Count)) Then PrepositionsCount +=1
    This will significantly improve the readability of your code.

    As for your main question. A normal list box displays single line items. In order to output 3 lines per an item you will need to set its DrawMode property to either OwnerDrawVariable or OwnerDrawFixed.

    Then you will need to catch the MeasureItem event and tell your listbox how big a rectangle you will need for a single item and next you have to catch the DrawItem event and to literally Draw your listbox item using GDI+ methods.

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    4

    Re: Simple Output Help Needed

    thanks for the advice on the array but i can't use it because it's an assignment for class and we have to demonstrate understanding of select case statements

    im still confused about the output.... thus our outputs and the output for this would start like:

    lstoutput.Items.Add(.............) <--------- im confused about what i would put in there.

  5. #5
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Simple Output Help Needed

    If it's a class I doubt they will teach you of OwnerDraw.
    Whatewer string expression you put in here it will appear as a selectable item of your listbox.
    So, what should be in the listbox?

    Listbox should contain some lists so type an example of how this list should look like.

    P.S. As for demonstration of SELECT CASE:

    Code:
    Select Case True
         Case Prepositions.Contains(words(Count))
                   PrepositionsCount += 1
         Case Articles.Contains(words(Count))
                   ArticlesCount += 1
         Case Unions.Contains(words(Count))
                   UnionsCount += 1
         Case Else
                   OtherWords += 1
    End Select

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    4

    Re: Simple Output Help Needed

    so you're saying that would be a more efficient way of select case? and where do you get "unions" from?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width