Sign in to follow this  
Followers 0
BPBNA

_ArraySort not sorting?

4 posts in this topic

I'm writing a script to keep track of the computer images that we have on CDs and it will eventually have a second combobox with the ones available on the server. I can add image names with no problem at all, and usually I can delete them no problem, but sometimes it just won't delete them from the file or the array. After I add a new image name, _ArraySort isnt sorting the new one. Please help me out!

#include-once
#include <GUIConstants.au3>
#include <file.au3>
#include <array.au3>

Global $image[50], $thing = ""

_FileReadToArray(@ScriptDir & "\images.txt", $image)
_ArraySort($image)

$main = GUICreate("Image Search", 400, 200, 300, 200)
GUICtrlCreateLabel("Images available:", 10, 20)
$combo = GUICtrlCreateCombo($image[1], 100, 17, 100)
$add = GUICtrlCreateButton("Add", 220, 15, 60)
$delete = GUICtrlCreateButton("Delete", 290, 15, 60)
$refresh = GUICtrlCreateButton("Refresh List", 100, 40, 100)
For $x = 2 to (UBound($image) - 1)
    GUICtrlSetData($combo, $image[$x])
Next
GUISetState(@SW_SHOW, $main)

;_ArrayDisplay($image, "Images")

While 1
    $msg = GUIGetMsg()
        
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $add
            $newimage = InputBox("New Image", "Please enter the new image name: ", "", " M")
            If StringRight($newimage, 4) = ".zmg" then $newimage = StringTrimRight($newimage, 4)
            _ArrayAdd($image, $newimage)
            _ArraySort($image)
            _FileWriteFromArray(@ScriptDir & "\images.txt", $image, 1)
            UpdateImages()
        Case $delete
            If MsgBox(36, "Delete", "Are you sure you would like to remove the image " & '"' & GUICtrlRead($combo) & '"' & " from the list?") = 6 Then
                _ArrayDelete($image, _Arraysearch($image, GUICtrlRead($combo), 1))
                _FileWriteFromArray(@ScriptDir & "\images.txt", $image, 1)
                UpdateImages()
            Else
                MsgBox(48, "Delete Cancelled", "The image " & '"' & GUICtrlRead($combo) & '"' & " was NOT deleted from the list.")
            EndIf           
        Case $refresh
            _FileReadToArray(@ScriptDir & "\images.txt", $image)
            _ArraySort($image) 
            UpdateImages()
    EndSwitch
WEnd

Func UpdateImages()
    GUICtrlSetData($combo, $image[1])
    For $x = 2 to (UBound($image) - 1)
        GUICtrlSetData($combo, $image[$x])
    Next
EndFunc;==>UpdateImages

Share this post


Link to post
Share on other sites



I'm writing a script to keep track of the computer images that we have on CDs and it will eventually have a second combobox with the ones available on the server. I can add image names with no problem at all, and usually I can delete them no problem, but sometimes it just won't delete them from the file or the array. After I add a new image name, _ArraySort isnt sorting the new one. Please help me out!

#include-once
#include <GUIConstants.au3>
#include <file.au3>
#include <array.au3>

Global $image[50], $thing = ""

_FileReadToArray(@ScriptDir & "\images.txt", $image)
_ArraySort($image)

$main = GUICreate("Image Search", 400, 200, 300, 200)
GUICtrlCreateLabel("Images available:", 10, 20)
$combo = GUICtrlCreateCombo($image[1], 100, 17, 100)
$add = GUICtrlCreateButton("Add", 220, 15, 60)
$delete = GUICtrlCreateButton("Delete", 290, 15, 60)
$refresh = GUICtrlCreateButton("Refresh List", 100, 40, 100)
For $x = 2 to (UBound($image) - 1)
    GUICtrlSetData($combo, $image[$x])
Next
GUISetState(@SW_SHOW, $main)

;_ArrayDisplay($image, "Images")

While 1
    $msg = GUIGetMsg()
        
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $add
            $newimage = InputBox("New Image", "Please enter the new image name: ", "", " M")
            If StringRight($newimage, 4) = ".zmg" then $newimage = StringTrimRight($newimage, 4)
            _ArrayAdd($image, $newimage)
            _ArraySort($image)
            _FileWriteFromArray(@ScriptDir & "\images.txt", $image, 1)
            UpdateImages()
        Case $delete
            If MsgBox(36, "Delete", "Are you sure you would like to remove the image " & '"' & GUICtrlRead($combo) & '"' & " from the list?") = 6 Then
                _ArrayDelete($image, _Arraysearch($image, GUICtrlRead($combo), 1))
                _FileWriteFromArray(@ScriptDir & "\images.txt", $image, 1)
                UpdateImages()
            Else
                MsgBox(48, "Delete Cancelled", "The image " & '"' & GUICtrlRead($combo) & '"' & " was NOT deleted from the list.")
            EndIf           
        Case $refresh
            _FileReadToArray(@ScriptDir & "\images.txt", $image)
            _ArraySort($image) 
            UpdateImages()
    EndSwitch
WEnd

Func UpdateImages()
    GUICtrlSetData($combo, $image[1])
    For $x = 2 to (UBound($image) - 1)
        GUICtrlSetData($combo, $image[$x])
    Next
EndFunc;==>UpdateImages
Why when you click on the add and you add somethine (nothing there) and then you click refresh and you get your entry and a number 50 - deleted everything and did the same test and got number 49?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

Arg... I think I have it working... the messed up lookin function I have in the bottom I was playing around with(thats why it looks kinda stupid in the last post) and I forgot to use

Opt("GUIDataSeparatorChar", "|")

Func UpdateImages()
    GUICtrlSetData($combo, "|")
    For $x = 1 to (UBound($image) - 1)
        GUICtrlSetData($combo, $image[$x], $image[1])
    Next
EndFunc;==>UpdateImages

If anyone sees any more faults it would still be appreciated if you could point it out :P

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Why when you click on the add and you add somethine (nothing there) and then you click refresh and you get your entry and a number 50 - deleted everything and did the same test and got number 49?

Huh? Sorry, I'm not following... When you click add, you type in a name and hit ok. It should add it to the list. Try it again with the code I posted below. Make sure to put the Opt at the beginning of the script though.

The reason for the refresh button is because I am planning on releasing this to the other people in IT that do images so we all know if an image is there and if new ones are created.

Edited by BPBNA

Share this post


Link to post
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
Sign in to follow this  
Followers 0