7 Replies - 5236 Views - Last Post: 25 October 2009 - 06:11 PM Rate Topic: -----

#1 foxdrat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-October 09

vb.net: if else condition

Post icon  Posted 24 October 2009 - 11:57 PM

I really need help. i know c++ and vb6 but now i am using vb.net right now. The problem is that when i use if else condition like vb6 he will read the else.. please tell me the difference with this programs and how 2 use if else statement in vb.net. Thank you
Is This A Good Question/Topic? 0
  • +

Replies To: vb.net: if else condition

#2 masashiorika  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 81
  • Joined: 06-July 09

Re: vb.net: if else condition

Posted 25 October 2009 - 12:15 AM

VB6 and VB.Net's If/Else statements run relatively the same.

Please post where it is going wrong so we can help you.
Was This Post Helpful? 1
  • +
  • -

#3 foxdrat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-October 09

Re: vb.net: if else condition

Posted 25 October 2009 - 12:39 AM

these is a sample of my program..

MsgBox("		 ",vbyesno)
if vbyes= true then
MsgBox("Correct")
else
MsgBox("Wrong")
end if


thanks for replying..

Mod Edit: When you are posting code please use code tags like this. :code:
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: vb.net: if else condition

Posted 25 October 2009 - 12:44 AM

Are you aware that MsgBox is the old vb6 method of showing a MessageBox.
In vb.net it is now MessageBox.Show.

Also in both it is a Function
Was This Post Helpful? 0
  • +
  • -

#5 dzone41  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 216
  • Joined: 21-August 09

Re: vb.net: if else condition

Posted 25 October 2009 - 01:17 AM

In your code, if vbyes does = True then execution will go to "MsgBox("Correct"), then to "End If".
if vbyes is "False" then code execution goes to "else", then MsgBox("Wrong") then "End If"
Set break points and follow it in the debugger

This post has been edited by dzone41: 25 October 2009 - 01:19 AM

Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: vb.net: if else condition

Posted 25 October 2009 - 01:24 AM

How will that work if the OP doesn't store of use the result of the messagebox?
Was This Post Helpful? 0
  • +
  • -

#7 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: vb.net: if else condition

Posted 25 October 2009 - 01:18 PM

A sample using .net code can be found at:
http://msdn.microsof...messagebox.aspx
Was This Post Helpful? 0
  • +
  • -

#8 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: vb.net: if else condition

Posted 25 October 2009 - 06:11 PM

Look in the msdn library, at the msgbox function. This is its signature:

Public Function MsgBox( _
   ByVal Prompt As Object, _
   Optional ByVal Buttons As MsgBoxStyle = MsgBoxStyle.OKOnly, _
   Optional ByVal Title As Object = Nothing _
) As MsgBoxResult


You can see that it returns a value of Type MsgBoxResult, not Boolean. There are 7 different results it can return, depending on how you call it and what the user does.


		Dim result As MsgBoxResult = MsgBox("Test", MsgBoxStyle.YesNo)
		If result = MsgBoxResult.Yes Then
			' Blah
		Else
			' Blah
		End If

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1