Click here to Skip to main content
15,881,778 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
VB
Private Sub Button2_Click (sender As System.Object, e As System.EventArgs) Handles button2.click
 
         As Integer Dim question
 
         Question = Val (InputBox ("Capital of Turkey?", "Question 2", 30, 40))
         If ısnothing (question = ("ankara")) Than
             MsgBox ("Wrong answer")
         Else: question = ("ankara")
             MsgBox ("Correct Answer")
         End If
     End Sub
Posted
Updated 26-Feb-15 11:15am
v4
Comments
Sergey Alexandrovich Kryukov 26-Feb-15 16:38pm    
What do you mean by that? Do you get a message box which misspells some Turkish text?
—SA
[no name] 26-Feb-15 16:45pm    
I updated the question. Do you understand now ?
ZurdoDev 26-Feb-15 16:55pm    
It fails because something is wrong. I give up, why?
[no name] 26-Feb-15 16:59pm    
I do not know the program very much. I'm trying to learn

1 solution

Bad usage of IsNothing function[^]! IsNothing returns a boolean value indicating whether an expression has no object assigned to it.

Try this:
VB
Dim question As String

question = InputBox("Capital of Turkey?", "Question 2")
MsgBox "The answer is " & IIf(question = "Ankara", "", "not ") & "correct!"


Note: to be sure that one string is equal to another, you need to know that comparison depends on many factors, such as: site-code, big/small letters, etc.

I'd suggest to read this:
Comparison Operators in Visual Basic[^]
StrComp Function (Visual Basic)[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Feb-15 18:42pm    
Good points, a 5.
—SA
Maciej Los 27-Feb-15 1:41am    
Thank you, Sergey ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900