3 Replies - 654 Views - Last Post: 21 December 2011 - 07:04 AM Rate Topic: -----

#1 Strxex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-December 11

Vowel Counting Not Working

Posted 20 December 2011 - 03:56 PM

My code for the counting vowel application for VB 6 is not working for some reason.
I think it works for the "a" vowel, but the others does not work...
Please help! Thanks:

 Option Explicit         'Strxex
Private strTxtInput As String
Private intVowelsCountA As Integer
Private intVowelsCountE As Integer
Private intVowelsCountI As Integer
Private intVowelsCountO As Integer
Private intVowelsCountU As Integer
Private intTotalVowels As Integer
Private strA As String
Private intI As Integer

Private Sub cmdCount_Click()
strTxtInput = txtInput.Text
    For intI = 1 To Len(strTxtInput)
    If Mid$(strTxtInput, intI, 1) = "a" Then
        intVowelsCountA = intVowelsCountA + 1
    ElseIf Mid$(strTxtInput, intI, 1) = "e" Then
        intVowelsCountA = intVowelsCountE + 1
    ElseIf Mid$(strTxtInput, intI, 1) = "i" Then
        intVowelsCountA = intVowelsCountI + 1
    ElseIf Mid$(strTxtInput, intI, 1) = "o" Then
        intVowelsCountA = intVowelsCountO + 1
    ElseIf Mid$(strTxtInput, intI, 1) = "u" Then
        intVowelsCountA = intVowelsCountU + 1
        
        End If
    Next
    
intTotalVowels = intVowelsCountA + intVowelsCountE + intVowelsCountI + intVowelsCountO + intVowelsCountU
lblOutput.Caption = intTotalVowels
End Sub

Private Sub cmdDone_Click()
    Unload Me
End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Vowel Counting Not Working

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9570
  • View blog
  • Posts: 36,242
  • Joined: 12-June 08

Re: Vowel Counting Not Working

Posted 20 December 2011 - 06:05 PM

Why is "intVowelsCountA" getting everyone else's input? Wouldn't they be using their own variables?

Quote

intVowelsCountA = intVowelsCountE + 1
intVowelsCountA = intVowelsCountI + 1
intVowelsCountA = intVowelsCountO + 1
intVowelsCountA = intVowelsCountU + 1

Was This Post Helpful? 1
  • +
  • -

#3 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: Vowel Counting Not Working

Posted 21 December 2011 - 02:59 AM

View Postmodi123_1, on 21 December 2011 - 01:05 AM, said:

Why is "intVowelsCountA" getting everyone else's input? Wouldn't they be using their own variables?

Quote

intVowelsCountA = intVowelsCountE + 1
intVowelsCountA = intVowelsCountI + 1
intVowelsCountA = intVowelsCountO + 1
intVowelsCountA = intVowelsCountU + 1


Agree, looks like a copy and paste job that hasn't been fully updated.

Also, might be worth adding something in to initialise the variables....if you run it more than once, there is nothing to reset the counters (assuming you've shown us the full code).
Was This Post Helpful? 0
  • +
  • -

#4 Strxex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-December 11

Re: Vowel Counting Not Working

Posted 21 December 2011 - 07:04 AM

Thanks, I fixed it.
Yeah I didn't notice the "intVowelsCountA"'s input. Thanks :D

Final Working code:
Option Explicit         'Strxex
Private strTxtInput As String
Private intVowelsCountA As Integer
Private intVowelsCountE As Integer
Private intVowelsCountI As Integer
Private intVowelsCountO As Integer
Private intVowelsCountU As Integer
Private intTotalVowels As Integer
Private strA As String
Private intI As Integer

Private Sub cmdCount_Click()
strTxtInput = txtInput.Text
    For intI = 1 To Len(strTxtInput)
    If Mid$(strTxtInput, intI, 1) = "a" Then
        intVowelsCountA = intVowelsCountA + 1
    ElseIf Mid$(strTxtInput, intI, 1) = "e" Then
        intVowelsCountE = intVowelsCountE + 1
    ElseIf Mid$(strTxtInput, intI, 1) = "i" Then
        intVowelsCountI = intVowelsCountI + 1
    ElseIf Mid$(strTxtInput, intI, 1) = "o" Then
        intVowelsCountO = intVowelsCountO + 1
    ElseIf Mid$(strTxtInput, intI, 1) = "u" Then
        intVowelsCountU = intVowelsCountU + 1
        
        End If
    Next
    
intTotalVowels = intVowelsCountA + intVowelsCountE + intVowelsCountI + intVowelsCountO + intVowelsCountU
lblOutput.Caption = intTotalVowels
End Sub

Private Sub cmdDone_Click()
    Unload Me
End Sub

Private Sub txtInput_Change()
intVowelsCountA = 0
intVowelsCountE = 0
intVowelsCountI = 0
intVowelsCountO = 0
intVowelsCountU = 0
lblOutput.Caption = ""
End Sub


This post has been edited by modi123_1: 21 December 2011 - 07:34 AM
Reason for edit:: fixed botched code tags

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1