Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Defining variables

Hi

I have few variables which have default value of 0. This value will change
during macro execution. Is there any way to declare 0 value to these
variables while defining those at the beginning of the code? Means when we
define variable as Dim cnt as integer, can I define 0 value there itself?

Thank You


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Defining variables

Hi,

When you dim your variable by default it is set as nothing which for an
integer variable is the same as zero which can be demonstrated with this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so cnt was zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This value will change
during macro execution. Is there any way to declare 0 value to these
variables while defining those at the beginning of the code? Means when we
define variable as Dim cnt as integer, can I define 0 value there itself?

Thank You


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Defining variables

This is correct. Here by 0 I want to say any value. Means suppose if I want
to assign default value of 2 (or any other value) to my variable, then is
there any way to assign it when we declare the variable? We can assign it in
separate statement like cnt = 2, but I want to assign it I at the same time
we declare the variable.

Thank You

"Mike H" wrote:

Hi,

When you dim your variable by default it is set as nothing which for an
integer variable is the same as zero which can be demonstrated with this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so cnt was zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This value will change
during macro execution. Is there any way to declare 0 value to these
variables while defining those at the beginning of the code? Means when we
define variable as Dim cnt as integer, can I define 0 value there itself?

Thank You


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Defining variables

AFAIK there's no way to do that in a single line, you must dim your variable
and can then define a value for it

Dim cnt As Integer
cnt = 6

Mike

"Pawan" wrote:

This is correct. Here by 0 I want to say any value. Means suppose if I want
to assign default value of 2 (or any other value) to my variable, then is
there any way to assign it when we declare the variable? We can assign it in
separate statement like cnt = 2, but I want to assign it I at the same time
we declare the variable.

Thank You

"Mike H" wrote:

Hi,

When you dim your variable by default it is set as nothing which for an
integer variable is the same as zero which can be demonstrated with this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so cnt was zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This value will change
during macro execution. Is there any way to declare 0 value to these
variables while defining those at the beginning of the code? Means when we
define variable as Dim cnt as integer, can I define 0 value there itself?

Thank You


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Defining variables

Ok. Thanks Mike

"Mike H" wrote:

AFAIK there's no way to do that in a single line, you must dim your variable
and can then define a value for it

Dim cnt As Integer
cnt = 6

Mike

"Pawan" wrote:

This is correct. Here by 0 I want to say any value. Means suppose if I want
to assign default value of 2 (or any other value) to my variable, then is
there any way to assign it when we declare the variable? We can assign it in
separate statement like cnt = 2, but I want to assign it I at the same time
we declare the variable.

Thank You

"Mike H" wrote:

Hi,

When you dim your variable by default it is set as nothing which for an
integer variable is the same as zero which can be demonstrated with this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so cnt was zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This value will change
during macro execution. Is there any way to declare 0 value to these
variables while defining those at the beginning of the code? Means when we
define variable as Dim cnt as integer, can I define 0 value there itself?

Thank You




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Defining variables

The only way that you can combine a dim and non-empty value is declaring an
optional parameter within a routine ie Optional 'variable' as integer = 3.

It would be a nice feature if it combined into a standalone Dim statement

Good luck

--
Ken
"Using Dbase dialects since 82"
"Started with Visicalc in the same year"


"Pawan" wrote:

Ok. Thanks Mike

"Mike H" wrote:

AFAIK there's no way to do that in a single line, you must dim your variable
and can then define a value for it

Dim cnt As Integer
cnt = 6

Mike

"Pawan" wrote:

This is correct. Here by 0 I want to say any value. Means suppose if I want
to assign default value of 2 (or any other value) to my variable, then is
there any way to assign it when we declare the variable? We can assign it in
separate statement like cnt = 2, but I want to assign it I at the same time
we declare the variable.

Thank You

"Mike H" wrote:

Hi,

When you dim your variable by default it is set as nothing which for an
integer variable is the same as zero which can be demonstrated with this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so cnt was zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This value will change
during macro execution. Is there any way to declare 0 value to these
variables while defining those at the beginning of the code? Means when we
define variable as Dim cnt as integer, can I define 0 value there itself?

Thank You


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Defining variables

You can put two logical lines on a single physical line like this:

Dim myConst as Long: myConst = 12

Personally, I would find this more difficult to read. (Maybe it's just me.)

Pawan wrote:

This is correct. Here by 0 I want to say any value. Means suppose if I want
to assign default value of 2 (or any other value) to my variable, then is
there any way to assign it when we declare the variable? We can assign it in
separate statement like cnt = 2, but I want to assign it I at the same time
we declare the variable.

Thank You

"Mike H" wrote:

Hi,

When you dim your variable by default it is set as nothing which for an
integer variable is the same as zero which can be demonstrated with this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so cnt was zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This value will change
during macro execution. Is there any way to declare 0 value to these
variables while defining those at the beginning of the code? Means when we
define variable as Dim cnt as integer, can I define 0 value there itself?

Thank You



--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Defining variables

It is not just you... I find that hard to read also. Plus, you are not
really saving anything significant be doing it this way either... it is
still two separate statements.

--
Rick (MVP - Excel)


"Dave Peterson" wrote in message
...
You can put two logical lines on a single physical line like this:

Dim myConst as Long: myConst = 12

Personally, I would find this more difficult to read. (Maybe it's just
me.)

Pawan wrote:

This is correct. Here by 0 I want to say any value. Means suppose if I
want
to assign default value of 2 (or any other value) to my variable, then is
there any way to assign it when we declare the variable? We can assign it
in
separate statement like cnt = 2, but I want to assign it I at the same
time
we declare the variable.

Thank You

"Mike H" wrote:

Hi,

When you dim your variable by default it is set as nothing which for an
integer variable is the same as zero which can be demonstrated with
this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so cnt was
zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This value will
change
during macro execution. Is there any way to declare 0 value to these
variables while defining those at the beginning of the code? Means
when we
define variable as Dim cnt as integer, can I define 0 value there
itself?

Thank You



--

Dave Peterson


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Defining variables

Actually, when the code is simple, I do use multiple logical lines on a single
physical line:

Select case something
case is = aaa : somethingelse = 5
case is = bbb : somethingelse = 6
case is = ccc : somethingelse = 7
case is = ddd : somethingelse = 8
End select

But, again, it's a personal preference.

Rick Rothstein wrote:

It is not just you... I find that hard to read also. Plus, you are not
really saving anything significant be doing it this way either... it is
still two separate statements.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
You can put two logical lines on a single physical line like this:

Dim myConst as Long: myConst = 12

Personally, I would find this more difficult to read. (Maybe it's just
me.)

Pawan wrote:

This is correct. Here by 0 I want to say any value. Means suppose if I
want
to assign default value of 2 (or any other value) to my variable, then is
there any way to assign it when we declare the variable? We can assign it
in
separate statement like cnt = 2, but I want to assign it I at the same
time
we declare the variable.

Thank You

"Mike H" wrote:

Hi,

When you dim your variable by default it is set as nothing which for an
integer variable is the same as zero which can be demonstrated with
this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so cnt was
zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This value will
change
during macro execution. Is there any way to declare 0 value to these
variables while defining those at the beginning of the code? Means
when we
define variable as Dim cnt as integer, can I define 0 value there
itself?

Thank You



--

Dave Peterson


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Defining variables

Yes, I think I remember you posting code like that in the past... I didn't
find it easy to read either.<g

Just for accuracy sake, the VB editor will not allow you to space the colon
away from the statement in front of it like you show.... the editor will
move the colon so that it is adjacent to the statement in front of it which
is one of the things that make these kinds of code lines hard to read in my
opinion.

--
Rick (MVP - Excel)


"Dave Peterson" wrote in message
...
Actually, when the code is simple, I do use multiple logical lines on a
single
physical line:

Select case something
case is = aaa : somethingelse = 5
case is = bbb : somethingelse = 6
case is = ccc : somethingelse = 7
case is = ddd : somethingelse = 8
End select

But, again, it's a personal preference.

Rick Rothstein wrote:

It is not just you... I find that hard to read also. Plus, you are not
really saving anything significant be doing it this way either... it is
still two separate statements.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
You can put two logical lines on a single physical line like this:

Dim myConst as Long: myConst = 12

Personally, I would find this more difficult to read. (Maybe it's just
me.)

Pawan wrote:

This is correct. Here by 0 I want to say any value. Means suppose if I
want
to assign default value of 2 (or any other value) to my variable, then
is
there any way to assign it when we declare the variable? We can assign
it
in
separate statement like cnt = 2, but I want to assign it I at the same
time
we declare the variable.

Thank You

"Mike H" wrote:

Hi,

When you dim your variable by default it is set as nothing which for
an
integer variable is the same as zero which can be demonstrated with
this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so cnt
was
zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This value
will
change
during macro execution. Is there any way to declare 0 value to
these
variables while defining those at the beginning of the code? Means
when we
define variable as Dim cnt as integer, can I define 0 value there
itself?

Thank You



--

Dave Peterson


--

Dave Peterson




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Defining variables

Actually, the VBE will allow me to enter it that way--it just won't keep it that
way.

I left the additional spaces for readability in the newsgroup post.



Rick Rothstein wrote:

Yes, I think I remember you posting code like that in the past... I didn't
find it easy to read either.<g

Just for accuracy sake, the VB editor will not allow you to space the colon
away from the statement in front of it like you show.... the editor will
move the colon so that it is adjacent to the statement in front of it which
is one of the things that make these kinds of code lines hard to read in my
opinion.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
Actually, when the code is simple, I do use multiple logical lines on a
single
physical line:

Select case something
case is = aaa : somethingelse = 5
case is = bbb : somethingelse = 6
case is = ccc : somethingelse = 7
case is = ddd : somethingelse = 8
End select

But, again, it's a personal preference.

Rick Rothstein wrote:

It is not just you... I find that hard to read also. Plus, you are not
really saving anything significant be doing it this way either... it is
still two separate statements.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
You can put two logical lines on a single physical line like this:

Dim myConst as Long: myConst = 12

Personally, I would find this more difficult to read. (Maybe it's just
me.)

Pawan wrote:

This is correct. Here by 0 I want to say any value. Means suppose if I
want
to assign default value of 2 (or any other value) to my variable, then
is
there any way to assign it when we declare the variable? We can assign
it
in
separate statement like cnt = 2, but I want to assign it I at the same
time
we declare the variable.

Thank You

"Mike H" wrote:

Hi,

When you dim your variable by default it is set as nothing which for
an
integer variable is the same as zero which can be demonstrated with
this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so cnt
was
zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This value
will
change
during macro execution. Is there any way to declare 0 value to
these
variables while defining those at the beginning of the code? Means
when we
define variable as Dim cnt as integer, can I define 0 value there
itself?

Thank You



--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Defining variables

I left the additional spaces for readability

That proves the point. It isn't that easy on the eye.

RBS


"Dave Peterson" wrote in message
...
Actually, the VBE will allow me to enter it that way--it just won't keep
it that
way.

I left the additional spaces for readability in the newsgroup post.



Rick Rothstein wrote:

Yes, I think I remember you posting code like that in the past... I
didn't
find it easy to read either.<g

Just for accuracy sake, the VB editor will not allow you to space the
colon
away from the statement in front of it like you show.... the editor will
move the colon so that it is adjacent to the statement in front of it
which
is one of the things that make these kinds of code lines hard to read in
my
opinion.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
Actually, when the code is simple, I do use multiple logical lines on a
single
physical line:

Select case something
case is = aaa : somethingelse = 5
case is = bbb : somethingelse = 6
case is = ccc : somethingelse = 7
case is = ddd : somethingelse = 8
End select

But, again, it's a personal preference.

Rick Rothstein wrote:

It is not just you... I find that hard to read also. Plus, you are not
really saving anything significant be doing it this way either... it
is
still two separate statements.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
You can put two logical lines on a single physical line like this:

Dim myConst as Long: myConst = 12

Personally, I would find this more difficult to read. (Maybe it's
just
me.)

Pawan wrote:

This is correct. Here by 0 I want to say any value. Means suppose
if I
want
to assign default value of 2 (or any other value) to my variable,
then
is
there any way to assign it when we declare the variable? We can
assign
it
in
separate statement like cnt = 2, but I want to assign it I at the
same
time
we declare the variable.

Thank You

"Mike H" wrote:

Hi,

When you dim your variable by default it is set as nothing which
for
an
integer variable is the same as zero which can be demonstrated
with
this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so cnt
was
zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This value
will
change
during macro execution. Is there any way to declare 0 value to
these
variables while defining those at the beginning of the code?
Means
when we
define variable as Dim cnt as integer, can I define 0 value
there
itself?

Thank You



--

Dave Peterson

--

Dave Peterson


--

Dave Peterson


  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Defining variables

Actually, I find this code:

Select Case something
Case Is = aaa: somethingelse = 5
Case Is = bbb: somethingelse = 6
Case Is = ccc: somethingelse = 7
Case Is = ddd: somethingelse = 8
End Select

easier on the eye than:

Select Case something
Case Is = aaa
somethingelse = 5
Case Is = bbb
somethingelse = 6
Case Is = ccc
somethingelse = 7
Case Is = ddd
somethingelse = 8
End Select



RB Smissaert wrote:

I left the additional spaces for readability


That proves the point. It isn't that easy on the eye.

RBS

"Dave Peterson" wrote in message
...
Actually, the VBE will allow me to enter it that way--it just won't keep
it that
way.

I left the additional spaces for readability in the newsgroup post.



Rick Rothstein wrote:

Yes, I think I remember you posting code like that in the past... I
didn't
find it easy to read either.<g

Just for accuracy sake, the VB editor will not allow you to space the
colon
away from the statement in front of it like you show.... the editor will
move the colon so that it is adjacent to the statement in front of it
which
is one of the things that make these kinds of code lines hard to read in
my
opinion.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
Actually, when the code is simple, I do use multiple logical lines on a
single
physical line:

Select case something
case is = aaa : somethingelse = 5
case is = bbb : somethingelse = 6
case is = ccc : somethingelse = 7
case is = ddd : somethingelse = 8
End select

But, again, it's a personal preference.

Rick Rothstein wrote:

It is not just you... I find that hard to read also. Plus, you are not
really saving anything significant be doing it this way either... it
is
still two separate statements.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
You can put two logical lines on a single physical line like this:

Dim myConst as Long: myConst = 12

Personally, I would find this more difficult to read. (Maybe it's
just
me.)

Pawan wrote:

This is correct. Here by 0 I want to say any value. Means suppose
if I
want
to assign default value of 2 (or any other value) to my variable,
then
is
there any way to assign it when we declare the variable? We can
assign
it
in
separate statement like cnt = 2, but I want to assign it I at the
same
time
we declare the variable.

Thank You

"Mike H" wrote:

Hi,

When you dim your variable by default it is set as nothing which
for
an
integer variable is the same as zero which can be demonstrated
with
this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so cnt
was
zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This value
will
change
during macro execution. Is there any way to declare 0 value to
these
variables while defining those at the beginning of the code?
Means
when we
define variable as Dim cnt as integer, can I define 0 value
there
itself?

Thank You



--

Dave Peterson

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Defining variables

Yes, that doesn't look bad actually.
Then again there are situations where it definitely looks bad and maybe it
is best
for consistency to never use it then.
All a matter of taste.

RBS

"Dave Peterson" wrote in message
...
Actually, I find this code:

Select Case something
Case Is = aaa: somethingelse = 5
Case Is = bbb: somethingelse = 6
Case Is = ccc: somethingelse = 7
Case Is = ddd: somethingelse = 8
End Select

easier on the eye than:

Select Case something
Case Is = aaa
somethingelse = 5
Case Is = bbb
somethingelse = 6
Case Is = ccc
somethingelse = 7
Case Is = ddd
somethingelse = 8
End Select



RB Smissaert wrote:

I left the additional spaces for readability


That proves the point. It isn't that easy on the eye.

RBS

"Dave Peterson" wrote in message
...
Actually, the VBE will allow me to enter it that way--it just won't
keep
it that
way.

I left the additional spaces for readability in the newsgroup post.



Rick Rothstein wrote:

Yes, I think I remember you posting code like that in the past... I
didn't
find it easy to read either.<g

Just for accuracy sake, the VB editor will not allow you to space the
colon
away from the statement in front of it like you show.... the editor
will
move the colon so that it is adjacent to the statement in front of it
which
is one of the things that make these kinds of code lines hard to read
in
my
opinion.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
Actually, when the code is simple, I do use multiple logical lines
on a
single
physical line:

Select case something
case is = aaa : somethingelse = 5
case is = bbb : somethingelse = 6
case is = ccc : somethingelse = 7
case is = ddd : somethingelse = 8
End select

But, again, it's a personal preference.

Rick Rothstein wrote:

It is not just you... I find that hard to read also. Plus, you are
not
really saving anything significant be doing it this way either...
it
is
still two separate statements.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
You can put two logical lines on a single physical line like
this:

Dim myConst as Long: myConst = 12

Personally, I would find this more difficult to read. (Maybe
it's
just
me.)

Pawan wrote:

This is correct. Here by 0 I want to say any value. Means
suppose
if I
want
to assign default value of 2 (or any other value) to my
variable,
then
is
there any way to assign it when we declare the variable? We can
assign
it
in
separate statement like cnt = 2, but I want to assign it I at
the
same
time
we declare the variable.

Thank You

"Mike H" wrote:

Hi,

When you dim your variable by default it is set as nothing
which
for
an
integer variable is the same as zero which can be
demonstrated
with
this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so
cnt
was
zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This
value
will
change
during macro execution. Is there any way to declare 0 value
to
these
variables while defining those at the beginning of the code?
Means
when we
define variable as Dim cnt as integer, can I define 0 value
there
itself?

Thank You



--

Dave Peterson

--

Dave Peterson

--

Dave Peterson


--

Dave Peterson


  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Defining variables

For the most part, I agree with you. Well, except for the parts that I don't
<vbg.

(Lack of consistency doesn't bother me that much.)

RB Smissaert wrote:

Yes, that doesn't look bad actually.
Then again there are situations where it definitely looks bad and maybe it
is best
for consistency to never use it then.
All a matter of taste.

RBS

"Dave Peterson" wrote in message
...
Actually, I find this code:

Select Case something
Case Is = aaa: somethingelse = 5
Case Is = bbb: somethingelse = 6
Case Is = ccc: somethingelse = 7
Case Is = ddd: somethingelse = 8
End Select

easier on the eye than:

Select Case something
Case Is = aaa
somethingelse = 5
Case Is = bbb
somethingelse = 6
Case Is = ccc
somethingelse = 7
Case Is = ddd
somethingelse = 8
End Select



RB Smissaert wrote:

I left the additional spaces for readability

That proves the point. It isn't that easy on the eye.

RBS

"Dave Peterson" wrote in message
...
Actually, the VBE will allow me to enter it that way--it just won't
keep
it that
way.

I left the additional spaces for readability in the newsgroup post.



Rick Rothstein wrote:

Yes, I think I remember you posting code like that in the past... I
didn't
find it easy to read either.<g

Just for accuracy sake, the VB editor will not allow you to space the
colon
away from the statement in front of it like you show.... the editor
will
move the colon so that it is adjacent to the statement in front of it
which
is one of the things that make these kinds of code lines hard to read
in
my
opinion.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
Actually, when the code is simple, I do use multiple logical lines
on a
single
physical line:

Select case something
case is = aaa : somethingelse = 5
case is = bbb : somethingelse = 6
case is = ccc : somethingelse = 7
case is = ddd : somethingelse = 8
End select

But, again, it's a personal preference.

Rick Rothstein wrote:

It is not just you... I find that hard to read also. Plus, you are
not
really saving anything significant be doing it this way either...
it
is
still two separate statements.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
You can put two logical lines on a single physical line like
this:

Dim myConst as Long: myConst = 12

Personally, I would find this more difficult to read. (Maybe
it's
just
me.)

Pawan wrote:

This is correct. Here by 0 I want to say any value. Means
suppose
if I
want
to assign default value of 2 (or any other value) to my
variable,
then
is
there any way to assign it when we declare the variable? We can
assign
it
in
separate statement like cnt = 2, but I want to assign it I at
the
same
time
we declare the variable.

Thank You

"Mike H" wrote:

Hi,

When you dim your variable by default it is set as nothing
which
for
an
integer variable is the same as zero which can be
demonstrated
with
this bit
of code

Dim cnt As Integer
MsgBox cnt + 10

If you try this you will find the message box displays 10 so
cnt
was
zero

Mike

"Pawan" wrote:

Hi

I have few variables which have default value of 0. This
value
will
change
during macro execution. Is there any way to declare 0 value
to
these
variables while defining those at the beginning of the code?
Means
when we
define variable as Dim cnt as integer, can I define 0 value
there
itself?

Thank You



--

Dave Peterson

--

Dave Peterson

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining a Range using Variables Billyruben Excel Discussion (Misc queries) 3 December 2nd 08 06:31 PM
Defining Variables with Same Name in Different Worksheets mhyzak Excel Discussion (Misc queries) 1 May 3rd 07 10:25 PM
VBA defining variables Jeff Excel Discussion (Misc queries) 2 November 3rd 05 11:33 PM
solver and defining all variables different than one another excel_excel_excel Excel Discussion (Misc queries) 0 July 19th 05 07:38 AM
Defining Variables that pass to other Subs JasonSelf[_14_] Excel Programming 2 August 11th 04 08:57 PM


All times are GMT +1. The time now is 06:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"