5 Replies - 284 Views - Last Post: 05 February 2013 - 04:33 AM Rate Topic: -----

#1 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 180
  • Joined: 18-May 09

Number boxes are being switched

Posted 04 February 2013 - 06:21 PM

There is an issue with this code which is when the program is run it will generate the correct passwords, but when the Clear button is pressed the NumHowMany & numLength is incorrect it swaps the 2 around, can anyone see any issues? if u need more info please ask. Hope i explained well.

    Private Sub btnGen_Click(sender As System.Object, e As System.EventArgs) Handles btnGen.Click
        Dim r, i, Counter, Numb, Length
        Dim Password As String
        Counter = -0
        If lstPass.Items.Count <= numLength.Value Then
            Length = numLength.Value
            Numb = numHowMany.Value
            If Numb = 0 Then
                MsgBox("You need to enter the amount of Passwords that you want Generated.", vbOKOnly + vbCritical, "How Many?")
            Else
                Length = numLength.Value
                If Length = 0 Then
                    MsgBox("You need to enter the Length of the Passwords you want to create.", vbOKOnly + vbCritical, "How Long?")
                Else
                    While Counter <= Length - 1
                        Counter = Counter + 1
                        Password = ""
                        For i = 1 To Numb
                            Randomize()
                            r = Int((Rnd() * 61) + 1)
                            Password = Password & Mid(Chars, r, 1)
                        Next i
                        lstPass.Items.Add(Password)
                    End While
                    btnGen.Enabled = False
                    btnClear.Enabled = True
                End If
            End If
        Else
            lstPass.Items.Clear()
            btnGen.Enabled = True
            btnClear.Enabled = False
        End If
    End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Number boxes are being switched

#2 b2.f2  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 76
  • Joined: 21-May 07

Re: Number boxes are being switched

Posted 04 February 2013 - 08:37 PM

You are saying that problem occurs when the clear button is pressed and yet you are posting codes from btnGen_Click , pleas post codes from Clear button
Was This Post Helpful? 0
  • +
  • -

#3 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 180
  • Joined: 18-May 09

Re: Number boxes are being switched

Posted 04 February 2013 - 08:53 PM

Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click
        lstPass.Items.Clear()
        btnGen.Enabled = True
        btnClear.Enabled = False
    End Sub


it does it even if the clear button is not pressed. If u generate the password then try and change the numbers it swaps the values also.
Its as if there is a third value and its skipping to increment it.
Was This Post Helpful? 0
  • +
  • -

#4 Guitora Kuronato  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 28
  • Joined: 02-December 12

Re: Number boxes are being switched

Posted 04 February 2013 - 09:13 PM

Just please post all your code
Was This Post Helpful? 0
  • +
  • -

#5 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Number boxes are being switched

Posted 04 February 2013 - 09:45 PM

View PostPNJLj, on 04 February 2013 - 07:21 PM, said:

There is an issue with this code which is when the program is run it will generate the correct passwords, but when the Clear button is pressed the NumHowMany & numLength is incorrect it swaps the 2 around, can anyone see any issues? if u need more info please ask. Hope i explained well.

You are counting generated passwords with Length, and generating the passwords with Numb.
Should be
          While Counter <= Numb - 1
              Counter = Counter + 1    ' !!
              Password = ""
              For i = 1 To Length      ' !!
                  Randomize()
                  r = Int((Rnd() * 61) + 1)
                  Password = Password & Mid(Chars, r, 1)
              Next i
              lstPass.Items.Add(Password)
          End While


Was This Post Helpful? 1
  • +
  • -

#6 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 180
  • Joined: 18-May 09

Re: Number boxes are being switched

Posted 05 February 2013 - 04:33 AM

Thankyou so much, That fixed the problem.
Much Appreciated.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1