No announcement yet.

How to clear the contents of a variable

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to clear the contents of a variable

    I am using a search script, which searches for an mp3, and then displays it in a listbox. The problem is that all searches after that display the names of the files I found the first time, as well as those of the second search in the list box. The end result is a bunch of the same names over and over again.
    How do I clear a variable, or overwrite the previous one?

  • #2
    Re: How to clear the contents of a variable

    You could use the set variable action and set the variable to "" or nothing to clear it.

    Remember that the listbox will keep appending data when you add to it. If the listbox had the search results in it already, your second search will append to the existing search. If that isn't the result you are looking for. Clear the list box before each search with a ListBoxObject[ListBox1].Remove (All) action.


    • #3
      Re: How to clear the contents of a variable

      Although I'm not sure which variable I'm working with(newbie) I have tried to do what you said with all of the custom variables, and it hasn't worked. I put that "set variable" action right at the beginning of my search button action list, and I have had no success. Also, using the listbox remove all option does clear the listbox, but they come back again when the results are displayed. This is a bit better, as there are then no doubles of filenames, but I have a remove button, to remove songs that were found that I don't want to hear, and they also come back. The code I am using is on this forum at

      If you can find out what I'm dealing with here, thank-you in advance [img]/ubbthreads/images/icons/smile.gif[/img]


      • #4
        Re: How to clear the contents of a variable

        From what I see, you are using a Global List named "files". Each time you search you are adding the search results to the list, then adding the contents of the entire global list to the listbox. Therefore your listbox keeps its existing files and then adds the contents of all your searches again.

        If you want the listbox to show only the contents of the most current search you need to do two things.

        1. Before the While loop in the "search button", clear the global list to start with a clean list

        2. Clear the listbox before adding your search results.

        Here's what the code would look like:
        %ObjectText% = EditFieldObject[EditField1].GetText
        %Files% = File.Search ("*%ObjectText%*.mp3", CustomPaths)
        %FileCount% = String.CountDelimitedStrings ("%Files%", ";;")
        %w% = "0"
        GlobalList[files].Remove (All)
        WHILE (%w% <= %FileCount%)
        %Full_Path% = String.GetDelimitedString ("%Files%", ";;", %w%)
        %Filename% = String.ParsePath ("%Full_Path%", Filename)
        GlobalList[files].Add (End, "%Filename%")
        %w% = Evaluate (%w% + 1)
        END WHILE
        ListBoxObject[ListBox1].Remove (All)
        %ListItem% = GlobalList[files].GetItem (All)
        ListBoxObject[ListBox1].Add (End, "%ListItem%")


        • #5
          Re: How to clear the contents of a variable

          Thanks! [img]/ubbthreads/images/icons/smile.gif[/img]
          It worked perfectly, and I feel like an idiot. I tried what you said before, and I spent hours trying to fiddle around with the variables, and I even remember thinking "it must have something to do with this global list thing", but as I was staying up all night, my brain simply forgot to explore that path......