944,155 Members | Top Members by Rank

Ad:
May 4th, 2006
0

helpppp!

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
janeane_tho12n is offline Offline
10 posts
since May 2006
May 4th, 2006
0

Re: helpppp!

try replacing true with vbyes.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 4th, 2006
0

Re: helpppp!

i already tried it and it gave me the same result? i dnt know whats wrong
Reputation Points: 10
Solved Threads: 0
Newbie Poster
janeane_tho12n is offline Offline
10 posts
since May 2006
May 4th, 2006
0

Re: helpppp!

what code is there between the if blocks (where it says 'code goes here), what's actually there?
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 4th, 2006
0

Re: helpppp!

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
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 4th, 2006
0

Re: helpppp!

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
janeane_tho12n is offline Offline
10 posts
since May 2006
May 4th, 2006
0

Re: helpppp!

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
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 4th, 2006
0

Re: helpppp!

well said. thank u thank u.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
janeane_tho12n is offline Offline
10 posts
since May 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Please Help me on Data Grouping in VB 6.0
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Toolbar - Buttonmenu





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC