Jump to content

MsgBox problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
j0rd4nn

j0rd4nn

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
Always happens to me :(

It's a really small code, but a problem nonetheless:
Private Sub Command1_Click()

If Text1.Text = "jordan" Or "Jordan" And Text2.Text = "fail" Or "fail" Then

Let MsgBox = "Congratulations, 2 out of 2 correct."

Else: MsgBox = "Unlucky, you got 1 or less incorrect."

End If

End Sub

It's obvious; you input a word, click the button and a pop-up happens telling you if you got it correct or not. For some reason, there something wrong with the MsgBox = "" code I'm using, any help here lads?

Well anyway, I want it to verify if the inputted words are jordan and fail, if so or if not a message box will appear. Thanks in advance lads, I really do appreciate it.

As a side note, do I need to tell it to check for Jordan and jordan or will jordan check for the letter regardless of capitalization?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I can almost guarantee it should be:
Private Sub Command1_Click()
If (Text1.Text = "jordan" Or Text1.Text="Jordan") And (Text2.Text = "fail" Or Text2.Text = "fail") Then
Let MsgBox = "Congratulations, 2 out of 2 correct."
Else: MsgBox = "Unlucky, you got 1 or less incorrect."
End If
End Sub

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
j0rd4nn

j0rd4nn

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
Doesn't work :/

I get this error for specifics (sorry I forgot to post it before hand):

Quote

Compile error:
Function call on left-hand side of assignment much return Variant or Object

And then it highlights the first MsgBox as shown:
MsgBox =


#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
What version of VB are you using? You shouldn't be using "LET" in newer versions. In VB6 you execute a messagebox like this:

msgbox "This is a message box!"

In your code you would need to remove the equal (=) sign. You do not assign a value to messagebox.

In Visual Basic .NET you create a message box like this:

MessageBox.Show("Some Message Here")


#5
j0rd4nn

j0rd4nn

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
I'm coding in VB6, proberly should of mentioned this.

When I get home tomorrow, I'll try it out. Thanks

#6
Guest_Jordan_*

Guest_Jordan_*
  • Guests
You can also append several other options like a YesNo question messagebox.

#7
j0rd4nn

j0rd4nn

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
Yeah I no thanks, but for now I'm keeping it simple.

Learn a bit, then use the tutorial, then from there add everything I know and build a new unique program so to speak. Helps me understand how it works instead of just reading you know.

#8
j0rd4nn

j0rd4nn

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
I found it out, and thought I would share it:
Private Sub Command1_Click()
If (Text1.Text = "jordan" Or Text1.Text="Jordan") And (Text2.Text = "fail" Or Text2.Text = "fail") Then
Let intMsg = MsgBox  ("Congratulations, 2 out of 2 correct.")
Else: intMsgBox = MsgBox ("Unlucky, you got 1 or less incorrect.")
End If
End Sub

This part of the code:
If (Text1.Text = "jordan" Or Text1.Text="Jordan") And (Text2.Text = "fail" Or Text2.Text = "fail") Then

The brackets "(" ")" are not necessary, but just looks better, and more organised. :)

Thanks for the help.

#9
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
MsgBox() returns a VB constant, such as vbYes or vbNo or vbCancel etc. These are actually binary integer constants, but it is easier to reference them via the built-in ones.

If you want to store the result of a MsgBox (in other words, what the user clicked) then you need a variable of the appropriate data type.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums