Post Reply 
VB.net help
Author Message
roberth
Resident Full Stop Abuser.....

Posts: 4,580.2098
Threads: 200
Joined: 18th Jun 2007
Reputation: -5.5814
E-Pigs: 43.8419
Offline
Post: #11
RE: VB.net help
ahh...so its pretty simple then i assume..our lecturer was making out it would be really hard (gimp)

01/11/2007 04:22 AM
Find all posts by this user Quote this message in a reply
roberth
Resident Full Stop Abuser.....

Posts: 4,580.2098
Threads: 200
Joined: 18th Jun 2007
Reputation: -5.5814
E-Pigs: 43.8419
Offline
Post: #12
RE: VB.net help
Next Question now


Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
       Dim Password As String
        Dim InputPassword As String
        Dim Attempt As Integer
        Password = "test"
        Attempt = 1


        Do
            InputPassword = InputBox("Enter password. This is attempt number " & Attempt & ".")

            Attempt = Attempt + 1


        Loop Until (Attempt = 4) Or (InputPassword = Password)


        If InputPassword = Password Then
            MsgBox("Well Done...not that it was that hard to guess")
            Dim F2 As New Form2()

            F2.Show()
        Else
            MsgBox("LIARS!!!!!!!!!!!")
        End If


Wee've been given this code, and need to Mask the password box, but i have no idea, not even slightly, everything i tried failed miserably

Can anyone mask this, or give me a code with the same function that will work please???


02/11/2007 04:53 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA
Smart Alternative

Posts: 17,022.2988
Threads: 1,174
Joined: 19th Jan 2007
Reputation: -1.71391
E-Pigs: 446.1274
Offline
Post: #13
RE: VB.net help
From knowledge of VB6, you can't mask an InputBox (well, not without some subclassing of sorts - probably too much for you).

What you need to do is make a new form, just for the password, and have a masked textbox or passwordbox.
02/11/2007 07:07 AM
Visit this user's website Find all posts by this user Quote this message in a reply
roberth
Resident Full Stop Abuser.....

Posts: 4,580.2098
Threads: 200
Joined: 18th Jun 2007
Reputation: -5.5814
E-Pigs: 43.8419
Offline
Post: #14
RE: VB.net help
in that case...what command do i use to shutdown a form when i load up a new one then, even our lecturer didnt know, i will confess hes useless

Oh...and

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Dim Password As String
        Dim F1 As New Form1
        Dim F3 As New Form3
        Dim F2 As New PswrdScreen
        Dim Attempt As Integer
        Password = "test"
        Attempt = 1


        Do
            lblAttempt.Text = "Enter password. This is attempt number " & Attempt
            Attempt = Attempt + 1
        Loop Until (Attempt = 4) Or (txtPass.Text = Password)
        If txtPass.Text = Password Then
            MsgBox("This password is valid!")
            F3.Show()

        Else
            MsgBox("This password is invalid!")
        End If


What's wrong with this that's making the loop not work with my label?? (it is named correctly)

Wee have another breakththrough, i realise why the label isn't showing up correctly, it has to be defined as F2.lblAttempt in form1, i think

If i post up, in a zip file, what i have so far, can anyone experienced that a peep at whazt im doing wrong??


.zip  Compiled Programs.zip (Size: 69.05 KB / Downloads: 211)

Oh, and ignore form3, i know it can be done better, but it suits my purposes, and it was the easiest way wee knew


(This post was last modified: 02/11/2007 02:32 PM by roberth.)
02/11/2007 07:59 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA
Smart Alternative

Posts: 17,022.2988
Threads: 1,174
Joined: 19th Jan 2007
Reputation: -1.71391
E-Pigs: 446.1274
Offline
Post: #15
RE: VB.net help
roberth - try looking into modal forms.  IDK how to do it in VB.NET, but in VB6, it would be something like:

Code:
F3.Show(Me, vbModal)

A modal form stops execution in the current form, like an InputBox.

Another point, your logic here is incorrect:

Code:
        Do
            lblAttempt.Text = "Enter password. This is attempt number " & Attempt
            Attempt = Attempt + 1
        Loop Until (Attempt = 4) Or (txtPass.Text = Password)

What you're saying is, set the label, increment a variable, then keep looping until you've incremented the variable to 4 (note that the label is set before the incrementation, so it will display "3").  The condition (txtPass.Text = Password) is irrelevant, as txtPass is never updated (the user is never given the chance).

What you should do is have some code like you did before, with the InputBox.  Instead of using an InputBox however, use a modal form.

02/11/2007 07:04 PM
Visit this user's website Find all posts by this user Quote this message in a reply
roberth
Resident Full Stop Abuser.....

Posts: 4,580.2098
Threads: 200
Joined: 18th Jun 2007
Reputation: -5.5814
E-Pigs: 43.8419
Offline
Post: #16
RE: VB.net help
not completley sure i understand :P, but i can see what you mean

And where have i defined my attempt as 3 exactly??...i can't find it, and that's one of the major problems :(


Haha...very nealry done now...only problem is that i can't seem to stop the process after one attempt up

Ill get this soon

(This post was last modified: 03/11/2007 04:41 AM by roberth.)
03/11/2007 04:04 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA
Smart Alternative

Posts: 17,022.2988
Threads: 1,174
Joined: 19th Jan 2007
Reputation: -1.71391
E-Pigs: 446.1274
Offline
Post: #17
RE: VB.net help
roberth Wrote:And where have i defined my attempt as 3 exactly??...i can't find it, and that's one of the major problems :(
Okay, umm, I'll try to explain it better:

Code:
Do
            lblAttempt.Text = "Enter password. This is attempt number " & Attempt
            Attempt = Attempt + 1
        Loop Until (Attempt = 4) Or (txtPass.Text = Password)

So, when you start the loop, Attempt =1.
First thing you do in the loop is set the attempt label to "1", then you add 1 to Attempt (so Attempt =2)

Then it will check the loop condition.  Since txtPass.Text is never changed within the loop, (txtPass.Text = Password) will _always_ be false.  So the condition can be broken down to Loop Until (Attempt = 4) Or False
You're "Or'ing" a False, which is equivalent to not "Or'ing" anything, so the above condition is equivalent to Loop Until (Attempt = 4).

Okay, so, since Attempt =2 at this point in time, the condition is False, and the loop continues.

On the next iteration of the loop, Attempt =3.

On the next iteration after that, when Attempt =3, the label is set to "3", Attempt is incremented (so Attempt now =4).  Then wee check the loop condition.  (Attempt = 4) is now true, so the loop exits.

So, the last value the label was set is "3".

This is because the loop isn't "delayed", that is, the computer sets the label to "1", "2" then "3", however, it does it so fast that you only see the final thing, a "3".

Hope that helps.

03/11/2007 04:50 AM
Visit this user's website Find all posts by this user Quote this message in a reply
roberth
Resident Full Stop Abuser.....

Posts: 4,580.2098
Threads: 200
Joined: 18th Jun 2007
Reputation: -5.5814
E-Pigs: 43.8419
Offline
Post: #18
RE: VB.net help
yeah, i see, ive updated it to this

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
        Do
            lblAttempt.Text = "Enter password. This is attempt number " & Attempt
  
            If txtPass.Text = Password Then
                MsgBox("This password is valid!")
                F3.Show()
                Close()

            Else
                MsgBox("This password is invalid!")
            End If
            Attempt = Attempt + 1
        Loop Until Attempt = 3


And the loop works fine now, but i want the end if to go after the loop until ,yet all it does is bitch at me if i try that

Well, fine ish. It loops, but i can't define it to stop, as i don't know how, and wheehter or not its right, it displays whichever text box 3 times before ending itself, either back to Form1 (without a chance for another attempt), or into the currency convertor..so i think im getting closer, but im not there yet am i...


(This post was last modified: 03/11/2007 05:41 AM by roberth.)
03/11/2007 05:00 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA
Smart Alternative

Posts: 17,022.2988
Threads: 1,174
Joined: 19th Jan 2007
Reputation: -1.71391
E-Pigs: 446.1274
Offline
Post: #19
RE: VB.net help
I don't know if this is valid VB.NET syntax (you'll have to look it up), but this is probably what you should write.  I hope you can understand the logic of the code.

Well...
Spoiler for Solution:

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Public Class PswrdScreen
	' this is stored globally, so that we remember the number of tries between
	' each attempt
	' Note, I've made this "zero based" (starts at 0) because IDK what the Form_Load()
	' function in Vb.NET is
	Dim Attempt As Integer
	
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGuess.Click
        Dim Password As String
        Dim F1 As New Form1
        Dim F3 As New Form3
        Password = "test"
		
		' If the user has had too many attempts...
		If Attempt >= 3 Then
			MsgBox("You have tried and failed too many times, my friend")
			Close()
		End If
		
		' Show the user the number of attempts made
		Attempt = Attempt + 1
		lblAttempt.Text = "Enter password. This is attempt number " & Attempt
		
		' validate password
        If txtPass.Text = Password Then
            MsgBox("This password is valid!")
            F3.Show()
            Close()

        Else
            MsgBox("This password is invalid!")
			' We don't need to close this form!
            'F1.Show()
            'Close()

        End If
    End Sub

    Private Sub txtPass_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPass.TextChanged

    End Sub
End Class

How does this work without a loop?  Well, think of it as a user initiated loop.

If you still want to take a punt at it, I'll give you a hint - using a loop is probably not the best way (might be if you were writing C).
03/11/2007 07:19 AM
Visit this user's website Find all posts by this user Quote this message in a reply
roberth
Resident Full Stop Abuser.....

Posts: 4,580.2098
Threads: 200
Joined: 18th Jun 2007
Reputation: -5.5814
E-Pigs: 43.8419
Offline
Post: #20
RE: VB.net help
Indeed, i see

Makes sense, and ill try it out asap

all works fine, except the value Attempt doesn't go up still, and in the code you supplied it isn't defined as an integer, is there a reason for that??

(This post was last modified: 04/11/2007 05:53 AM by roberth.)
04/11/2007 05:36 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

 Quick Theme: