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.:)
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

820 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