Avatar of Cook09
Cook09Flag for United States of America asked on

Initialize Variables from the Declaration

Is there a way to initialize a variable as it is being declared?  In a number of cases the variable needs to be reset.  It seems that there was some method for performing a:

Dim i As Integer = 0, but the different ways attempted all end up with a compile error:
      Expected: end of statement

So it seems that there may not be a way to do this, but thought it prudent to ask the Experts prior to using another method.

Microsoft Excel

Avatar of undefined
Last Comment

8/22/2022 - Mon

You can declare something as a constant, e.g.
Const i As Integer = 0

Open in new window

By the way the defaul value of an integer will be zero. Not sure what you are trying to achieve anyway.
Patrick Matthews

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

Appreciated Matthew for advising that it really couldn't be done in VBA.  Found Patrick's response as a comprehensive solution to initialize or reset whatever variables that may need to be "cleaned out", even during the course of a project.


Ron - Thanks for the grade and points - Patrick
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

You have always provided me usable solutions and this is another example...so thank you.