Jump to content

Looping Help


savj14
 Share

Recommended Posts

I just can't figure this out.......I am trying to do a check to make sure something is in the List to Delete. If there is nothing in the List than shoot an error. If there is Send a confirmation Msgbox and then delete.

Right now it will shoot the error message back to you even if there is something in the List. I hope someone can help me out.

Case $msg = $Visio_Delete
    If _GUICtrlListViewDeleteItemsSelected($Visio_List)="" Then
    msgbox(0, "Error", "Nothing to Delete")
    ContinueLoop
    EndIf
    MsgBox(4, "Delete?", "Are you Sure you want to Delete " & GUICtrlRead($Visio_User_First) & " " & GUICtrlRead($Visio_User_Last)) 
_GUICtrlListViewDeleteItemsSelected ($Visio_List)
ContinueLoop
Link to comment
Share on other sites

I would think you don't really want to use _GUICtrlListViewDeleteItemsSelected() in the IF as that is checking the outcome of the delete.

You want to read the list here to see if it has anything in it, so you want to use something like _GUICtrlListViewGetItemCount() instead and test for = 0

Link to comment
Share on other sites

Hi Savj14,

The reason you are continuously getting the error message, regardless of if something is in the list or not, is because _GUICtrlListViewDeleteItemsSelected($Visio_List) has no return value for the IF statement to reference.

The function you are looking for is

_GUICtrlListViewGetSelectedCount($Visio_List)

This function returns the number of items selected in the given listview.

This here, should get your case working properly.

Case $msg = $Visio_Delete
    If _GUICtrlListViewGetSelectedCount($Visio_List)=0 Then
    msgbox(0, "Error", "Nothing to Delete")
    ContinueLoop
    EndIf
    If MsgBox(4, "Delete?", "Are you Sure you want to Delete " & GUICtrlRead($Visio_User_First) & " " & GUICtrlRead($Visio_User_Last)) = 7 Then 
        ContinueLoop
    Else
        _GUICtrlListViewDeleteItemsSelected ($Visio_List)
    EndIf

I went ahead and added the error checking into the MsgBox for you. Without the If statement in there, testing the return of the message box, it would have deleted your record anyway.

If you have any further questions, just ask.

~Felanor

Link to comment
Share on other sites

too many if and useless commands like continue loop, this fits what you want:

Case $msg = $Visio_Delete
    If _GUICtrlListViewGetSelectedCount($Visio_List) = 0 Then
    MsgBox(0, "Error", "Nothing to Delete")
    Else
    If MsgBox(4, "Delete?", "Are you Sure you want to Delete " & GUICtrlRead($Visio_User_First) & " " & GUICtrlRead($Visio_User_Last)) = 6 Then _GUICtrlListViewDeleteItemsSelected ($Visio_List)
    EndIf
Link to comment
Share on other sites

Thanks for the Help it is working perfectly.

I was wondering how to check for duplicate entries in the List. I want to have a loop check before it adds the entry to the list. I have no clue where to start

Here is my code to add the entry to the List:

;Add User to List   
        GUICtrlCreateListViewItem(GUICtrlRead($Visio_User_First) & "|" & GUICtrlRead($Visio_User_Last) & "|" & GUICtrlRead($Visio_Version), $Visio_List)
        GUICtrlSetData($Visio_User_First,"")
        GUICtrlSetData($Visio_User_Last,"")
            ContinueLoop
Link to comment
Share on other sites

Here is what I have so far:

;Add User to List
    $Visio_Duplicate = _GUICtrlListViewFindItem ($Visio_List, GUICtrlRead($Visio_User_First), -1, BitOR($LVFI_STRING, $LVFI_WRAP))
    $Visio_Duplicate2 = _GUICtrlListViewFindItem ($Visio_List, GUICtrlRead($Visio_User_Last), -1, BitOR($LVFI_STRING, $LVFI_WRAP))      
            If $Visio_Duplicate <> -1 And $Visio_Duplicate2 <> -1 Then
                MsgBox(0, "Error: User Cannot Be Added", "This User Already Exists")
            Else
        GUICtrlCreateListViewItem(GUICtrlRead($Visio_User_First) & "|" & GUICtrlRead($Visio_User_Last) & "|" & GUICtrlRead($Visio_Version), $Visio_List)
        GUICtrlSetData($Visio_User_First,"")
        GUICtrlSetData($Visio_User_Last,"")
            ContinueLoop
        EndIf

It doesn't seem to work with the And statement. If I take it out it won't add an entry with the same first name. I can't seem to get this to check both first and last name.

Any ideas?

Link to comment
Share on other sites

  • Moderators

Anyone out there??

Yes..

In answer to your question, you haven't even provided "failing" code to try and decipher what it is you are trying to achieve.

The snippet you provided doesn't illustrate the true issue (which is all the code before it).

My suggestion would be to take some time to write a "working" / "non-working" example... confusing? I think you should at least create(and post) a recreation script that shows your "Exact" problem... before you can expect to be helped.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Yes..

In answer to your question, you haven't even provided "failing" code to try and decipher what it is you are trying to achieve.

The snippet you provided doesn't illustrate the true issue (which is all the code before it).

My suggestion would be to take some time to write a "working" / "non-working" example... confusing? I think you should at least create(and post) a recreation script that shows your "Exact" problem... before you can expect to be helped.

That is exactly what I did was post the "Failing Code"..........I explained that it worked when I did this and Failed when I did this........if you go back and read my posts you will see.........Not sure what point you are trying to make with you post other than to confuse people

Link to comment
Share on other sites

  • Moderators

That is exactly what I did was post the "Failing Code"..........I explained that it worked when I did this and Failed when I did this........if you go back and read my posts you will see.........Not sure what point you are trying to make with you post other than to confuse people

How about a workable GUI, so we don't have to waist our time making one to help you!

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

How about a workable GUI, so we don't have to waist our time making one to help you!

I have a GUI.........and have never said one word about needing help with making one...I just posted the portion of the code where I am having some issues. I don't feel that the GUI and/or the rest of my code needs to be posted...I am not looking for a hand me out here. You are the only person here that doesn't seem to be helping in any way, just making things more complicated. I'd appreciate it if you would not post in this thread again.

I will provide you with some help.........FYI:

"so we don't have to waist our time making one to help you!"

The correct word you are looking for here is "waste", as waist is a part of the human body.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...