This is a VB6 question.

I seem to have a problem with a form that should be unloading or at the very least become not visible. For whatever reason when another form is shown (form2.Show as an example) or made visible (Form2.Visible = True, next line would say Unload Form1 for instance), that same form (Form1) will come back up, including any message boxes as well... I quit them 2ce (sometimes 3 times) and they will finally go away for good.

It seems that on the first form in the code, even after the next form called is loaded, the code is re-read again even though i have definately unloaded it (it = the first form (Form1)).

Any ideas why this may be happening? This really is odd.

I will supply more code if needed.

thanks for any help. :)

A copy of the actual code would be nice... I'm learning myself and this is definitely issue that I foresee in my future. :cool:

ok BigSeckC,

Here is the code I am having an issue with at the moment.

If Len(pass) <> 0 And InStr(1, pass, "reset") = False Then
        frmVerify.Height = 2100
        Label2.Visible = True
        Command1.Enabled = False
        Command1.Caption = "Loading..."
        Pause 1.5
        Unload frmVerify
        frmenter.Visible = True
    
    ElseIf InStr(1, pass, "reset") Then
            Unload frmVerify
            Form2.Show
            MsgBox "Your Password has been reset.  Please make a new one now."  
       
    Else
        frmVerify.Height = 1910
        Command1.Visible = True
        frmenter.Visible = False
     End If
1:
End Sub

Now as you can see a number of things can happen here. But if it calls for a password reset, then the message box comes up 2 more times after it is clicked out. If the frmenter form is called for, then after the correct password is entered, the password form does go away, but comes back over and over endlessly. The code for the frmenter click is below:

Private Sub Command1_Click()
Dim pass As String
   On Error GoTo program

Open "C:\test.tst" For Input As #1
Input #1, pass
Close #1
If Text1.Text = pass Then
    frmenter.Visible = False
    Form3.Show
    
    Else
    enter = MsgBox("Incorrect Password", vbError, "Error")
End If
Exit Sub
program:
Open "c:\test.tst" For Output As #1
Write #1, "reset"
Close #1
End Sub

I cant figure out why this is happening. The only thing i have found that will stop frmenter from coming back is to add 'vbModal' to the form3 that is called from form2 in the code directly above. I do not like using that however, as it isnt really solving the problem.

Any help would definately be appreciated.

Ok... time to state the obvious... it's Looping the code.

Would a 'Do...While' help in this situation? I'm asking this as a general question to anyone...

Seems like that 'could/would' work - but I'm not proficient enough to say 'do this'.

Have you tried googling a 'pw reset snippet'? I had to do that once and it did help me understand what I was doing wrong :)

no i havent looked for that.. I will do it now. I know its looping the code, but i dont know why, obviously... hehe. thanks for the help.. ill check it out.

also, Im not sure how a Do While statement would help as that is a type of looping in itself. If Then isnt supposed to loop at all. That is what is so odd to me about this. It goes back to this code no matter what I do. Im sure that solution is fairly simple, yet it it isnt obvious to me, yet.

Thanks again. :)

I know - it's truly weird - the reasoning behind the Do..While is:

"technically" if the code is "looping" without being told to, a Do...While 'should', in effect, negate the situation. (e.g., Do this - While that - Then Quit)

The only other things I can think of would be:

1. Run the program on another box - "maybe"there is 'something' on the code box that is causing the anomaly. (e.g., bad memory address, bad spot on HDD, etc.)

2. Re-write the code using a New Form and Test with each New Line - maybe even on a different box - 1 of 2 reasons...

A. The existing file could be corrupted. <-- not entirely impossible.

B. In testing each line, you would be narrowing down where 'the loop' is coming into play.

...right now, it's honestly the only things I can think of.

*crosses fingers for a corrupted file...

Not to insult your intelligence, but by box - I mean computer. Just in case someone else was wondering...

...why do I have this sneaky feeling I'm gonna run into this too?...:sweat:

Just looking at the code again...

What procedure is tied to '1:'?

End If
1:
End Sub

...maybe there is something there...

do a thing ..................
use the unload command after the
frmenter.Visible = True
line.
the error u describe is just the opposte of waht it shold be withthis code.so just tey that..

what is that PAUSE in your code ?

I'm assuming that the program is being told to wait 1.5 seconds before continuing. Is 'pause' not a valid command?

It makes sense 'logically'...but if it's not a command - it's not a command. :P

ok i have been busy redoing a lot of the code....

the form intermittently does the aforementioned initial problem now. VERY strange indeed.

I will attempt to redo the entire code for the form that is looping for no apparent reason in the next day or two.

Now to answer a few questions....

the "1" was used before when I was actually looking to see if a file that held the encrypted password was there or not. If it wasnt there, then "goto 1," which ended the procedure. But now I'm not using a file to store the encrypted password. I am writing it to the registry instead (also encrypted). Much better this way imho.

the Pause in the code was (and still is used) if a password has been previously entered in to load the next form. The reason i used the Pause was because the GUI looks kinda cool and it allowed for a little time for the user to see what is actually happening. The Pause is now set at 2 instead of 1.5.

Also, the Pause is a valid command since I have code to actually count (in seconds instead of milliseconds) in a separate procedure/subroutine.

Lastly, I have tried an 'unload form' already to no avail because as it loops, it simply reopens the form that was unloaded. I tried that before i posted this problem here. Good suggestion however. :)

Hope that clears some things up. The problem is still not solved though. :\

Thanks for the help very much. Im sure eventually it will get it figured out. Hopefully sooner than later. :)

NP.... as I said before, I'm learning too so I'm having to use 'logic' to try and decode the code :D

I'm hoping to find an answer too because I have a project in mind that could run into the same type of situation. Solve it now, less headache later :twisted:

Good thinking.

Just to let you know... I tried to completely redo the code and that dide work either. Since there is 3 different if then statements, and it DOES repeat 3 times, I started thinking that the number of IF-Then statements is the reason for the number of repeats. They are all inside one subroutine/procedure.

The problem is, I cant really simplify it. I suppose i could use a "Case" statement instead, but I haven't ever seen a case argument that has multiple lines after it in any examples of source that i have looked at. Logically, it "could" work. But, I just dont know about "Case" coding that well to say for sure right now.

I will go on the premise that because in this one sub/procedure that there are 3 if..then statements. It is the only thing that makes sense at the moment for the number of repeats I am getting. Where in the heck are the experienced coders for VB? I am pretty sure that a several of them, at the very least, have enough knowledge to easily fix this little problem. :(

Patiently awaiting a reason why this thing repeats when it swhouldnt. :(

I'm assuming that the program is being told to wait 1.5 seconds before continuing. Is 'pause' not a valid command?

It makes sense 'logically'...but if it's not a command - it's not a command. :P

not a command as far as i know, there use to be a sleep command in qbasic (i think)... but writing a pause sub is doable to say the least... assuming one was written for use with this program, how its set up could be part of the problem i guess...

funny, i've never used form.visible = true / false to show or hide forms... always just used .show or .hide... didn't even know it worked until now... well there's my new thing for the day ;)

[edit]ok... so i probably shouldn't be posting at 6:30 am with no sleep... sorry, didn't notice the second page :$ [/edit]

the code for pause goes as follows and I am fairly certain that it is not part of the problem:

Sub pause(interval)
Current = Timer
Do While Timer - Current < Val(interval)
DoEvents
Loop
End Sub

looking at that, wouldn't think so...

alright, unrelated to the form not disapearing... i have a question about your code...

what happens if someone uses presetpass as their password? (or some random combination of alphanumeric characters that happens to contain the string reset in the somewhere inside of it..?

as a note... with the code provided; i can see no reason that the form would keep coming back...

I'm not sure I understand what you mean. But as far as the password goes, if there is no password at all, it asks if you want to make one. If not, then the password form does not come up. If you do want to. then it does.

After that, it saves the password to the registry (encoded). There is no preset pass to check. It won't look for a password until one has been created, but if it has been saved already in a prior running of the program, then the program checks for the password.

If it is there, the program will start. If not, then it wont. Simple as that.

I dont really understand the question. I hope this answers it.

was just wondering about the check for reset... instr will check within String1 for an instance of String2, string2 being reset, if String1 is set to anything including reset, it'll come back as true...

so reset will come back as saying, yes... it says reset...
preset will come back as saying that it says reset...
and 324resetas351 will come back as saying that it says reset...

might want to use

if pass <> "reset" then
 'your valid password code
elseif pass = "reset" then
 'your reset password code
end if

better yet, might want to use a string of charaters they can't use as a password... for instance
stReset = chr$(13) & chr$(13) & chr$(13)

Comments
thank you

That particular portion of code has nothing to do with a password in the way you are describing at all. That piece of code has to do with a database check for something else entirely. And it doesnt "reset" to the best of my knowledge as it is pulling an HDD volume ID.

However, that information will certainly prove to be quite valuable in the future. Thank you very much for it. :)

There are many things happening in this particular "sub." I am beginning to think that it is repeating itself due to the placement of certain lines of code OR how many times i run the code consecutively without restarting VB6. Because it is an intermittent problem sometimes as well. It either doesn't happen at all, or repeats once after the initial run, or twice after the initial run. It is REALLY frustrating. Crazyness for sure.

Even the compiled code will do the same "redo" even when it didn't in the testing phase of the code. So whatever is causing it is not fixed for sure. But, I just recently made another chg to the code (tonight) and I haven't seen it happen at all lately. That means exactly nothing though because i have had that happen before since posting this problem only to see the "redo" return. :(

As Always,

Thank you for the help and comments. It is certainly appreciated.

awwwwwwwwww NUTS... was hoping something may have fixed this... I'm with you right now - possibly the different IF statements in your procedures. Took a small break from coding this weekend to let some things sink in for me before I move on - but I'm definitely watching this thread and *crosses fingers for a fix...

sorry man... i tried :)

not a command as far as i know, there use to be a sleep command in qbasic (i think)... but writing a pause sub is doable to say the least... assuming one was written for use with this program, how its set up could be part of the problem i guess...

funny, i've never used form.visible = true / false to show or hide forms... always just used .show or .hide... didn't even know it worked until now... well there's my new thing for the day ;)

[edit]ok... so i probably shouldn't be posting at 6:30 am with no sleep... sorry, didn't notice the second page :$ [/edit]

LOL - hear ya... the way the code was written it appeared as though 'Pause' was being called as a Procedure - i haven't run into anything denoting that command :)

so i was just kinda assuming and hoping that i'm learning something XD

Comments
an E for Effort

The pause is being called. I put the code for it on the previous page. Ill post it again here for you:

Sub pause(interval)
Current = Timer
Do While Timer - Current < Val(interval)
DoEvents
Loop
End Sub

now in an interesting twist, I move some stuff around in the part of the code i showed at the beginning that was looping for no apparent reason. I am not getting that same thing to happen now. It may happen later, but it hasnt started all day. So very strange indeed. Once im SURE it has fixed that problem, I will post the order I have put the code in that eliminated the code from looping. Until then, im crossing my fingers that it indeed has been corrected.

Well I am going to say for now that the problem has been corrected. I still am not 100% sure that it is, but i havent had it happen for 2 days straight.

What I did was rearrange some of the code in the sub that was looping.

this is how the troubled area was:

Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Static buf As String
Dim Wdata As String
Winsock2.GetData Wdata, vbString
buf = buf & Wdata
Dim Val As String
pause 1.5
Winsock2.Close
Val = getstring(HKEY_LOCAL_MACHINE, "xxxx\xxxx\xxxx\xxxx", "blah")

Now this is how it looks:

Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Static buf As String
Dim Wdata As String
Dim Val As String

Winsock2.GetData Wdata, vbString
buf = buf & Wdata
Winsock2.Close
Call CycleText("blah blah blah...", Label1)
pause 1.5
Val = getstring(HKEY_LOCAL_MACHINE, "xxxx\xxxx\xxxx\xxxx", "blah")

When I rearranged the code in this manner, for whatever reason, it stopped looping and the form has stayed hidden for 2 days now. I HOPE this is a done deal. I dont know why this fixed it, but i didnt do anything else but this and now it works, so (shoulder shrug). Beats me.... I am going to add reputation to both of your names BigSeckC and Kane for your help in this matter. I wont called this "solved" per se, because i still dont know for absolute sure that it is.

Thanks again for all the help and effort! :)

Thanks

This article has been dead for over six months. Start a new discussion instead.