 |
|

04-12-2005, 06:20 PM
|
|
Freshman
|
|
Join Date: Feb 2005
Posts: 30
|
|
what is Option Explicit
|
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.
|
|

04-12-2005, 06:25 PM
|
 |
Keeper of foo
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
|
|
|
Option Explicit forces you to declare your variables.
|
__________________
~ Quod non mortiferum, fortiorem me facit ~
Avatar by lebb
|

04-12-2005, 06:25 PM
|
|
Ultimate Contributor
|
|
Join Date: Apr 2003
Location: Texas, USA
Posts: 1,623
|
|
|
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.
|
|

04-12-2005, 06:26 PM
|
|
Freshman
|
|
Join Date: Feb 2005
Posts: 30
|
|
|
dont you always need to declare variables though?
|
|

04-12-2005, 06:28 PM
|
 |
Keeper of foo
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
|
|
You should. But Vb doesn't force you to, unless you force it to force you. 
|
__________________
~ Quod non mortiferum, fortiorem me facit ~
Avatar by lebb
|

04-12-2005, 06:32 PM
|
|
Freshman
|
|
Join Date: Feb 2005
Posts: 30
|
|
|
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.
|
|

04-12-2005, 06:34 PM
|
 |
Keeper of foo
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
|
|
|
It's not a command. VB has no 'commands'. And yes, it's very necessary.
|
__________________
~ Quod non mortiferum, fortiorem me facit ~
Avatar by lebb
|

04-12-2005, 06:40 PM
|
|
Freshman
|
|
Join Date: Feb 2005
Posts: 30
|
|
|
im still kind of confused though. why is it necessary, and what about the full screen mode thing.
|
|

04-12-2005, 06:40 PM
|
 |
Senior Contributor
|
|
Join Date: Dec 2003
Location: Columbus, Ohio USA
Posts: 1,129
|
|
Quote:
|
Originally Posted by larrylaffer133
....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.
|
__________________
Did you Google your question before posting it here? Remember, Google is your friend. ;)
|

04-12-2005, 06:43 PM
|
 |
Keeper of foo
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
|
|
|
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.
|
__________________
~ Quod non mortiferum, fortiorem me facit ~
Avatar by lebb
|

04-12-2005, 06:46 PM
|
|
Freshman
|
|
Join Date: Feb 2005
Posts: 30
|
|
|
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.
|
|

04-12-2005, 06:53 PM
|
|
Centurion
|
|
Join Date: Mar 2005
Location: 3rd Rock From The Sun
Posts: 190
|
|
|
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
|
__________________
Signature space for rent.
|

04-12-2005, 07:00 PM
|
|
Freshman
|
|
Join Date: Feb 2005
Posts: 30
|
|
|
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?
|
|

04-12-2005, 07:09 PM
|
 |
Keeper of foo
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
|
|
|
vbKeyEnter, vbKeyEscape, etc
|
__________________
~ Quod non mortiferum, fortiorem me facit ~
Avatar by lebb
|

04-12-2005, 07:14 PM
|
 |
Regular
|
|
Join Date: Apr 2005
Location: The Faroe Islands
Posts: 70
|
|
you can easily check it by adding a textbox to your form and setting this code to your textbox:
Code:
Public Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
MsgBox "Key Pressed: " & KeyCode
End Sub
|
__________________
"Commit Suicide Or Die Trying"
- "What do you give an elephant with diarrhoea?"
- "Lots of space"
|

04-12-2005, 07:19 PM
|
|
Centurion
|
|
Join Date: Mar 2005
Location: 3rd Rock From The Sun
Posts: 190
|
|
Quote:
|
Originally Posted by reboot
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
|
__________________
Signature space for rent.
|

04-12-2005, 07:20 PM
|
|
Freshman
|
|
Join Date: Feb 2005
Posts: 30
|
|
|
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.
|
|

04-12-2005, 07:22 PM
|
 |
Keeper of foo
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
|
|
|
Sorry, I misspoke. It's vbKeyReturn... And its value is also 13. Constants are better. Learn to use them.
|
__________________
~ Quod non mortiferum, fortiorem me facit ~
Avatar by lebb
|

04-12-2005, 07:30 PM
|
|
Centurion
|
|
Join Date: Mar 2005
Location: 3rd Rock From The Sun
Posts: 190
|
|
|
check this out if you need more key codes
use the decimal section for key codes
i attached it
|
__________________
Signature space for rent.
Last edited by cool_dude; 04-12-2005 at 07:33 PM.
Reason: forgot to attach a file :)
|

04-12-2005, 08:27 PM
|
 |
Ultimate Contributor
Forum Leader * Expert *
|
|
Join Date: Feb 2004
Location: New Jersey
Posts: 3,338
|
|
__________________
DON'T CLICK HERE
Useful forum tags: [VB][/VB], [CODE][/CODE], [HTML][/HTML]
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|