larrylaffer133
04-12-2005, 06:20 PM
what is Option Explicit? i see this code in the general declarations section of a form sometimes and i dont know what it does or why people add it to their code.
what is Option Explicitlarrylaffer133 04-12-2005, 06:20 PM what is Option Explicit? i see this code in the general declarations section of a form sometimes and i dont know what it does or why people add it to their code. reboot 04-12-2005, 06:25 PM Option Explicit forces you to declare your variables. mrjeffy321 04-12-2005, 06:25 PM Option Explicit tell the compiler that you are required to delcare all your variables before you use them. otherwise, without Option Explicit, you can start using variables names whatever you want, and VB will automatically create one for you. This sounds great, how nice of VB, but really, this is a bad idea, it leads to errors in your code (because if you miss type a variable name, VB creates a new one without telling you, storing its value and continues running, un-be-knownst to you, the variable you think you were using is being left alone. Also, if dont declare a variable yourself, vb will auto declare it as a variant (which take the most memory). a variant can hold any data type, numbers letters, ...., but that wont dee you much good when you want to multiply a variable you think is containing a number and is acutally containing a combobox (although that would be a rather poor coding job to make that misstake, it could theroetically happen). It is just a good idea to use Option Explicit always. larrylaffer133 04-12-2005, 06:26 PM dont you always need to declare variables though? reboot 04-12-2005, 06:28 PM You should. But Vb doesn't force you to, unless you force it to force you. :) larrylaffer133 04-12-2005, 06:32 PM ok so it really isnt a necessary command? also how do you put a program in fullscreen mode without the window. then by hitting esc or something it gets out. reboot 04-12-2005, 06:34 PM It's not a command. VB has no 'commands'. And yes, it's very necessary. larrylaffer133 04-12-2005, 06:40 PM im still kind of confused though. why is it necessary, and what about the full screen mode thing. jpaugh78 04-12-2005, 06:40 PM ....also how do you put a program in fullscreen mode without the window. then by hitting esc or something it gets out. Well, you'd have to use the keypress event to see when the user presses the escape key. But to make it full screen without a window, i believe you just change the border setting of the form, and make the windowState maximized. reboot 04-12-2005, 06:43 PM If you don't have Option Explicit, and you misspell a variable, VB doesn't complain, likely causing you no end of trouble. This has been explained once already. larrylaffer133 04-12-2005, 06:46 PM oh ok, i understand. so if you set variables and then go to add a number to a certain variable but you misspell the variable vb will tell you there is no variable that exists with that name? otherwise it wouldnt say anything and it would take a long time to find out the problem. cool_dude 04-12-2005, 06:53 PM set your form BorderStyle to 0 - None set your form WindowState to 2 - Maximized and add this code Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 27 Then Unload Me End If End Sub 27 stands for escape if you press escape it will close your form larrylaffer133 04-12-2005, 07:00 PM Oh awesome. What is the keycode for enter? Is there a keycode list so i can see the codes for all the keys on the keyboard? reboot 04-12-2005, 07:09 PM vbKeyEnter, vbKeyEscape, etc webpsycho 04-12-2005, 07:14 PM you can easily check it by adding a textbox to your form and setting this code to your textbox: Public Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) MsgBox "Key Pressed: " & KeyCode End Sub cool_dude 04-12-2005, 07:19 PM vbKeyEnter, vbKeyEscape, etc this only returns an error If KeyCode = 13 Then Unload Me End If this will do the trick note: 13 is enter button larrylaffer133 04-12-2005, 07:20 PM Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If vbKeyEnter Then Unload Me End If End Sub this isnt working. sorry to be annoying, im just new to this. reboot 04-12-2005, 07:22 PM Sorry, I misspoke. It's vbKeyReturn... And its value is also 13. Constants are better. Learn to use them. cool_dude 04-12-2005, 07:30 PM check this out if you need more key codes use the decimal section for key codes i attached it HardCode 04-12-2005, 08:27 PM Why would you use that list when it goes against reboot's solid advice of using the constants? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vb98/html/vbidxKeyCodeConstants.asp cool_dude 04-12-2005, 09:01 PM aghh.... this is much better than my little sheet thanks for a tip HardCode HardCode 04-12-2005, 09:32 PM It wasn't the content, rather the context :) passel 04-13-2005, 11:00 AM I also believe (don't have VB6 available at the moment), that you could enter the class name, and then start typing in the constant and get a dropdown list of the available identifiers in the class. i.e. If KeyCode = vba.vbkeyr would have a dropdown list with vbKeyR, vbKeyRButton, vbKeyReturn, etc.... The dropdown box should appear as soon as you type the period after vba. HardCode 04-13-2005, 11:22 AM You can do that, too, without the class name. If you type "vbkey" then hit CTRL+J, Intellisense will kick in and filter on any public object/constant/enum that starts with "vbkey". |
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum