| | |
helpppp!
Thread Solved |
•
•
Join Date: May 2006
Posts: 10
Reputation:
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:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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.
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)
Dim msg As VbMsgBoxResult msg = MsgBox("Save this one?", vbYesNo) If msg = vbYes Then MsgBox "true" Else MsgBox "false" End If
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
![]() |
Similar Threads
- Audio Not Playing (Windows NT / 2000 / XP)
- Startup Problem EMERGENCY! (Windows NT / 2000 / XP)
- Math/computerscience Log Problem- Helpppp (Computer Science)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Please Help me on Data Grouping in VB 6.0
- Next Thread: Toolbar - Buttonmenu
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






