PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → [WM22] Variable getting changed, and I'm not sure why.
[WM22] Variable getting changed, and I'm not sure why.
Débuté par Robert, 07 sep. 2017 18:01 - 1 réponse
Posté le 07 septembre 2017 - 18:01
I'm not sure why this is happening, so if anyone can provide some insight, that'd be greatly appreciated.
I have a procedure calling another procedure. And the 2nd procedure is changing the value of a variable in the parent procedure when it shouldn't be.
It's an easy issue to code around. I can use a hold variable to fix it's value, but I'd like to know why this is happening.

I'm not sure how much info is needed to understand what's going on here, so here's pretty much everything.

I have a mobile application that allows users to update info in a SQL database on a server via a web service.
(Procedures listed below.)
One specific procedure takes two input parameters sLocTagNumber and sLocation.
In this procedure, it calls the procedure UpdateTagLocation (which is responsible for actually talking to the web services and updating the information) and passes these two same values to it.

Update tag location uses a different variable name for it's first parameter because in some scenarios, it's possible for UpdateTagLocation() to changes it's internal value for sTagNumber. This is where the problem is happening. It never touches sLocTagNumber in code however.

For example The line SWITCH UpdateTagLocation(sLocTagNumber,sLocation) is sending the value "43326A" for sLocTagNumber.
During UpdateTagLocation() sTagNumber is getting changed from "43326A" to "32114"
When the code comes back out of UpdateTagLocation() back to the switch statement. sLocTagNumber has changed to "32114"

If anyone has any insight on why this is happening. I'd love to know.
Thanks!


Procedure StageTag(sLocTagNumber is string, sLocation is string)

IF sLocTagNumber <> "" AND sLocTagNumber <> 0 AND sLocation <> "" THEN
sLocTagNumber = NoCharacter(sLocTagNumber,CRLF)
// nResSubscript is int
// nResSubscript = ArraySeek(garrStagingLocations,asLinearFirst,NoSpace(Upper(sTagNumber)))
SWITCH UpdateTagLocation(sLocTagNumber,sLocation) //This is where the value is getting changed
CASE 0:
nLoopLocation is int = LooperSeek(ATT_TagNumber,"TAG: " + sLocTagNumber,searchExactMatch)
LOOP_PickData[nLoopLocation].ATT_StageBtnVisible = False
LOOP_PickData[nLoopLocation].ATT_Watermark = True
WIN_MachinePickList.garrTagInfo[ArraySeek(WIN_MachinePickList.garrTagInfo,asLinear,"TagNumber",sLocTagNumber)]:PlantLocation = sLocation
IF InTestMode() = True THEN
Trace("Tag:"+ sLocTagNumber + " staged to " + sLocation)
END
CASE 1:

CASE 2:
Info("""" + sLocTagNumber + """" + " is not a valid location")
OTHER CASE

END
END


Procedure UpdateTagLocation(sTagNumber is string, sLocation is string)
//Blah blah
END
Posté le 08 septembre 2017 - 09:03
Robert avait soumis l'idée :
I'm not sure why this is happening, so if anyone can provide some insight,
that'd be greatly appreciated.
I have a procedure calling another procedure. And the 2nd procedure is
changing the value of a variable in the parent procedure when it shouldn't
be. It's an easy issue to code around. I can use a hold variable to fix it's
value, but I'd like to know why this is happening.

I'm not sure how much info is needed to understand what's going on here, so
here's pretty much everything.

I have a mobile application that allows users to update info in a SQL
database on a server via a web service.
(Procedures listed below.)
One specific procedure takes two input parameters sLocTagNumber and
sLocation.
In this procedure, it calls the procedure UpdateTagLocation (which is
responsible for actually talking to the web services and updating the
information) and passes these two same values to it.

Update tag location uses a different variable name for it's first parameter
because in some scenarios, it's possible for UpdateTagLocation() to changes
it's internal value for sTagNumber. This is where the problem is happening.
It never touches sLocTagNumber in code however.

For example The line SWITCH UpdateTagLocation(sLocTagNumber,sLocation) is
sending the value "43326A" for sLocTagNumber.
During UpdateTagLocation() sTagNumber is getting changed from "43326A" to
"32114"
When the code comes back out of UpdateTagLocation() back to the switch
statement. sLocTagNumber has changed to "32114"

If anyone has any insight on why this is happening. I'd love to know. Thanks!


PROCEDURE StageTag(sLocTagNumber is string, sLocation is string)

IF sLocTagNumber <> "" AND sLocTagNumber <> 0 AND sLocation <> "" THEN
sLocTagNumber = NoCharacter(sLocTagNumber,CRLF)
// nResSubscript is int
// nResSubscript =
ArraySeek(garrStagingLocations,asLinearFirst,NoSpace(Upper(sTagNumber)))
SWITCH UpdateTagLocation(sLocTagNumber,sLocation) //This is where the value
is getting changed
CASE 0:
nLoopLocation is int = LooperSeek(ATT_TagNumber,"TAG: " +
sLocTagNumber,searchExactMatch)
LOOP_PickData[nLoopLocation].ATT_StageBtnVisible = False
LOOP_PickData[nLoopLocation].ATT_Watermark = True
WIN_MachinePickList.garrTagInfo[ArraySeek(WIN_MachinePickList.garrTagInfo,asLinear,"TagNumber",sLocTagNumber)]:PlantLocation
= sLocation
IF InTestMode() = True THEN
Trace("Tag:"+ sLocTagNumber + " staged to " + sLocation)
END
CASE 1:

CASE 2:
Info("""" + sLocTagNumber + """" + " is not a valid location")
OTHER CASE

END
END


PROCEDURE UpdateTagLocation(sTagNumber is string, sLocation is string)
//Blah blah
End


hello

the answer is there :
http://doc.windev.com/en-US/…

Passing parameters by address vs Passing parameters by values

--
Cordialement JeAn-PhI