Thread Solved

Join Date: May 2006
Posts: 10
Reputation: janeane_tho12n is an unknown quantity at this point 
Solved Threads: 0
janeane_tho12n janeane_tho12n is offline Offline
Newbie Poster

helpppp!

 
0
  #1
May 4th, 2006
can anyone help me w/ this one?

code:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. dim msg as boolean
  2.  
  3. msg = msgbox ("Save this one?", vbyesno)
  4.  
  5. if msg = true then
  6. 'code goes here
  7. else
  8. 'code goes here
  9. end if
when i run this one my code jumps to else though i choose yes to save the file.
Last edited by Comatose; May 4th, 2006 at 7:21 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: helpppp!

 
0
  #2
May 4th, 2006
try replacing true with vbyes.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 10
Reputation: janeane_tho12n is an unknown quantity at this point 
Solved Threads: 0
janeane_tho12n janeane_tho12n is offline Offline
Newbie Poster

Re: helpppp!

 
0
  #3
May 4th, 2006
i already tried it and it gave me the same result? i dnt know whats wrong
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: helpppp!

 
0
  #4
May 4th, 2006
what code is there between the if blocks (where it says 'code goes here), what's actually there?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: helpppp!

 
0
  #5
May 4th, 2006
Ok, the problem is that you declared the variable (msg) as a boolean value.... while the msgbox function returns more values than just true and false. This code works wonderfully when you change the type declaration of your variable:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim msg As VbMsgBoxResult
  2.  
  3. msg = MsgBox("Save this one?", vbYesNo)
  4.  
  5. If msg = vbYes Then
  6. MsgBox "true"
  7. Else
  8. MsgBox "false"
  9. End If
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 10
Reputation: janeane_tho12n is an unknown quantity at this point 
Solved Threads: 0
janeane_tho12n janeane_tho12n is offline Offline
Newbie Poster

Re: helpppp!

 
0
  #6
May 4th, 2006
yep got it i just deleted the declaration andleave it as a variant variable. but i think its a good practice to declare a variable right?
thanks for your help.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: helpppp!

 
0
  #7
May 4th, 2006
Declaring variables isn't required in VB, but it's a great practice. Part of the reason is, when you get into other languages, that are more powerful, you'll be forced to declare any variable before you can use it.... also, declaring variables provides the program with a reserve of memory for that variable. This makes your program smaller, and makes it run faster. On a simple test application, like the one we have here, it won't make a noticable difference, but in larger applications, you'll be asking yourself what the hell happened. Provided is a link to a page that will help you to optimize your VB programming, so that you can increase the speed significantly of yours apps.

Also, When you don't declare a variable, it's default type is a variant. If you read the page linked, you'll see why variants are a no, no. Basically, they are the largest, most bulky variable type in existance, and should really be treated like the Leper Variable. In fact, every time you use a variant type variable, I want you to think about how you are giving your code leprosy.

http://www.aivosto.com/vbtips/stringopt.html
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 10
Reputation: janeane_tho12n is an unknown quantity at this point 
Solved Threads: 0
janeane_tho12n janeane_tho12n is offline Offline
Newbie Poster

Re: helpppp!

 
0
  #8
May 4th, 2006
well said. thank u thank u.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC