Retaining a value

Posted on 2014-10-09
Last Modified: 2014-10-09
I use the code below to determine a value, however later in the procedure I would like to use it again and the value is empty?  Is there a way to make this a global value so it is not lost?  Or a way to carry the value from one procedure to another?  Trying to determine just where I am losing it.

session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").Text = strValidMatlNum
Question by:RWayneH
  • 3
  • 2
LVL 27

Accepted Solution

Glenn Ray earned 500 total points
ID: 40371469
You could declare strValidMatlNum as a Global variable (added outside your subroutine).  This will allow the value to be used in all modules:
Option Explicit
Global strValidMatlNum as String

Sub subroutine()
End Sub

Open in new window

Be sure you don't have other declarations for the same variable name elsewhere.  I will sometimes create a module exclusively for global variables.


Author Comment

ID: 40371675
It worked!!  Thanks... but if some reason I could not use Ln1?  I made the procedure stop at places were I was setting a variable to Y or X...  different one..  After I commented that out it worked.  Any thoughts on the Ln 1
LVL 33

Expert Comment

ID: 40371692

You should always use Option Explicit as it helps you find undeclared variables, and you should always declare your variables.:)
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

LVL 27

Expert Comment

by:Glenn Ray
ID: 40371727
^ What imnorie said.    If you add the Option Explicit and then do a compile (VBA menu: Debug - Compile VBA Project) you'll be alerted to any/all undeclared variables.


Author Closing Comment

ID: 40371774
Thanks for the help.
LVL 27

Expert Comment

by:Glenn Ray
ID: 40371778
You're welcome.

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question