By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

run time error '5': invalid procedure call or argument

P: 16
Hi i am working on an application.in where i have to declare a global variable to access a file path of one document and it should be used in different modules.
i declared the global variable and assiged the value to the variable also.

Expand|Select|Wrap|Line Numbers
  1. Global FilePath As String
  2.  
  3. Function getFilePath() As String
  4.     getFilePath = FilePath
  5.     FilePath = "C:\quadyster\R3AgreementDetails"
  6. End Function
But while using the global variable it is showing empty value i was not getting where i made the error please show me some solution to that
Jun 27 '18 #1

✓ answered by twinnyfo

You need to switch lines 4 and 5:

Expand|Select|Wrap|Line Numbers
  1. Public FilePath As String
  2.  
  3. Function getFilePath() As String
  4.     FilePath = "C:\quadyster\R3AgreementDetails"
  5.     getFilePath = FilePath
  6. End Function
Also, I would recommend using the Public statement, rather than Global, as this is a more standard statement.

Share this Question
Share on Google+
3 Replies


twinnyfo
Expert Mod 2.5K+
P: 3,055
You need to switch lines 4 and 5:

Expand|Select|Wrap|Line Numbers
  1. Public FilePath As String
  2.  
  3. Function getFilePath() As String
  4.     FilePath = "C:\quadyster\R3AgreementDetails"
  5.     getFilePath = FilePath
  6. End Function
Also, I would recommend using the Public statement, rather than Global, as this is a more standard statement.
Jun 27 '18 #2

NeoPa
Expert Mod 15k+
P: 31,186
Indeed. In your original code you set getFilePath with FilePath before you'd set FilePath, so it was still an empty string.

Strangely enough, if you'd called it a second time it would have worked ;-)
Jun 27 '18 #3

P: 16
Thanks for the solutions given i made the changes and it is working fine.
Jun 29 '18 #4

Post your reply

Sign in to post your reply or Sign up for a free account.