Computing.Net > Forums > Programming > Whats wrong with this VB code?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Whats wrong with this VB code?

Reply to Message Icon

Name: Tidus
Date: January 10, 2004 at 18:40:14 Pacific
OS: Winxp
CPU/Ram: ?
Comment:

Private Sub txt1_Change()
If txt1.Text <> Y Or txt1.Text <> N Then
MsgBox("Only Y and N please", vbOKOnly, "Only Y or N please", None, None) = vbOK
End Sub

-

Whats wrong with the code? >< Sry im only in grade 10 Computer science class, still learning, so No flaming please i just want to know how i can make it ::Beep:: and stop people from entering anything other than "Y" or "N" in the textbox, thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: Tidus
Date: January 10, 2004 at 18:41:38 Pacific
Reply:

EDIT: O i forgot to enter this part in the code, it still doesnt work:

-----------------

Private Sub txt1_Change()
If txt1.Text <> Y Or txt1.Text <> N Then
MsgBox("Only Y and N please", vbOKOnly, "Only Y or N please", None, None) = vbOK
End if 'Edited Part
End Sub

----------------


0

Response Number 2
Name: egkenny
Date: January 10, 2004 at 19:37:39 Pacific
Reply:

Private Sub txt1_Change()
If txt1.Text <> "Y" And txt1.Text <> "N" Then
Result = MsgBox("Only Y and N please", vbOKOnly, "Only Y or N please")
End If
End Sub


0

Response Number 3
Name: Tidus
Date: January 10, 2004 at 20:04:16 Pacific
Reply:

Wait...

[quote]

If txt1.Text <> "Y" And txt1.Text <> "N" Then

[/quote]

And?? That would mess it up wouldnt it cuz im trying to get a yes or no answer. Cant enter both letters at the same time? Would OR work in the same code? -.-


0

Response Number 4
Name: egkenny
Date: January 10, 2004 at 20:59:07 Pacific
Reply:

No, the statement I gave is correct
An important law to use when you are working
with computer logic is:
De Morgan's laws
not (P and Q) = (not P) or (not Q)
not (P or Q) = (not P) and (not Q)

Here is the PROOF

We start with what we want to be true:
(txt1.Text = "Y") or (txt1.Text = "N")

We want to invoke the Message box ONLY when that is NOT true:

not((txt1.Text = "Y") or (txt1.Text = "N"))

By using De Morgan's laws this is equal to:
not(txt1.Text = "Y") and not(txt1.Text = "N")
(txt1.Text <> "Y") and (txt1.Text <> "N")


0

Response Number 5
Name: Sord
Date: January 11, 2004 at 16:08:46 Pacific
Reply:

Don't forget the quotes though as egkenny showed!


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Whats wrong with this VB code?

What is wrong with this ASP code? www.computing.net/answers/programming/what-is-wrong-with-this-asp-code/5324.html

what's wrong with this code? www.computing.net/answers/programming/whats-wrong-with-this-code/8504.html

VB ticking me off www.computing.net/answers/programming/vb-ticking-me-off/6680.html