4 Replies - 24522 Views - Last Post: 24 September 2008 - 02:09 AM Rate Topic: -----

#1 VBBeginner  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 13
  • Joined: 22-September 08

Msgbox Result Problem

Post icon  Posted 23 September 2008 - 04:49 PM

Heh i was trying in one of my programs to have a msgbox choice, but it never works. My teacher said declare the result as a variable but for some reason this isnt working. (He did not actually give me this code i tried to figure it out myself) Im a beginner, so to me this code seems sound. The code editor didnt pick up any problems and i dont know why this isnt working. Any advice would be appreciated. Thanks,

Nicholas

Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		MsgBox("Testing 123", MsgBoxStyle.YesNo, "Testing")
		Dim A As MsgBoxResult
		If A = MsgBoxResult.Yes Then
			MsgBox("Yes")
		ElseIf A = MsgBoxResult.No Then
			MsgBox("No")
		End If
	End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: Msgbox Result Problem

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Msgbox Result Problem

Posted 23 September 2008 - 06:23 PM

You're using the legacy (VB6) MsgBox, which isn't going to give the MessageBoxResult value, when you should be using the .Net MessageBox Class. Try this

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim result As MessageBoxResult = MessageBox.Show("Testing 123", "Testing", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        If result = MessageBoxResult.Yes Then
            MessageBox.Show("Yes")
        Else
            MessageBox.Show("No")
        End If
    End Sub
End Class



Hope that helps :)
Was This Post Helpful? 0
  • +
  • -

#3 Damage  Icon User is offline

  • Lord of Schwing
  • member icon

Reputation: 29
  • View blog
  • Posts: 1,093
  • Joined: 05-June 08

Re: Msgbox Result Problem

Posted 23 September 2008 - 08:51 PM

huh, i had no idea that msgbox was legacy thing(but i don't know much :P) but if i try copy and paste the declaration

 Dim result As MessageBoxResult = MessageBox.Show("Testing 123", "Testing", MessageBoxButtons.YesNo, MessageBoxIcon.Question)  



I get told that it's(MessageBoxResult) an undefined type and one of the fixes is to change it to msgboxresult. I'm using 2005 professional. Am i missing something?
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Msgbox Result Problem

Posted 23 September 2008 - 10:51 PM

Then try DialogResult, it's more 2.0and the other seems to be 3.5 based. Look at these modifications

Imports System.Windows.Forms

Public Class Form1

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim result As Windows.Forms.DialogResult = MessageBox.Show("Testing 123", "Testing", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If result = Windows.Forms.DialogResult.Yes Then
            MessageBox.Show("Yes")
        Else
            MessageBox.Show("No")
        End If
    End Sub
End Class




Here I actually created a test project and believe I got what your end results were wanting to be.
Was This Post Helpful? 1

#6 Damage  Icon User is offline

  • Lord of Schwing
  • member icon

Reputation: 29
  • View blog
  • Posts: 1,093
  • Joined: 05-June 08

Re: Msgbox Result Problem

Posted 24 September 2008 - 02:09 AM

ahh okay, gotcha
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1