Solved

haveing problem checking condition...if found

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

803 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