Solved

haveing problem checking condition...if found

Posted on 2004-10-18
4
148 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 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now