Solved

haveing problem checking condition...if found

Posted on 2004-10-18
4
155 Views
Last Modified: 2012-05-05
if trying to see if Test_User@testing.com is in USERS.Items(i).UserName

the below code keeps fireing
MsgBox("Now your server has " & USERS.Count & " users")
no matter what i do

any other ways to check this?? im stumped!!

thx
Johnny
aka Pern

        found = 0
        For i = 0 To USERS.Count - 1
            If (USERS.Items(i).UserName = "Test_User@testing.com") Then
                'MsgBox("The User: " & USER.UserName & " all ready exist")
                found = 1
            Else
                'USERS.Add(USER)
                'MsgBox("Now your server has " & USERS.Count & " users")
                found = 0
            End If
        Next i

        If (found = 1) Then
            MsgBox("The User: " & USER.UserName & " all ready exist")
            'found = 1
        Else
            'USERS.Add(USER)
            MsgBox("Now your server has " & USERS.Count & " users")
            'found = 0
        End If
0
Comment
Question by:Johnny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 12343488
Hi I think you have forget to break your for loop!
0
 
LVL 5

Assisted Solution

by:KarcOrigin
KarcOrigin earned 300 total points
ID: 12343501
Try this-

        found = 0
        For i = 0 To USERS.Count - 1
            If (USERS.Items(i).UserName = "Test_User@testing.com") Then
                'MsgBox("The User: " & USER.UserName & " all ready exist")
                found = 1
                Exit For ' <----------- THIS STATEMENT
            Else
                'USERS.Add(USER)
                'MsgBox("Now your server has " & USERS.Count & " users")
                found = 0
            End If
        Next i

        If (found = 1) Then
            MsgBox("The User: " & USER.UserName & " all ready exist")
            'found = 1
        Else
            'USERS.Add(USER)
            MsgBox("Now your server has " & USERS.Count & " users")
            'found = 0
        End If

Although I don't have an idea what is your USERS structure type but I suppose Exit For statement is needed if you found that USERS.Items(i).UserName = "Test_User@testing.com"

Cheers!
0
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 200 total points
ID: 12345125
Exit For is needed of course but there should not be any ELSE BLOCK

try this


 found = 0
        For i = 0 To USERS.Count - 1
            If (USERS.Items(i).UserName = "Test_User@testing.com") Then
                'MsgBox("The User: " & USER.UserName & " all ready exist")
                found = 1
                Exit For
            End If
               
'---------> These Statements should be out of the If Block, No Else Block

                'USERS.Add(USER)
                'MsgBox("Now your server has " & USERS.Count & " users")
                found = 0
           
        Next i

        If (found = 1) Then
            MsgBox("The User: " & USER.UserName & " all ready exist")
            'found = 1
        Else
            'USERS.Add(USER)
            MsgBox("Now your server has " & USERS.Count & " users")
            'found = 0
        End If
0
 

Author Comment

by:Johnny
ID: 12347056
you where both tight  so i awarded more points to the assisted answer and less to the acepted answer as i couldnt figure out who did more so i balanced it out as i felt the acepted answer was worth more...

thx i was stupid i should have known that after finding the solution to exit it...

thx
Johnny
aka Pern
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question