Solved

Parse the letters of the alphabet when a user inputs a word....

Posted on 2009-07-06
14
645 Views
Last Modified: 2012-05-07
I need to create a Windows application that contains a single form. The form will have three controls, a textbox, a button displaying the text Parse and a suitable UI control, preferably scrollable, used to display the results. After entering the text and clicking the Parse button, the program should output the number of times each letter in the alphabet occurs in the textbox. Case sensitivity is not required.

For example, if the user enters baaad as the text and hits the Parse Button, the result control should display:

There are 3 A's
There are 1 B's
There are 0 C's
There are 1 D's
There are 0 E's
There are 0 F's
etc...

Any thoughts?

I'd like it in VB.NET if possible, but C#, VB Script or ASP.NET is fine....
0
Comment
Question by:pborregg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
14 Comments
 
LVL 18

Accepted Solution

by:
UnifiedIS earned 500 total points
ID: 24787578
text box is called txtLetterCount, list box named lstLetterCount

This is the click event:
        Dim sABC As String = "abcdefghijklmnopqrstuvwxyz"
        Dim sLetter As String
        Dim iCount As Integer
        For x As Integer = 0 To sABC.Length - 1
            iCount = 0
            sLetter = sABC.Substring(x, 1).ToUpper
            For y As Integer = 0 To Me.txtLetterCount.Text.Trim.Length - 1
                If Me.txtLetterCount.Text.Substring(y, 1).ToUpper = sLetter.ToUpper Then
                    iCount += 1
                End If
            Next
            Me.lstLetterCount.Items.Add("There are " & iCount & Space(1) & sLetter & "'s")
        Next
0
 

Author Comment

by:pborregg
ID: 24789008
Getting this error UnifiedIS:

Technical Information (for support personnel)

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'abcdefghijklmnopqrst'
/racmswebprojectMSSQL/Untitled-4.asp, line 8


Browser Type:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 1.0.3705; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)

Page:
GET /racmswebprojectMSSQL/Untitled-4.asp

Time:
Monday, July 06, 2009, 4:36:41 PM


More information:
Microsoft Support
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
 
        Dim sABC 
		sABC = "abcdefghijklmnopqrstuvwxyz"
        Dim sLetter
        Dim iCount
        For x = 0 to sABC.Length - 1
            iCount = 0
            sLetter = sABC.Substring(x, 1).ToUpper
            For y = 0 To form1.txtLetterCount.Text.Trim.Length - 1
                If form1.txtLetterCount.Text.Substring(y, 1).ToUpper = sLetter.ToUpper Then
                    iCount + 1
                End If
            Next
            form1.lstLetterCount.Items.Add("There are " & iCount & Space(1) & sLetter & "'s")
        Next
 
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <input type="text" name="txtLetterCount" id="txtLetterCount" />
    <input type="button" name="btnControl" id="btnControl" value="Parse" />
</p>
  <p>
    <textarea name="lstLetterCount" id="lstLetterCount" cols="45" rows="5"></textarea>
</p>
</form>
</body>
</html>

Open in new window

0
 
LVL 15

Expert Comment

by:spprivate
ID: 24789269
Declare sABC as String

Dim sABC As String = "abcdefghijklmnopqrstuvwxyz"
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:pborregg
ID: 24789548
Get this error now...

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/racmswebprojectMSSQL/Untitled-4.asp, line 4, column 9
Dim sABC as String, sLetter, iCount, x, y
--------^


Browser Type:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 1.0.3705; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)

Page:
GET /racmswebprojectMSSQL/Untitled-4.asp

Time:
Monday, July 06, 2009, 5:56:24 PM


More information:
Microsoft Support
0
 

Author Comment

by:pborregg
ID: 24790284
Ok, I'd like this is VB SCRIPT

Does anyone have any idea of what I'm looking for?
0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 24790674
You specifically asked for VB.NET.  I coded your routine and it works exactly as you asked.  So, the answer is no, I have no idea what your are looking for.
0
 

Author Comment

by:pborregg
ID: 24790697
Ok, sorry, I believe you... how do I call that button clicked event from the button and code I put above...

Do I need to encapsulate the code you wrote with Sub btnControl_onclick() and End Sub?

Peter
0
 

Author Comment

by:pborregg
ID: 24790704
Unified,

What I'm asking for is the entire page code.. I'm new to VB.NET but not new to VB Script.

Thanks,

Peter
0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 24790717
I don't know the syntax for the control event methods in vb script but yes, that code goes in the click event of the button.  
0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 24790745
I'm assuming you are using the designer to place your controls

public class yourformname
 Private Sub btnDrawing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDrawing.Click
Dim sABC As String = "abcdefghijklmnopqrstuvwxyz"
        Dim sLetter As String
        Dim iCount As Integer
        For x As Integer = 0 To sABC.Length - 1
            iCount = 0
            sLetter = sABC.Substring(x, 1).ToUpper
            For y As Integer = 0 To Me.txtLetterCount.Text.Trim.Length - 1
                If Me.txtLetterCount.Text.Substring(y, 1).ToUpper = sLetter.ToUpper Then
                    iCount += 1
                End If
            Next
            Me.lstLetterCount.Items.Add("There are " & iCount & Space(1) & sLetter & "'s")
        Next
    End Sub

end class


0
 

Author Comment

by:pborregg
ID: 24790760
Here's my ASPX page so far...

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <input type="text" name="textField" id="textField" />
    <input type="button" name="btnControl" id="btnControl" value="Parse" onclick="btnClickEvent()" />
  </p>
  <p>
    <textarea name="textBox" id="textBox" cols="45" rows="5"></textarea>
</p>
</form>
</body>
</html>

Do I need a Code Behind Page or can I simply put it on the same page?
0
 

Author Comment

by:pborregg
ID: 24790783
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="utf-8" %>
<%#

public class form1
Private Sub btnControl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnControl.Click
Dim sABC As String = "abcdefghijklmnopqrstuvwxyz"
        Dim sLetter As String
        Dim iCount As Integer
        For x As Integer = 0 To sABC.Length - 1
            iCount = 0
            sLetter = sABC.Substring(x, 1).ToUpper
            For y As Integer = 0 To Me.txtLetterCount.Text.Trim.Length - 1
                If Me.txtLetterCount.Text.Substring(y, 1).ToUpper = sLetter.ToUpper Then
                    iCount += 1
                End If
            Next
            Me.lstLetterCount.Items.Add("There are " & iCount & Space(1) & sLetter & "'s")
        Next
    End Sub

end class

 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <input type="text" name="textField" id="textField" />
    <input type="button" name="btnControl" id="btnControl" value="Parse" onclick="btnClickEvent()" />
  </p>
  <p>
    <textarea name="textBox" id="textBox" cols="45" rows="5"></textarea>
</p>
</form>
</body>
</html>
0
 

Author Comment

by:pborregg
ID: 24790839
It's throwing an error:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30201: Expression expected.

Source Error:

 

Line 3:  
Line 4:  
Line 5:  Public Class Form1 <-- HERE
Line 6:  
Line 7:        Private Sub btnControl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnControl.Click
 
0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 24791058
Not sure, but waaay off the question now
0

Featured Post

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question