I'm going nuts please help with homework

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MaxBlack

    #1

    I'm going nuts please help with homework

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



    Private Sub Button1_Click(B yVal sender As Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    Dim firstLetter As String


    firstLetter = empIDtextBox.Te xt.Remove(1, 3)
    firstLetter = firstLetter.ToU pper()
    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", MessageBoxButto ns.OK,
    MessageBoxIcon. Error, _
    MessageBoxDefau ltButton.Button 1)
    If button = Windows.Forms.D ialogResult.OK Then
    empIDtextBox.Te xt = ""
    empIDtextBox.Fo cus()
    End If
    End If

    End Sub
    End Class




    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
  • Rick Rothstein \(MVP - VB\)

    #2
    Re: I'm going nuts please help with homework

    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.publi c.dotnet.langua ges.vb
    microsoft.publi c.dotnet.langua ges.vb.upgrade
    microsoft.publi c.dotnet.langua ges.vb.controls
    microsoft.publi c.dotnet.langua ges.vb.data

    And these for more general .NET questions

    microsoft.publi c.dotnet.genera l
    microsoft.publi c.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


    Comment

    Working...