-
Oct 28th, 2016, 07:01 AM
#1
Thread Starter
New Member
Form keeps popping up after closing
So for my project i got 2 forms one as a loading screen and one as the main 'window'
after the loading screen finishes 'loading' it closes and the second form pops up - this part works great no problems so far
but after im done with the work on the second form when i try to close it keeps popping back up, on vb i can just stop debugging
but i have to use task manager to stop it normally
heres the code(i know its not great im new and im still learning ) :
Code:
Public Class Form1
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
Timer2.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Visible = Not Label1.Visible
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
ProgressBar1.Increment(2)
If ProgressBar1.Value = ProgressBar1.Maximum Then
Me.Hide()
Form2.Show()
Timer1.Stop()
End If
End Sub
End Class
and form 2 is just a webpage
Any help is GREATLY appreciated
sorry if i make no sense or if i seem retarded
-
Oct 28th, 2016, 07:17 AM
#2
Re: Form keeps popping up after closing
Change Me.Hide to Me.Close
You'll need to change your Shutdown Mode to When last form closes.
Project-->Properties
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 28th, 2016, 07:28 AM
#3
Thread Starter
New Member
Re: Form keeps popping up after closing
-
Oct 28th, 2016, 09:10 AM
#4
Thread Starter
New Member
Re: Form keeps popping up after closing
Alright got no idea what happened, changing the shutdown mode and swapping hide to close worked when i first tried it but now after the form opens and finishes loading the whole thing closes instead of just form 1
My original problem is that form 1 works fine and form 2 works fine until i try to close then windows of form 2 keeps popping up again and again
-Again any help is greatly appreciated
-
Oct 28th, 2016, 09:22 AM
#5
Re: Form keeps popping up after closing
You've got some strange stuff going on in that first snippet. For one thing, you have a method called Form3_Load in Form1. Both of those names are default names, which never clarifies things, but the Handles clause should apply to Form1, so what's with the Form3? Also, what's with the Load, since the Handles is for Activated? That's just a method name, so it isn't a problem in itself. You could name a method anything at all. It just suggests that some copying and pasting was going on, and that some confusion may be resulting.
Then you have timer2 showing windows in the tick event, which stops timer1, not timer2. I don't see any code that stops timer2, and timer2 is the one showing the form, so it seems obvious that Form2 will keep popping up whenever that timer fires.
My usual boring signature: Nothing
-
Oct 28th, 2016, 09:39 AM
#6
Thread Starter
New Member
Re: Form keeps popping up after closing
The code was copied but i chaned it around to fit what i was making but the problem is fixed now thanks to you . Instead of form3_load it should have been form2 and instead of timer1 it should have been timer2
- Thanks so much for the help and sorry being blind to not realize the mistakes
Also if i wanted vb to hold down a key like shift/space in the webpage in form2 what can i use? Sendkey doesnt seem to work
Thanks in advance
-
Oct 28th, 2016, 09:57 AM
#7
Re: Form keeps popping up after closing
Trying to manipulate a web page is almost always a bad idea. There once was a time when web pages were a bunch of text, a few links, and possibly some pictures. These days, web pages are a HUGE mass of things taking on many different, mutable, forms. If there is an API that can be used rather than the web page, then you should use the API in ALL cases. If there isn't an API...well, why isn't there an API? If it's because the site doesn't want you doing what you are trying to do, then asking about it here is a violation of the AUP. If it's because the site owners don't have their act together, then light a fire under them. The whole point of the web is interaction with some group of people, and an API is just a way to broaden that appeal.
My usual boring signature: Nothing
-
Oct 28th, 2016, 08:39 PM
#8
Thread Starter
New Member
Re: Form keeps popping up after closing
well umm you see all i want it to do is just hold down the space key on hacker typer so code would just rain down fast i already tried using a macro and it worked so i hoped that i could do the same on vb
-
Oct 29th, 2016, 03:54 PM
#9
Re: Form keeps popping up after closing
That doesn't sound like a benign thing to be doing. Let me remind you that the AUP of this site specifically prohibits asking questions about malicious things, which includes pranks.
My usual boring signature: Nothing
-
Oct 29th, 2016, 06:31 PM
#10
Thread Starter
New Member
Re: Form keeps popping up after closing
Its not supposed to be a prank or a joke virus or anything, all the app does is have a loading screen and then a second window pops up with hackertyper and code is supposed to fly down automatically and then a 3rd window will pop up where you would choose a bunch of stuff to put on an image.
I know it sounds dumb but its just a fun project i decided to work on through the long weekend
-
Oct 30th, 2016, 12:47 AM
#11
Re: Form keeps popping up after closing
Originally Posted by IDon'tKnow
, all the app does is have a loading screen and then a second window pops up with hackertyper and code is supposed to fly down automatically
Couldn't you make something similar without using a web browser control and that web site?
Just a simple example, I used the file kernel.txt from, https://github.com/duiker101/Hacker-Typer
and break the text file into array at the ; char, then draw chars into a textbox, pretty lame ...
Code:
Public Class Form1
Private typeHackerTextParts() As String = IO.File.ReadAllText("kernel.txt").Split(";"c)
Private textPartIndex As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.TextBox1.BackColor = Color.Black
Me.TextBox1.ForeColor = Color.Lime
Timer1.Interval = 33
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Static currentCharIndex As Integer
If currentCharIndex >= typeHackerTextParts(textPartIndex).Length Then
textPartIndex += 1
If textPartIndex >= typeHackerTextParts.Count Then textPartIndex = 0
currentCharIndex = 0
End If
Me.TextBox1.AppendText(typeHackerTextParts(textPartIndex).Substring(currentCharIndex, 1))
currentCharIndex += 1
End Sub
End Class
-
Nov 1st, 2016, 06:54 AM
#12
Thread Starter
New Member
Re: Form keeps popping up after closing
sorry it took so much time but it worked! thanks so much man <3
-
Nov 1st, 2016, 07:03 AM
#13
Thread Starter
New Member
Re: Form keeps popping up after closing
sorry for bothering again but is there anyway to make it type faster? changing the interval doesn't work and im not sure what to change.
sorry if the thing to change is obvious but again im new to vb
-
Nov 1st, 2016, 02:03 PM
#14
Re: Form keeps popping up after closing
A timer interval of 33 milliseconds is about as fast as it gets using a timer.
You could rewrite the code using a secondary thread, and the thread.sleep method within a loop...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 1st, 2016, 04:49 PM
#15
Re: Form keeps popping up after closing
Or "type" twice as fast by doing two (or more would be faster still) characters per tick, instead of one.
Also, the winform timer is usually tied to a 64 hz clock (15.625 ms interval).
If you choose an interval of 1 to 15, you'll get that 64hz rate (a tick every 15.625 ms (give or take) ).
If you choose an interval of 16 to 31, you'll get a tick every other clock, i.e. 32 times per second (31.25 ms interval, give or take).
If you choose an interval of 32 to 48, you'll get a tick every third clock, i.e. 21.333... times per second (46.875 ms interval, give or take).
The choice of 33 ms interval, which might be chosen thinking it would give you about a 30hz update most likely is really giving you 25% less, around 21 ticks per second.
So, if you change the interval to 15 or less, it will probably type three times faster, and if you do multiple characters per tick, even more so.
-
Nov 2nd, 2016, 05:00 AM
#16
Thread Starter
New Member
Re: Form keeps popping up after closing
Originally Posted by .paul.
A timer interval of 33 milliseconds is about as fast as it gets using a timer.
You could rewrite the code using a secondary thread, and the thread.sleep method within a loop...
Again im new so im not sure how to do that some code would help but its all up to you thanks for the help so far
Originally Posted by passel
Or "type" twice as fast by doing two (or more would be faster still) characters per tick, instead of one.
Also, the winform timer is usually tied to a 64 hz clock (15.625 ms interval).
If you choose an interval of 1 to 15, you'll get that 64hz rate (a tick every 15.625 ms (give or take) ).
If you choose an interval of 16 to 31, you'll get a tick every other clock, i.e. 32 times per second (31.25 ms interval, give or take).
If you choose an interval of 32 to 48, you'll get a tick every third clock, i.e. 21.333... times per second (46.875 ms interval, give or take).
The choice of 33 ms interval, which might be chosen thinking it would give you about a 30hz update most likely is really giving you 25% less, around 21 ticks per second.
So, if you change the interval to 15 or less, it will probably type three times faster, and if you do multiple characters per tick, even more so.
I already changed the timer to 10 ( changing it lower keeps crashing idk why) it types somewhat faster but not to a noticeable amount.
I want the code to type out fast to the point where it would scroll down fast to the end in 10-15 seconds or so
but again its up to you if you want to help or not thanks for the help so far
-
Nov 2nd, 2016, 07:48 AM
#17
Re: Form keeps popping up after closing
Why use a timer in the first place?
-tg
-
Nov 2nd, 2016, 03:52 PM
#18
Thread Starter
New Member
Re: Form keeps popping up after closing
Originally Posted by techgnome
Why use a timer in the first place?
-tg
If you got a better way of doing the same thing by all means share it
-
Nov 2nd, 2016, 04:27 PM
#19
Re: Form keeps popping up after closing
Well, if I understand it right, you don't really need the program to be responding to YOU between characters, right? It's just blasting text into the display. So, you could remove the timer entirely and just run the code that is in the timer tick event in a loop. There would be two things that you'd have to add for that to look reasonable.
The first is that you'd probably want there to be at least SOME delay between characters popping up, so add a Thread.Sleep() into the loop. The argument to Thread.Sleep is the number of milliseconds to sleep. If you set that at 33, you'd get about what you have with the timer. Set it to 5, and you'd be getting roughly 200 characters per second, which is probably too fast, but might be ok. Just play around with the arugment to the Thread.Sleep to see what works best.
The second point is that no messages will be processed while that loop is running. This means that no keyboard input will be received (you can type all you want, nothing will happen). However, it also means that the screen won't paint, so the characters wouldn't normally show up on the screen until after the loop was finished. To fix this, add a Me.Textbox1.Refresh into the loop. This will force the textbox to redraw immediately rather than waiting for the paint event it will never receive.
My usual boring signature: Nothing
-
Nov 2nd, 2016, 04:45 PM
#20
Re: Form keeps popping up after closing
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 3rd, 2016, 01:15 AM
#21
Thread Starter
New Member
Re: Form keeps popping up after closing
Alright so it worked a few times and the code works perfectly but i keep getting these errors
Code:
Error 11 Could not copy "obj\x86\Debug\*retarded name*" to "bin\Debug\*retarded name*". Exceeded retry count of 10. Failed. *retarded name*
Error 12 Unable to copy file "obj\x86\Debug\*retarded name*" to "bin\Debug\*retarded name*". The process cannot access the file 'bin\Debug\*retarded name*' because it is being used by another process. *retarded name*
this is the code for the form ( 90% of it is Paul's)
Code:
Imports System.Threading
Imports System.ComponentModel
Public Class Form2
Private typeHackerTextParts() As String = IO.File.ReadAllText("kernel.txt").Split(";"c)
Private textPartIndex As Integer
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
Timer2.Start()
Me.TextBox1.BackColor = Color.Black
Me.TextBox1.ForeColor = Color.Lime
BackgroundWorker1.WorkerReportsProgress = True
BackgroundWorker1.WorkerSupportsCancellation = True
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
ProgressBar1.Increment(0.6)
If ProgressBar1.Value = ProgressBar1.Maximum Then
Me.Hide()
Form3.Show()
Timer2.Stop()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Visible = Not Label1.Visible
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Do Until e.Cancel
Static currentCharIndex As Integer
If currentCharIndex >= typeHackerTextParts(textPartIndex).Length Then
textPartIndex += 1
If textPartIndex >= typeHackerTextParts.Count Then textPartIndex = 0
currentCharIndex = 0
End If
BackgroundWorker1.ReportProgress(0, typeHackerTextParts(textPartIndex).Substring(currentCharIndex, 1))
currentCharIndex += 1
Threading.Thread.Sleep(5)
Loop
End Sub
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Try
Me.TextBox1.AppendText(e.UserState.ToString)
Catch ex As ObjectDisposedException
End
End Try
End Sub
Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
BackgroundWorker1.CancelAsync()
End Sub
End Class
Thanks for the help so far guys i really appreciate it!
Last edited by IDon'tKnow; Nov 3rd, 2016 at 08:21 AM.
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
|