Welcome to Dream.In.Code
Become a VB Expert!

Join 137,234 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,682 people online right now. Registration is fast and FREE... Join Now!




Application that allows the user to enter password

 
Reply to this topicStart new topic

Application that allows the user to enter password, Replace all vowels with A,E,I,O,U

km22
11 Mar, 2007 - 01:04 PM
Post #1

New D.I.C Head
*

Joined: 11 Mar, 2007
Posts: 32


My Contributions
I am working on an assignment for Visual Basic Beginning (visual basic 2005), and need to create an application that allows the user to enter a password, and all vowels need to be replaced with X. The code below is what I have so far...and is not working. If any anybody could steer me in the right direction - if I should be using the Replace method (which is what I used), or the Contains method. Although I have tried the Contains method also, my code didnt work for this method either...any help would be greatly appreciated...

This is my code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles newPasswordButton.Click

Dim origPassword As String

origPassword = origPasswordTextBox.Text

If origPassword.Length = 5 Then
origPassword = origPassword.Replace("A-E-I-O-U", "X")
newPasswordLabel.Text = origPassword
End If
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Application That Allows The User To Enter Password
11 Mar, 2007 - 01:51 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
If I'm not mistaken, the .replace method takes either a single character to replace, or a string. you appear to be trying to pass it a regular expression as a parameter. you will like have to put the function call in a loop that checks for each vowel. Also, the code you've written will only run if the length of the password is 5 characters.
User is online!Profile CardPM
+Quote Post

km22
RE: Application That Allows The User To Enter Password
12 Mar, 2007 - 09:28 AM
Post #3

New D.I.C Head
*

Joined: 11 Mar, 2007
Posts: 32


My Contributions
Thank you, I sure appreciate the reply. I recoded my assignment using a loop function - this is not working either, I end up with one X, and every vowel is supposed to show up as an X; instead of just the one X. I have tried changing my code so many times, and I cannot get this to work... smile.gif I have included my revised code (again, any help would be appreciated):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles newPasswordButton.Click

Dim origPass As String
Dim num As String

origPass = origPasswordTextBox.Text.ToUpper
num = origPass

Do While num.Length = (5)

MessageBox.Show("Password is five characters.", _
"password", MessageBoxButtons.OK, _
MessageBoxIcon.Information)

If num.Contains("A") Then
num = ("X")
End If

If num.Contains("E") Then
num = ("X")
End If

If num.Contains("I") Then
num = ("X")
End If

If num.Contains("O") Then
num = ("X")
End If

If num.Contains("U") Then
num = ("X")
End If

num = newPasswordLabel.Text


Loop


End Sub


User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Application That Allows The User To Enter Password
12 Mar, 2007 - 09:36 AM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
That is because you are setting the entire value of num to X. you'll need something like the following (syntax may not be exact).
CODE

dim str1 as string
str1 = origPasswordTextBox.Text.ToUpper
str1 = Replace(str1,"A","X")
str1 = Replace(str1,"E","X")
str1 = Replace(str1,"I","X")
str1 = Replace(str1,"O","X")
str1 = Replace(str1,"U","X")


User is online!Profile CardPM
+Quote Post

km22
RE: Application That Allows The User To Enter Password
12 Mar, 2007 - 02:55 PM
Post #5

New D.I.C Head
*

Joined: 11 Mar, 2007
Posts: 32


My Contributions
Thank you so much. I have tried so many different ways to get the code to work - and now it is (thanks again). Also part of the assignment was to change all numbers to Z and then reverse the password. This is the revised code (again…):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles newPasswordButton.Click

Dim origPass As String
Const message As String = _
"The password must contain 5 characters."

origPass = origPasswordTextBox.Text.ToUpper

If origPass.Length = 5 Then

origPass = Replace(origPass, "A", "X")
origPass = Replace(origPass, "E", "X")
origPass = Replace(origPass, "I", "X")
origPass = Replace(origPass, "O", "X")
origPass = Replace(origPass, "U", "X")
origPass = Replace(origPass, "0", "Z")
origPass = Replace(origPass, "1", "Z")
origPass = Replace(origPass, "2", "Z")
origPass = Replace(origPass, "3", "Z")
origPass = Replace(origPass, "4", "Z")
origPass = Replace(origPass, "5", "Z")
origPass = Replace(origPass, "6", "Z")
origPass = Replace(origPass, "7", "Z")
origPass = Replace(origPass, "8", "Z")
origPass = Replace(origPass, "9", "Z")
Else
MessageBox.Show(message, "password", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

origPass = StrReverse(origPass)

newPasswordLabel.Text = origPass

End Sub

(Not pertaining to the code)
Ps. I noticed a little mad icon on the subject line. I didn’t mean to add that there with my last post, I must have checked the wrong icon (first time using these…oops)

- Kathy

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:55PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month