
-----------------------------------
Musta
Wed Jan 16, 2013 8:00 pm

Display .mp3 names in GUI.CreateTextboxChoice
-----------------------------------
What is it you are trying to achieve?



What is the problem you are having?



Describe what you have tried to solve this problem
 0
loop
    exit when eof (fileNo)

    get : fileNo, adder (x + 1)
    x := x + 1
end loop
close : fileNo
var playsongname : string
var streamNumber, file : int
var fileName : string
streamNumber := Dir.Open (".")
assert streamNumber > 0
open : fileNo, "songnames", put
loop
    fileName := Dir.Get (streamNumber)
    exit when fileName = ""
    put : fileNo, fileName
end loop
Dir.Close (streamNumber)
put "These are the optional songs to play that you have imported!"
for w : 3 .. (x - 3)
    % if adder (w) *  "3" then
        put adder (w)
    % else
    % end if
end for
put ""
put "What song would you like to play?"
get playsongname
process playmusic
    loop
        Music.PlayFile (playsongname)
    end loop
end playmusic
fork playmusic


[/code]

(Put sound file in same directory as saved example then just run)

How would I go about having an if statement, that would use string manipulation to determine if a line in the text file it reads ends with .mp3?

I have it so that it reads from the text file and (used to) skip a few items that weren't songs (hence the for loop "w" starting at 3 and going to x-3). Now with a ton of songs it doesn't skip them properly, so I'll have to use an if statement or something to only show them on the screen if it ends in .mp3, or at least a 3 using an *.

-----------------------------------
Tony
Thu Jan 17, 2013 8:40 pm

RE:Display .mp3 names in GUI.CreateTextboxChoice
-----------------------------------
you can select just a part of a string. [tdoc]substring[/tdoc]

-----------------------------------
Musta
Thu Jan 17, 2013 9:05 pm

Re: RE:Display .mp3 names in GUI.CreateTextboxChoice
-----------------------------------
you can select just a part of a string. 

But how would I even use that in an if statement?

[code]
for w : 3 .. (x)
     if adder (w) (*..*-2) = "mp3" then
        put adder (w)
     else
     end if
end for
[/code] 
* being last, *-2 being the last three, equaling "mp3", sounds like it works, just doesn't. I don't know how to do this properly.

Edit: Durr, put the things backwards. Still doesn't work though.

-----------------------------------
Tony
Thu Jan 17, 2013 9:32 pm

RE:Display .mp3 names in GUI.CreateTextboxChoice
-----------------------------------
what is it actually though?
[code]
if adder (w) (*..*-2) = "mp3" then 
        put adder (w) 
     else 
        put "not mp3. Found: ", adder (w) (*..*-2)
     end if 
[/code]

-----------------------------------
Musta
Thu Jan 17, 2013 9:41 pm

Re: RE:Display .mp3 names in GUI.CreateTextboxChoice
-----------------------------------
what is it actually though?


I scan the directory and save all of the files onto a text file. Then I open the text file and display all of the objects on the screen, allowing the user to see the choices they can select.

This part right here is the "put" part, "adder" is an array, "adder(1)" is line 1 in the text file, "adder(2)" is line 2 etc.

So instead of putting every line (Which includes the program's name itself, the text file's name etc.), I'm trying to get it to only put files that end in "mp3" on the screen.

That "Not MP3" part works I guess, but it would be nice to just not show them at all

-----------------------------------
Tony
Fri Jan 18, 2013 1:39 pm

RE:Display .mp3 names in GUI.CreateTextboxChoice
-----------------------------------
The "not mp3" line is just a placeholder for understanding what your program is actually doing.

-----------------------------------
Musta
Fri Jan 18, 2013 3:00 pm

Re: RE:Display .mp3 names in GUI.CreateTextboxChoice
-----------------------------------
The "not mp3" line is just a placeholder for understanding what your program is actually doing.

I spent some more time on it today and got it working 100% perfectly, I am happy.

Thanks for the help everybody, the Dir module really helped. Even my teacher didn't know what it was lol
