Go Back   Forum Care Forums > Development Reference Area > Visual Basic

Reply
 
LinkBack Thread Tools Display Modes
I'm going nuts please help with homework
Old
  (#1)
MaxBlack
Guest
 
Posts: n/a
Default I'm going nuts please help with homework - 06-04-2007, 10:32 AM

This is not working and for my life I can't figure out why:



Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim firstLetter As String


firstLetter = empIDtextBox.Text.Remove(1, 3)
firstLetter = firstLetter.ToUpper()
Label2.Text = firstLetter


If firstLetter <> "F" Or firstLetter <> "P" Then
Dim button As DialogResult
button = MessageBox.Show("First letter must be F or P!", _
"Error Message", MessageBoxButtons.OK,
MessageBoxIcon.Error, _
MessageBoxDefaultButton.Button1)
If button = Windows.Forms.DialogResult.OK Then
empIDtextBox.Text = ""
empIDtextBox.Focus()
End If
End If

End Sub
End Cl***




The program is much more complex but I can't even get this part to
work. The input is a 4 character string such as "f123"

It should strip out the last 3 characters and change the first letter
to upper case.

If I take out the "Or firstLetter <> "P" " then it's ok.

Label2 outputs the correct letter of "F" but still gives me an error
message.

"f123" should work and so should "p123"

My brain is thinking if firstLetter is not F or firstLetter is not P
then give error message, but that ain't workin' for me.

TIA,

Max
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: I'm going nuts please help with homework
Old
  (#2)
Rick Rothstein \(MVP - VB\)
Guest
 
Posts: n/a
Default Re: I'm going nuts please help with homework - 06-04-2007, 10:32 AM

> This is not working and for my life I can't figure out why:
>
> If firstLetter <> "F" Or firstLetter <> "P" Then


Think about what this If-Then statement does... yes, if firstLetter is any
letter other than "F" or "P", then firstLetter meets your test BUT because
you used OR... if firstLetter is an "F" then it is not a "P"; and if it is a
"P", then it is not an "F"... these will also meet your test.

For future reference...

Almost everybody in this newsgroup is using VB6 or lower. While you may get
a stray answer to VB.NET (including VB2003, VB2005 and VB Express which have
dropped .NET from their names) questions here, you should ask them in
newsgroups devoted exclusively to .NET programming (the languages are
different enough to warrant separate newsgroup support). Look for newsgroups
with either the word "dotnet" or "vsnet" in their name.

For the microsoft news server, try these newsgroups for Visual Basic .NET
related questions...

microsoft.public.dotnet.languages.vb
microsoft.public.dotnet.languages.vb.upgrade
microsoft.public.dotnet.languages.vb.controls
microsoft.public.dotnet.languages.vb.data

And these for more general .NET questions

microsoft.public.dotnet.general
microsoft.public.vsnet.general

Note: There are many other .NET newgroups (use the first three "fields" from
the last two as templates when searching for them), but the above ones
should get you started.

Rick


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top