Problem with the line

Hi,
I don't know why I have got the error (Shown in Fig 1)

to the last line below?
Sub Validate_repre_code(msg As String, para_code As String, para_fnd As Boolean)
    Dim local_rw As Integer
    
    ...
End Sub
        
    Dim fnd_repre As Boolean, repre_code As String, chk_msg As String
    ...
                repre_code = Cells(rw_kp + 1, 11).Value
                chk_msg = ""
                Validate_repre_code chk_msg, repre_code, fnd_repre
                ...

Open in new window


The previous codes are working fine, while I've just added the above codes to the existing ones. Once I've remarked the above line in error, the whole process again is working fine. Why?
t510.png
LVL 11
HuaMin ChenSystem AnalystAsked:
Who is Participating?
 
HuaMin ChenConnect With a Mentor System AnalystAuthor Commented:
Thanks. I did change the way to not to pass any string to a subroutine. Then it works as expected.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
have tested the code snippet as you posted it, and it works just fine.

the only reason I know you will get this error is when chk_msg is NOT defined as string.

please make sure you don't have that variable DIMed somewhere else with other data type.
0
 
HuaMin ChenSystem AnalystAuthor Commented:
Thanks.
Within the whole process, chk_msg is NOT DIMed elsewhere.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
how big is the project / makro?
the only other explanation is that you are missing a project reference...
or that the 2 lines
chk_msg = ""
                Validate_repre_code chk_msg, repre_code, fnd_repre

Open in new window

are before the line which dim's the chk_msg.
do you have OPTION EXPLICIT on the first line of the code ?
0
 
HuaMin ChenSystem AnalystAuthor Commented:
Yes, it is VBA macro.

chk_msg has been DIMed before these 2 lines.

chk_msg = ""
                Validate_repre_code chk_msg, repre_code, fnd_repre

Open in new window


I don't have OPTION EXPLICIT in the whole macro.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>I don't have OPTION EXPLICIT in the whole macro.
please add that line as first line in the marco, and run the compile.

did you check the project => references?

otherwise, can you attach the project file with "reduced" code but still with the issue?
0
 
HuaMin ChenSystem AnalystAuthor Commented:
After I've put the line like (shown in Fig 2)

I get the current error shown in Fig 2. Why?
t513.png
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
first line of the MAKRO, no of the procedure/sub.
it has to be the TOP LINE of your code page
0
 
HuaMin ChenSystem AnalystAuthor Commented:
But now I get this (shown in Fig 3), while I've DIMed the variable already.
t515.png
0
 
HuaMin ChenSystem AnalystAuthor Commented:
Please help. thanks
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this error is self-explaining.
you don't declare that variable anywhere ...
0
 
TommySzalapskiCommented:
The Option Explicit that you added is going to make you go back and Dim every variable that you haven't.
Expect several of those errors, but when you get them all cleaned up, you may just find the original issue and solve it.
0
 
HuaMin ChenSystem AnalystAuthor Commented:
Sorry, after having put that, I am still getting the same problem
t516.png
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
please upload the file.
otherwise I cannot "see" deeper
0
 
HuaMin ChenSystem AnalystAuthor Commented:
I resolved this already
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.