• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Newbies questions part1.

Hi Expert,

Q1: Why some people places a "exit sub" when there's no error management... is it faster?
ex.: private sub BilyBob()
           exit sub <----
      end sub

Q2: what means "&Hxx"
ex.: Const KEY_SET_VALUE = &H2 or Const SWP_HIDEWINDOW = &H80 or Const TOTO = &0, etc.

Dim lTest as Long
lTest& = Clng(number)  -> why the "&" after the variable?

thks for all...


1 Solution
Hi m_renaud,

The protocol of this site is against asking multiple questions within a single thread so you are better off asking seperate questions in future.

1) Doesn't have to be based on error management, you may want to exit a sub or function earlier in your code based on some condition or other. For instance if a certain variable holds a certain value you may want to exit the sub rather than carry on processing. Of course this can almost always be handled by restructuring the code!

2) &Hnn means it is a hexadecimal number for example &Hff is the number represented by FF in hexadecimal, namely 255

3) & at the end of a variable explicitly defines it as a long integer, variable$ would be a string, variable% an integer and there are others. This is partly a backwards compatibility issue and also partly because it is useful at times to explicitly type a variable or value in an api call.

Tim Cottee
Brainbench MVP for Visual Basic
1) no it is no faster and some people will argue it is bad practise

2)&Hxx is a xex value

3)lTest& is a shortcut way of saying the variable is a long like
dim l& would be typed as long
Q1 - Exit sub

Could be several things.  
Personal preference, habit, or the way they were trained
Error handling code has been removed
Coding standard

Q2 - &Hxx
VB - & declares the value as a LONG
C - &H - Hex number

Q3 - & after
VB - Declares it as a long.

m_renaudAuthor Commented:
Hi TimCottee,

it was 3 littles questions... i did not believe them enough important to make three questions...
next time i'll pay attention...

thks for answers


Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now