Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 934 | Replies: 7 | Solved
![]() |
•
•
Join Date: May 2006
Posts: 10
Reputation:
Rep Power: 3
Solved Threads: 0
can anyone help me w/ this one?
code:
when i run this one my code jumps to else though i choose yes to save the file.
code:
dim msg as boolean
msg = msgbox ("Save this one?", vbyesno)
if msg = true then
'code goes here
else
'code goes here
end if Last edited by Comatose : May 4th, 2006 at 7:21 am.
•
•
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation:
Rep Power: 7
Solved Threads: 108
•
•
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation:
Rep Power: 7
Solved Threads: 108
•
•
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation:
Rep Power: 7
Solved Threads: 108
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:
Dim msg As VbMsgBoxResult
msg = MsgBox("Save this one?", vbYesNo)
If msg = vbYes Then
MsgBox "true"
Else
MsgBox "false"
End If•
•
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation:
Rep Power: 7
Solved Threads: 108
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
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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode