Length of an if statement in dotnet (migrating from asp to asp.net)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a module that's processed as an include file in a tradtional asp
application that I'm migrating to dotnet.

In one of the modules, there's an if statement that's gotten appended to
over the years it's been in production, that when it's been translated into
dotnet, the if statement (if..... then) itself is several hundred characters
long.

The original statement was similar to:

if session("rpt") = "X1" and (session("user") = "User1" or session("user") =
"User2".....

which has now become

if session("rpt").ToString() = "X1" and (session("user").ToString() =
"User1" or session("user").ToString() = "User2".......

Is there a max length that the if statement can be?

SC
 
Hello jai,

No, but dear God isnt that a maintenance nightmare? Why wouldnt you refactor that as soon as possible?
 
It is somewhat of a maintenance problem, but I wasn't sure if it was the
cause of the problem I'm having.

My reason for not recoding it at this point was if it wasn't a problem (i.e.
the thing that was now breaking the app in dotnet), I didn't want to waste
time fixing it & it not be what was wrong.

If I take out this file from the dotnet application, it will execute; if I
put it in, it will not. The only thing that jumped out to me on this was
the length of the if statement in this module. All the if's and end if's
match up, everything else looks pretty normal.

SC




Matt Berther said:
Hello jai,

No, but dear God isnt that a maintenance nightmare? Why wouldnt you
refactor that as soon as possible?
 
Why don't you tell us what the error is.
I would be surprised if the compiler actually put a limit on this, as then
it wouldn't be such a good compiler.

It is somewhat of a maintenance problem, but I wasn't sure if it was the
cause of the problem I'm having.

My reason for not recoding it at this point was if it wasn't a problem (i.e.
the thing that was now breaking the app in dotnet), I didn't want to waste
time fixing it & it not be what was wrong.

If I take out this file from the dotnet application, it will execute; if I
put it in, it will not. The only thing that jumped out to me on this was
the length of the if statement in this module. All the if's and end if's
match up, everything else looks pretty normal.

SC




Matt Berther said:
Hello jai,

No, but dear God isnt that a maintenance nightmare? Why wouldnt you
refactor that as soon as possible?
 
If the includes are in, I get the error:

"Common Language Runtime detected an invalid program"

When I try to single-step thru the code.

The last line of code I know executes is a response.redirect into the module
that calls the 2nd one as an include file. I cannot even single-step into
the module, before I get that error message.

SC




Marina said:
Why don't you tell us what the error is.
I would be surprised if the compiler actually put a limit on this, as then
it wouldn't be such a good compiler.
 
Are you sure that the problem lies in the IF statement?
if session("rpt").ToString() = "X1" and (session("user").ToString()
"User1" or session("user").ToString() = "User2"......

If yes, you can improve it a little bi
Dim strRpt as string = session("rpt").ToString()
Dim strUser as string = session("user").ToString()
If strRpt = "X1" And (strUser = "User1" Or strUser = "User2" ........ The

Or even you can use Select Case
If strRpt = "X1" The
Select strUse
Case "User1", "User2" ....
........
End Selec
End If
 
Back
Top