Solved

haveing problem checking condition...if found

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check only one toolstripmenu item 12 63
Disable the weekends on datepicker control 6 52
VB Catch Statement in Event Viewer. 2 20
Intermittent OleDbConnection Error 20 53
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

759 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