|
-
Mar 25th, 2005, 03:13 PM
#1
Thread Starter
Hyperactive Member
Killing after processing
Is it possible to put a command to kill the process after it has finished. i.e after clicking a command button that writes to a file. when it has finished can I kill that somehow -
Thanks
R
-
Mar 25th, 2005, 03:15 PM
#2
Re: Killing after processing
You can't kill a process that has already ended.
-
Mar 25th, 2005, 03:32 PM
#3
Thread Starter
Hyperactive Member
Re: Killing after processing
does this make sense then. I click a button that updates my file but it renders all my other command buttons useless and I cant understand why.
thanks
R
-
Mar 25th, 2005, 03:44 PM
#4
Re: Killing after processing
Try using a DoEvents if you have some loop.
-
Mar 25th, 2005, 04:05 PM
#5
Thread Starter
Hyperactive Member
Re: Killing after processing
It is when this is happening, I will try and have a look for info on what you just suggested.
Thanks
R
VB Code:
Private Sub Command2_Click()
Dim f1 As Integer, xmlpath As String, songpath As String, mp3path As String, f2 As Integer, i As Integer, pos As Integer
Dim Artist As String, SongName As String, artname As String, fname As String, MyPath As String
Dim mysong As String
Dim mytag As Boolean
mp3path = "C:\Program Files\mgamerz\XML PLAYER\my_mp3s\"
xmlpath = "C:\Program Files\mgamerz\XML PLAYER\"
SongName = Dir(mp3path & "\*.mp3")
fname = mp3path & SongName
With Form4
While Not Len(SongName) = 0
' Artist = GetMP3Tag(fname)
If Not i = 0 Then
Load .Label1(i): Load .Text1(i)
.Label1(i).Top = .Label1(i - 1).Top + 350
.Text1(i).Top = .Text1(i - 1).Top + 350
.Label1(i).Visible = True: .Text1(i).Visible = True
End If
.Label1(i) = SongName
mytag = GetMP3Tag(fname)
.Text1(i) = RTrim(MP3Info.sArtist)
SongName = Dir
fname = mp3path & SongName
i = i + 1
Wend
.Height = .Text1(.Text1.Count - 1).Top + 1600
.TAG = mp3path
MDIForm1.Caption = "Close This Form to Update XML Playlist"
.Show
' .WindowState = 2
End With
TAG = "wait"
While TAG = "wait"
DoEvents
Wend
i = 1
f2 = FreeFile
Open mp3path & "mp3.txt" For Output As #f2
f1 = FreeFile
Open xmlpath & "audiolist.xml" For Output As #f1
Print #f1, "<?xml version=""1.0""?>"
Print #f1, "<songs>"
SongName = Dir(mp3path & "\*.mp3")
i = 1
While Not Len(SongName) = 0
' if you can return the name of the artist you put the code in here
mytag = GetMP3Tag(mp3path & SongName)
'pos = InStr(mytag, "\")
mytag = Replace(mytag, "\", "/")
Do While InStr(mytag, " ")
mytag = Replace(mytag, " ", "")
Loop
Artist = RTrim(MP3Info.sArtist)
If Len(Artist) = 0 Then Artist = "UNKOWN"
MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath))) & " " & SongName
MyPath = Replace(MyPath, "\", "/")
MyPath = Replace(MyPath, " ", "", 1, 1)
mysong = Left$(SongName, Len(SongName) - 4)
songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & mysong & """/> "
Print #f1, songpath
Print #f2, SongName
Sleep 100
SongName = Dir
Wend
Print #f1, "</songs>"
Close
End Sub
-
Mar 25th, 2005, 06:17 PM
#6
Re: Killing after processing
I would put one DoEvents into each While/Wend loop.
-
Mar 25th, 2005, 06:21 PM
#7
Thread Starter
Hyperactive Member
Re: Killing after processing
not too sure where to add it or how to do that - would it just need to be in the update XML code?
Thanks
R
-
Mar 25th, 2005, 06:29 PM
#8
Re: Killing after processing
doevents let your computer do other things while its doing your code, so it wont freeze. Put it rigth before the wend, remember its one word-doevents
-
Mar 25th, 2005, 06:54 PM
#9
Thread Starter
Hyperactive Member
Re: Killing after processing
I'll need to do some reading into that thanks
-
Mar 25th, 2005, 07:37 PM
#10
Thread Starter
Hyperactive Member
Re: Killing after processing
will I be able to add the do events to the exixting code I posted or will it all need changing,
Thanks
R
-
Mar 25th, 2005, 08:35 PM
#11
Re: Killing after processing
I'll format your code for you, so you can see where it would go
VB Code:
Private Sub Command2_Click()
Dim f1 As Integer, xmlpath As String, songpath As String, mp3path As String, f2 As Integer, i As Integer, pos As Integer
Dim Artist As String, SongName As String, artname As String, fname As String, MyPath As String
Dim mysong As String
Dim mytag As Boolean
mp3path = "C:\Program Files\mgamerz\XML PLAYER\my_mp3s\"
xmlpath = "C:\Program Files\mgamerz\XML PLAYER\"
SongName = Dir(mp3path & "\*.mp3")
fname = mp3path & SongName
With Form4
While Not Len(SongName) = 0
If Not i = 0 Then
Load .Label1(i): Load .Text1(i)
.Label1(i).Top = .Label1(i - 1).Top + 350
.Text1(i).Top = .Text1(i - 1).Top + 350
.Label1(i).Visible = True: .Text1(i).Visible = True
End If
.Label1(i) = SongName
mytag = GetMP3Tag(fname)
.Text1(i) = RTrim(MP3Info.sArtist)
SongName = Dir
fname = mp3path & SongName
i = i + 1
Wend
.Height = .Text1(.Text1.Count - 1).Top + 1600
.TAG = mp3path
MDIForm1.Caption = "Close This Form to Update XML Playlist"
.Show
End With
f2 = FreeFile
Open mp3path & "mp3.txt" For Output As #f2
f1 = FreeFile
Open xmlpath & "audiolist.xml" For Output As #f1
Print #f1, "<?xml version=""1.0""?>"
Print #f1, "<songs>"
SongName = Dir(mp3path & "\*.mp3")
i = 1
While Not Len(SongName) = 0
[B]DoEvents[/B] ' <---------------------------- HERE \\
mytag = GetMP3Tag(mp3path & SongName)
mytag = Replace(mytag, "\", "/")
Do While InStr(mytag, " ")
mytag = Replace(mytag, " ", "")
Loop
Artist = RTrim(MP3Info.sArtist)
If Len(Artist) = 0 Then Artist = "UNKOWN"
MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath))) & " " & SongName
MyPath = Replace(MyPath, "\", "/")
MyPath = Replace(MyPath, " ", "", 1, 1)
mysong = Left$(SongName, Len(SongName) - 4)
songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & mysong & """/> "
Print #f1, songpath
Print #f2, SongName
Sleep 100
SongName = Dir
Wend
Print #f1, "</songs>"
Close #f1
close #f2
End Sub
-
Mar 25th, 2005, 10:46 PM
#12
Thread Starter
Hyperactive Member
Re: Killing after processing
Thanks for that but Im still unsure of the next step. I have been studying my books but I just cant seem to fathom it out. I thought this would be the process that needs to end before anything else can be carried out.
Sorry to be a nuisance as usual
Rob
-
Mar 25th, 2005, 11:35 PM
#13
Junior Member
Re: Killing after processing
That would suck. Say you are playing music in a game. until the music finishes you cannot play the game? Yeah, it would make you mute your game more often. It is my understanding that code runs from top to bottom in every event, but multiple events can be running at the same time.
-
Mar 25th, 2005, 11:40 PM
#14
Re: Killing after processing
What do you want to do while the computer is saving files? You could set enabled = false for all of the butons so that they cannot be clicked until the save finishes.
Explain what you want to be able to do while the computer is saving the files?
-
Mar 26th, 2005, 03:23 PM
#15
Thread Starter
Hyperactive Member
Re: Killing after processing
what I want is that when the program has finished writing the XML file then the user can add more files or delete files but currently after the button is clicked to update the XML file the other buttons stop functioning.
Thanks
Rob
-
Mar 26th, 2005, 05:59 PM
#16
Thread Starter
Hyperactive Member
Re: Killing after processing
would it be easier if I made it into 2 seperate programs?
-
Mar 26th, 2005, 09:01 PM
#17
Thread Starter
Hyperactive Member
Re: Killing after processing
If set enabled = false for all of the butons would that allow them to work when the xml file has been processed?
thanks
R
-
Mar 26th, 2005, 09:12 PM
#18
Re: Killing after processing
You turn them back on when the code has finished. You could also search for LockWindowUpdate, which prevents doing anything until Unlock Window
-
Mar 26th, 2005, 09:22 PM
#19
Thread Starter
Hyperactive Member
Re: Killing after processing
would I put the code to disable the buttons at the beginning of the code and then enable them at the end?
-
Mar 26th, 2005, 09:24 PM
#20
Re: Killing after processing
Yes. That would prevent them doing anthing else while the code is executing.
-
Mar 26th, 2005, 09:46 PM
#21
Thread Starter
Hyperactive Member
Re: Killing after processing
thanks for that, I havent goot VB installed on this machine because Ive been trying to find it in books but am I right in thinking that they wiil need to be disabled before this line
VB Code:
Dim f1 As Integer, xmlpath As String, songpath As String, mp3path As String, f2 As Integer, i As Integer, pos As Integer
and then enable them after this line
VB Code:
Print #f1, "</songs>"
Close #f1
close #f2
Is it only because the code hasn't finished executing that the buttons wont work currently
-
Mar 26th, 2005, 10:25 PM
#22
Re: Killing after processing
You will like this. I have just been changing it to suit you. Also saved it for next time, so I don't have to search the forums.
VB Code:
Option Explicit
Private Sub Form_Load()
Dim ctlAll As Control
For Each ctlAll In Me.Controls
If TypeOf ctlAll Is CommandButton Then
ctlAll.Enabled = False
End If
Next
End Sub
Turns of ALL buttons in the form. Just change it to TRUE to turn them back on.
-
Mar 26th, 2005, 10:35 PM
#23
Thread Starter
Hyperactive Member
Re: Killing after processing
Thanks very much as I say I cannot try it until later because I have no access to VB but I will keep you posted. It is really appreciated.
Rob
-
Mar 26th, 2005, 10:43 PM
#24
Thread Starter
Hyperactive Member
Re: Killing after processing
Just a quickie when I have added that to my code where will I need to add the code to enable them - Thanks very much again
R
-
Mar 26th, 2005, 10:56 PM
#25
Re: Killing after processing
Same loop from above, but change it to this:
-
Mar 26th, 2005, 11:11 PM
#26
Thread Starter
Hyperactive Member
Re: Killing after processing
if the first bit of code goes on the form load where will the second go. Sorry I just want to get it clear because I want to try and not bother you later because I think Ive taken up enough of your time.
Thanks
R
-
Mar 26th, 2005, 11:15 PM
#27
Re: Killing after processing
Just like you said in Post #21. Disable them at the top and re-enable them at the bottom. Substitue the correct form name for your app. I used Form1 in my sample, but you probably have it named something else.
-
Mar 26th, 2005, 11:33 PM
#28
Thread Starter
Hyperactive Member
Re: Killing after processing
-
Mar 27th, 2005, 03:49 PM
#29
Thread Starter
Hyperactive Member
Re: Killing after processing
Right, I have successfully added the code and got the buttons to be disabled when the file is bieng written but after the file has been written the buttons still cease to work. If I wanted to add or delete files I need to close the app and restart it.
Any other suggestions that could be caussing this.
Thanks
R
-
Mar 27th, 2005, 03:59 PM
#30
Re: Killing after processing
did you run the code to enable them?
put a breakpoint in to make sure it gets there.
are the buttons enabled?
-
Mar 27th, 2005, 04:41 PM
#31
Thread Starter
Hyperactive Member
Re: Killing after processing
the buttons disable when the filea are bieng added and then they are enabled again Here is where I added them to my code
VB Code:
Private Sub Command2_Click()
Dim f1 As Integer, xmlpath As String, songpath As String, mp3path As String, f2 As Integer, i As Integer, pos As Integer
Dim Artist As String, SongName As String, artname As String, fname As String, MyPath As String
Dim mysong As String
Dim mytag As Boolean
Dim ctlAll As Control
For Each ctlAll In Me.Controls
If TypeOf ctlAll Is CommandButton Then
ctlAll.Enabled = False
End If
Next
mp3path = "C:\Program Files\mgamerz\XML PLAYER\my_mp3s\"
xmlpath = "C:\Program Files\mgamerz\XML PLAYER\"
SongName = Dir(mp3path & "\*.mp3")
fname = mp3path & SongName
With Form4
While Not Len(SongName) = 0
' Artist = GetMP3Tag(fname)
If Not i = 0 Then
Load .Label1(i): Load .Text1(i)
.Label1(i).Top = .Label1(i - 1).Top + 350
.Text1(i).Top = .Text1(i - 1).Top + 350
.Label1(i).Visible = True: .Text1(i).Visible = True
End If
.Label1(i) = SongName
mytag = GetMP3Tag(fname)
.Text1(i) = RTrim(MP3Info.sArtist)
SongName = Dir
fname = mp3path & SongName
i = i + 1
Wend
.Height = .Text1(.Text1.Count - 1).Top + 1600
.TAG = mp3path
MDIForm1.Caption = "Close This Form to Update XML Playlist"
.Show
' .WindowState = 2
End With
TAG = "wait"
While TAG = "wait"
DoEvents
Wend
i = 1
f2 = FreeFile
Open mp3path & "mp3.txt" For Output As #f2
f1 = FreeFile
Open xmlpath & "audiolist.xml" For Output As #f1
Print #f1, "<?xml version=""1.0""?>"
Print #f1, "<songs>"
SongName = Dir(mp3path & "\*.mp3")
i = 1
While Not Len(SongName) = 0
' if you can return the name of the artist you put the code in here
mytag = GetMP3Tag(mp3path & SongName)
'pos = InStr(mytag, "\")
mytag = Replace(mytag, "\", "/")
Do While InStr(mytag, " ")
mytag = Replace(mytag, " ", "")
Loop
Artist = RTrim(MP3Info.sArtist)
If Len(Artist) = 0 Then Artist = "UNKOWN"
MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath))) & " " & SongName
MyPath = Replace(MyPath, "\", "/")
MyPath = Replace(MyPath, " ", "", 1, 1)
mysong = Left$(SongName, Len(SongName) - 4)
songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & mysong & """/> "
Print #f1, songpath
Print #f2, SongName
Sleep 100
SongName = Dir
Wend
Print #f1, "</songs>"
For Each ctlAll In Me.Controls
If TypeOf ctlAll Is CommandButton Then
ctlAll.Enabled = True
End If
Next
Close
End Sub
-
Mar 27th, 2005, 04:56 PM
#32
Re: Killing after processing
CLOSE should be Close #F1
what happened to the formatted code that I made 
So does it work correctly? That looks right.
-
Mar 27th, 2005, 05:14 PM
#33
Thread Starter
Hyperactive Member
Re: Killing after processing
Hi I have used the formatted code I just didn't want to mess it up which is usually what I normally do. I have made the changes you suggested. as below but I add a number of songs, Add some more and then the buttons just will not do anything. It allows me to add songs once or twice but then they cease to work.
Thanks
R
VB Code:
Private Sub Command2_Click()
Dim f1 As Integer, xmlpath As String, songpath As String, mp3path As String, f2 As Integer, i As Integer, pos As Integer
Dim Artist As String, SongName As String, artname As String, fname As String, MyPath As String
Dim mysong As String
Dim mytag As Boolean
Dim ctlAll As Control
For Each ctlAll In Me.Controls
If TypeOf ctlAll Is CommandButton Then
ctlAll.Enabled = False
End If
Next
mp3path = "C:\Program Files\mgamerz\XML PLAYER\my_mp3s\"
xmlpath = "C:\Program Files\mgamerz\XML PLAYER\"
SongName = Dir(mp3path & "\*.mp3")
fname = mp3path & SongName
With Form4
While Not Len(SongName) = 0
If Not i = 0 Then
Load .Label1(i): Load .Text1(i)
.Label1(i).Top = .Label1(i - 1).Top + 350
.Text1(i).Top = .Text1(i - 1).Top + 350
.Label1(i).Visible = True: .Text1(i).Visible = True
End If
.Label1(i) = SongName
mytag = GetMP3Tag(fname)
.Text1(i) = RTrim(MP3Info.sArtist)
SongName = Dir
fname = mp3path & SongName
i = i + 1
Wend
.Height = .Text1(.Text1.Count - 1).Top + 1600
.TAG = mp3path
MDIForm1.Caption = "Close This Form to Update XML Playlist"
.Show
End With
f2 = FreeFile
Open mp3path & "mp3.txt" For Output As #f2
f1 = FreeFile
Open xmlpath & "audiolist.xml" For Output As #f1
Print #f1, "<?xml version=""1.0""?>"
Print #f1, "<songs>"
SongName = Dir(mp3path & "\*.mp3")
i = 1
While Not Len(SongName) = 0
DoEvents ' <---------------------------- HERE \\
mytag = GetMP3Tag(mp3path & SongName)
mytag = Replace(mytag, "\", "/")
Do While InStr(mytag, " ")
mytag = Replace(mytag, " ", "")
Loop
Artist = RTrim(MP3Info.sArtist)
If Len(Artist) = 0 Then Artist = "UNKOWN"
MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath))) & " " & SongName
MyPath = Replace(MyPath, "\", "/")
MyPath = Replace(MyPath, " ", "", 1, 1)
mysong = Left$(SongName, Len(SongName) - 4)
songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & mysong & """/> "
Print #f1, songpath
Print #f2, SongName
Sleep 100
SongName = Dir
Wend
Print #f1, "</songs>"
For Each ctlAll In Me.Controls
If TypeOf ctlAll Is CommandButton Then
ctlAll.Enabled = True
End If
Next
Close #f1
Close #f2
End Sub
-
Mar 27th, 2005, 05:30 PM
#34
Re: Killing after processing
I'm not sure. Add some Debug.Print statements to tell you where the program is executing "Reading Files" "Writing XML" so we can figure out where it is messing up. You don't have any other timers or anything that could be interrupting the code, do you? What about Error Traps? Do you have On Error Goto 0 to turn off error traps?
-
Mar 27th, 2005, 05:40 PM
#35
Thread Starter
Hyperactive Member
Re: Killing after processing
Ive never done that before is it difficult to do?
-
Mar 27th, 2005, 05:55 PM
#36
Re: Killing after processing
Just place a few lines in your code, like
VB Code:
On Error Goto 0 ' At the top of the module somewhere
debug.print "Reading XML file"
-
-
-
debug.print "Writing file#1"
-
-
-
debug.print "Writing file#2"
-
-
-
As the program is running, it will print the line it runs accross in the debug window of your ide (and not do anything when it's compiled)
Use the on error goto 0 to make sure that any error is not sending the code somewhere else while the buttons are disabled. You could also try not disabling the buttons and seeing if the buttons don't work after a few times through.
-
Mar 27th, 2005, 06:17 PM
#37
Thread Starter
Hyperactive Member
Re: Killing after processing
I cannot find any errors. Is it possible that you could have a look through it when you get time if I attach it as a zip file here? I may be missing something obvoius.
Thanks
R
-
Mar 27th, 2005, 07:17 PM
#38
Re: Killing after processing
It wouldnot run on my computer without all of the necessary files. If you have any error traps that aren't set to 0, then any error in your code would go to that error trap. if the buttons were disabled at the time, that would explain them not working. I don't think I could find anything by just looking through the code. You have to find an error, and determine where it is occurring by stepping through it, or printing out messages, or whatever you can do to help you.
I've done a lot of this code, and my code usually works many times as long as it works the first time.
Good Luck!
-
Mar 27th, 2005, 10:14 PM
#39
Thread Starter
Hyperactive Member
Re: Killing after processing
Thanks David for all your help throughout this, I think I have found the problem it's either the length of the file names or the amount of files I have been trying to add. I have managed to add 93 file so far. I have added them in 10's and they all have short names. So maybe thats what it was all along. I dont know if that makes sense but again thanks very much for all your help.
Cheers
?Rob
-
Mar 27th, 2005, 10:19 PM
#40
Re: Killing after processing
I think someone said that FSO had a limited number of files that it allowed. Now that you say that it rang a bell. Look for FSO.Files or something like that.
The buffer is too small for that many files.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|