excel vb question

  • Thread starter Thread starter Darryl
  • Start date Start date
D

Darryl

Greetings,
I am writing some vb code in excel (version that comes with Office 2000).

I am a programmer, and really haven't dealt with excel before.

If I define a public variable on the workbook, can I initialize it at
definition ?

ie,
public test as integer init 0

How do I initialize the variable (or determine it needs initialization)
before using it ?

thanks,
-D
 
Darryl,

You can use a constant

Public Const test As Integer = 0

of course, that stops you changing it later.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Sorry I wasn't very clear.
I need it to be a variable as I'm going to increment it as I do
certain things.
 
Then you can't initialise is as you thought. What you can do is something
like this

Public test As Variant

Sub myCode()

If IsEmpty(test) Then
test = 0
End If
'rest of code

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
OK.
If I define a variable that is integer, is it automatically initialized to 0
or can
it be any old garbage ?

I'm going to keep adding 1 to the variable each time a button is pressed and
I don't want to do something like
test = test +1
if test is garbage.

thanks,
D

I assume that IsEmpty only works with variant type variables ?
 
Yes, an integer initialises to 0 every time.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top