Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

haveing problem checking condition...if found

Posted on 2004-10-18
4
Medium Priority
?
161 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
  • 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 1200 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 800 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month7 days, 5 hours left to enroll

783 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