Results 1 to 22 of 22

Thread: Checking from a list

  1. #1

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Checking from a list

    Alright, I have a listbox, and I dont really know much about them, one of the few I dont know alot about. I know some of the basics, but what Im looking to do is run like a check. I have two listboxes, each with items in them. I want to take the first item in the first listbox, and match it with the first item in the second listbox. Im going to use a small command that puts the two together and checks if its valid. Then, after the first two are checked, I want to take the second item in the second list and match it again with the first one. Can someone give me an example loop on how this would work? Thanks in advanced

  2. #2
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Checking from a list

    try this
    VB Code:
    1. Dim i As Integer, x As Integer
    2.  
    3. For i = 0 To List1.ListCount - 1
    4.  For x = 0 To List2.ListCount - 1
    5.   MsgBox List1.List(i) & List2.List(x) 'this line holds the 2 joined items.
    6.  Next x
    7. Next i

    casey.

  3. #3

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: Checking from a list

    No, its kind of hard to explain. Im just confused how I would make the loop. Alright, here is what I have. I got 2 list boxes, this program is desgined to check if your user and passwords are valid. In one list is the username, in the other is the password. What I want to do once started, is for the first item in the user list, to goto a textbox. Then the first item in the second list go into the second textbox. Once that is done, Im going to run a check, and after its complete, its need to continue. When it continues the 2 textboxes will be set to nothing, then I want the first item in the first list to appear again in the first box, and the second item in the second list to appear in the second box. Then it will do the check and continue. I want it to run like this until the second list is empty, or everything checked. I just dont know how the loop would look, thats where I need help.

    So the procedure would go like:

    1. First item in the first list is put in the first textbox
    2. First item in the second list is put in the second textbox
    3. The check is run and the two textboxes are cleared
    4. The first item in the first list gets put back into the first textbox
    5. The second item in the second list is put in the second listbox
    6. The check is run and boxes are cleared
    7. Process repeats with the first item going back into the first textbox, then the third item on the second list going into the second textbox and running the check again
    8. This goes on until the second list is all checked.
    Last edited by Inuyasha1782; Jul 8th, 2005 at 07:20 PM.

  4. #4
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Checking from a list

    Inuyasha1782, I know you are using ListBox's because of the example I made for you a couple days. You need to use just the arrays. The arrays are anything that you Dim at the top of a sub or the form. Let me know if you need an example.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Checking from a list

    This looks like you are creating a dictionary cracker, with a list of known user names and different passwords, and would be against the AUP to discuss. Please explain how you would attempt to use this to do anything but that.

  6. #6
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Checking from a list

    No, I think he has a list of passwords then a list of usernames and wants to check if the username and password are valid. Here is a short example of how I would do it:
    VB Code:
    1. Dim strName() As String
    2. Dim strPass() As String
    3.  
    4. Private Sub Command1_Click()
    5.   Dim strMyName As String
    6.   Dim strMyPass As String
    7.  
    8.   strMyName = txtName.Text
    9.   strMyPass = txtPass.Text
    10.  
    11.   For i = 0 to UBound(strName)
    12.     If strName(i) = strMyName then
    13.       For j = 0 to UBound(strPass)
    14.         If strPass(j) = strMyPass then
    15.           ' the name and pass are correct
    16.         Else
    17.           ' wrong pass
    18.         End If
    19.       Next j
    20.     Else
    21.       ' wrong name
    22.     End If
    23.   Next i
    24. End Sub
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Checking from a list

    Why would you need that? I'll take care of my own password, thank you.

  8. #8

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: Checking from a list

    rawr! I knew that would come up, I was just hoping I would not get accused of it. On the game, its normal to have many accounts, and this is just a small program to see if they are still valid. Sorry if it was taken in a malicious matter. Anyways, no, Im using listboxes for a reason =0 They need to know what they put dont they... Anyways, I'll check out the coding, thanks.

    *Edit* In your coding, what exactly are you doing, you comment that you are checking, when I have my own way of checking, or did I misunderstand you?

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Checking from a list

    Why would you check one user with all the account passwords? Unless I missed something, that sounds like what you want to do.

  10. #10

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: Checking from a list

    I suck at explaning things rotfl. I messed up in my second post, I ment each password, with each user. Sorry about that, Im still confused about that example though >_<

  11. #11
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Checking from a list

    If you have a way to validate, this is each user with each corresponding password


    VB Code:
    1. Dim i As Integer
    2.  
    3. For i = 0 To List1.ListCount - 1
    4.   MsgBox List1.List(i) & List2.List(x) 'this line holds the 2 joined items.
    5. Next i

  12. #12

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: Checking from a list

    Ok so here is what I have:

    VB Code:
    1. Private Sub Command4_Click()
    2.  
    3. Dim i As Integer
    4.  
    5.  
    6. For i = 0 To lstWebsites.ListCount - 1
    7.   MsgBox lstWebsites.List(i) & lstPass.List(x) 'this line holds the 2 joined items.
    8. Next i
    9.  
    10. End Sub

    In list one there is Girly, and text. In list two there is Johnny, and cadeo. So when they match it should go Girly, and Johhny. Then text and cadeo. After testing it, it went, Girly Johhny, and Text johnny, but it should of been text cadeo. What happened?

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Checking from a list

    Sorry about that. I left the x in there. If you used Option Explicit for every form, you would have gotten an error, letting you know that X wasn't declared.
    Then you would have seen that I elimated the X loop. Hopefully you would have used the i loop. In your case, i was 0 both times.

    VB Code:
    1. Option Explicit
    2. Private Sub Command4_Click()
    3.  
    4. Dim i As Integer
    5.  
    6.  
    7. For i = 0 To lstWebsites.ListCount - 1
    8.   MsgBox lstWebsites.List(i) & lstPass.List(i) 'this line holds the 2 joined items.
    9. Next i
    10.  
    11. End Sub

  14. #14

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: Checking from a list

    Yea I got yours to work. Well from your code above, and this code too, it does it twice. Like it will msgbox two times, I only want it to do it once, so I can check, then do it again, check etc etc. So here is what it looks like:

    VB Code:
    1. Private Sub Command4_Click()
    2.  
    3. Dim i As Integer
    4.  
    5.  
    6. For i = 0 To lstPass.ListCount - 1
    7.   Pass.Text = lstPass.List(i)
    8.   User.Text = lstUser.List(x) 'this line holds the 2 joined items.
    9. Next i
    10.  
    11. End Sub

    See I just want it to enter the first two into the correct box, except it does the second matching ones, basicly as far down as the list can go, since there are only two items. How do you control it to fit what I want?

  15. #15
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Checking from a list

    You are leaving off some of the code, and I wonder about it, but this is the change that I just made.
    VB Code:
    1. Private Sub Command4_Click()
    2.  
    3. Dim i As Integer
    4.  
    5.  
    6. For i = 0 To lstPass.ListCount - 1
    7.   Pass.Text = lstPass.List(i)
    8.   User.Text = lstUser.List([COLOR=Red]i[/COLOR]) 'this line holds the 2 joined items.
    9. Next i
    10.  
    11. End Sub

  16. #16

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: Checking from a list

    Yea, thats what I ment, but thats not fixing the problem, it checks the last user and pass. Like the last would be text and cadeo, it skips girly and johnny and goes to text cadeo.

  17. #17
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Checking from a list

    Oh. I see what you want. You have to declare x as a static
    You want to check only one at a time. OK. This will prolly do it.

    VB Code:
    1. Private Sub Command4_Click()
    2.   static i as integer
    3.   if i= lstPass.ListCount - 1 then i=0 ' loop if you repeat
    4.   Pass.Text = lstPass.List(i)
    5.   User.Text = lstUser.List(i) 'this line holds the 2 joined items.
    6.   i=i+1
    7. End Sub

  18. #18
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Checking from a list

    Sorry Inuyasha, I thought you were looking for a basic password checking this.I misunderstood.

    No offense, but please try to read your posts before you submit them and fix grammer/spelling errors. You seem like English might not be your first language, and thats totally fine. It would just help us understand you better if you spent a few extra seconds before you post. Thanks.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  19. #19

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: Checking from a list

    Sorry about that, Ill take that into consideration. Anyways, so that does the first pair, how would you continue it? It's not like Next i or anything, so it's a little bit different for me.

    This was kind of my whole problem, just getting the loop right to check all of them.

  20. #20
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Checking from a list

    I thought you were using a listbox, which is why I have the first statement. If the value is too high, it gets reset to 0. The i=i+1 loops through the listbox. It is using LstPass, which is what I thought you wanted.
    VB Code:
    1. if i= lstPass.ListCount - 1 then i=0 ' loop if you repeat
    2.   Pass.Text = lstPass.List(i)
    3.   User.Text = lstUser.List(i) 'this line holds the 2 joined items.
    4.   i=i+1

    The static keyword keeps it from resetting i to zero each time.

  21. #21

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: Checking from a list

    Yes, I mean its all right now, it matches up right, but only once. Now that its done it the first time, I want it to continue on, after I do the check. Here is what the code looks like:

    VB Code:
    1. Private Sub Command4_Click()
    2. Static i As Integer
    3.   If i = lstPass.ListCount - 1 Then i = 0 ' loop if you repeat
    4.   Pass.Text = lstPass.List(i)
    5.   User.Text = lstUser.List(i) 'this line holds the 2 joined items.
    6.   i = i + 1
    7. Check
    8. End Sub

    See, the check is just a simple check stament, after it checks the first, I want it to continue on to the second pair.

  22. #22
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Checking from a list

    That's what I had the first time. To get the next instance, you can just click the button again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width