Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another issue: Changing one variable instantly changes the value of another variable
#1
I have a short subroutine that takes a path and removes the quotes if the path is enclosed in quotes. It then removes any trailing backslash from the path if one exists.

I was getting some unexpected results, so into debug mode I went to find the problem. As I step through the code one line at a time, I find this problem:

As soon as I execute the line that reads Temp$ = "" not only does Temp$ get set to "" but in that very moment Path$ also gets set to "" (an empty string). For the life of me, I cannot make sense of why this happens.

A few notes:

1) Path$ is not defined outside of this subroutine, so it is local to the subroutine only.

2) Temp$ is DIMed at the start of my program as a SHARED string, so that variable should be available globally.

I apologize for not supplying the full code. The problem is that this is a part of a program almost 15,000 lines long now.

Can anyone give me anything to look for here? I simply cannot see how changing one variable would instantly change another variable as well.



Code: (Select All)
Sub CleanPath (Path$)

    ' Remove quotes and trailing backslash from a path

    ' To use this subroutine: Pass the path to this sub, the sub will return the path
    ' without quotes and a trailing backslash in Temp$.

    Dim x As Integer

    ' start by stripping the quotes

    Temp$ = ""

    For x = 1 To Len(Path$)
        If Mid$(Path$, x, 1) <> Chr$(34) Then
            Temp$ = Temp$ + Mid$(Path$, x, 1)
        End If
    Next x

    ' Remove the trailing backslash, if present

    If Right$(Temp$, 1) = "\" Then
        Temp$ = Left$(Temp$, (Len(Temp$) - 1))
    End If

End Sub
Reply


Messages In This Thread
Another issue: Changing one variable instantly changes the value of another variable - by hanness - 06-17-2022, 02:03 AM



Users browsing this thread: 2 Guest(s)