Sign in to follow this  
Followers 0
billthecreator

Im stuck in a hole, can you throw a rope?

2 posts in this topic

#1 ·  Posted (edited)

Im trying to make a program like an address book, had it working for a while but somethings wrong. Heres what i got...

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <GuiList.au3>
#include <File.au3>


Dim $data_Location = @ScriptDir & "\Data\"
Dim $File_Location = @ScriptDir & "\Data\Customerinfo.ini"
Dim $File_Location2 = @ScriptDir & "\Data\Dellservlogin.ini"
Dim $num = 0, $Input[5], $data_[5]

DirGetSize($data_Location)
If @error = 1 Then
DirCreate($data_Location)
EndIf

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$Gui = GUICreate("Address Book",788,514, 120,-1)
GUISetBkColor (0xE1E9F6)
GUICtrlCreateGroup ("Search", 4, 0, 475, 45)
GUICtrlCreateGroup ("Aktionen", 485, 0, 300, 45)
$Combo = GuiCtrlCreateCombo("", 290, 18, 90, 120, $CBS_DROPDOWNLIST)
$String = GuiCtrlCreateInput("", 10, 18, 250, 20)
GUICtrlCreateLabel ( "in", 270, 21 )
GUICtrlSetData($Combo,"Last Name|First Name|Address|E-mail Address|Telephone", "Last Name")

$Button_1 = GuiCtrlCreateButton("Search", 390, 18, 80, 20)
$Button_2 = GuiCtrlCreateButton("Delete", 695, 18, 80, 20)
$Button_3 = GuiCtrlCreateButton("Close", 595, 18, 80, 20)
$Button_4 = GuiCtrlCreateButton("New", 495, 18, 80, 20)
$List = GuiCtrlCreateListView ("Last Name|First Name|Address|E-mail Address|Telephone",4,50,780,460,-1, BitOR($LVS_EX_REGIONAL, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
GUICtrlSetState($String,$GUI_FOCUS)
GuiSetState()

$Gui3 = GUICreate("New Entry",120, 514, 913,-1, -1, -1, $Gui)
GUISetBkColor (0xE1E9F6)
$aInput[1] = GuiCtrlCreateInput("Last Name",  5, 5, 110, 20)
$aInput[2] = GuiCtrlCreateInput("First Name", 5,30, 110, 20)
$aInput[3] = GuiCtrlCreateInput("Address", 5, 55, 110, 20)
$aInput[4] = GuiCtrlCreateInput("E-mail Address", 5, 80, 110, 20)
$aInput[5] = GuiCtrlCreateInput("Telephone", 5, 105, 110, 20)
$aButton_1 = GuiCtrlCreateButton("Add", 5, 130, 50, 20)
$aButton_2 = GuiCtrlCreateButton("Cancel", 60, 130, 50, 20)

GUICtrlSetOnEvent($aButton_1, "add_List")
GUICtrlSetOnEvent($Button_2, "Remove_Entry")
GUICtrlSetOnEvent($Button_3, "Close_List")


Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($List) ]

;~ Load the previously saved data

While 1
    $i = GuiGetMsg(1)
    Select
    Case $i = $GUI_EVENT_CLOSE And $i[1] = $Gui
        ;~   Save listview data into the ini file before closing
        Exit
;~   A search function
    Case $i = $Button_2
        $confirm = MsgBox (4, "Delete", "Are you sure you want to delete?")
        If $confirm = 6 Then
            _GUICtrlListViewDeleteItemsSelected($List)
        EndIf
    Case $i = $Button_4
        GUISetState (@SW_SHOW , $Gui3)
    Case $i = $aButton_2
        GUISetState (@SW_Hide , $Gui3)
    Case $i = $aButton_1
        
;~   Save as a new item in the listview
        GUISetState (@SW_HIDE , $Gui3)
    Case $i = $GUI_EVENT_CLOSE And $i[1] = $Gui3
        GUISetState (@SW_HIDE , $Gui3)
    Case $i = $List
        _GUICtrlListViewSort($List, $B_DESCENDING, GUICtrlGetState($List))
    EndSelect
WEnd

Func SaveListView($list, $file)
    $data = ''
    For $i = 0 To _GUICtrlListViewGetItemCount($list) - 1
        $data &= _GUICtrlListViewGetItemText($list, $i) & @CRLF
    Next
    $data = StringTrimRight($data,2)
    FileDelete($file)
    FileWrite($file, $data)
EndFunc

Func LoadListView($list, $file)
    $data = FileRead($file)
    $data = StringSplit($data, @CRLF, 1)
    For $i = 1 To $data[0] - 1
        GuiCtrlCreateListViewItem($data[$i],$List)
    Next
EndFunc

Func Close_List()
Local $s_indices = _GUICtrlListViewGetSelectedIndices($List)
GUISetState(@SW_HIDE, $Gui3)
_GUICtrlListViewDeleteAllItems($List)
GUISetState(@SW_HIDE, $Gui3)
GUISetState(@SW_SHOW, $Gui)
GUISetState(@SW_RESTORE, $Gui)
EndFunc

Func add_List()
$length = _FileCountLines($File_Location)
If $length = 0 Then $length = 1
IniWrite($File_Location, "CustomerInfo", $length, GUICtrlRead($aInput[1]) & "," & GUICtrlRead($aInput[2]) & "," & GUICtrlRead($aInput[3]) & "," & GUICtrlRead($aInput[4]) & "," & GUICtrlRead($aInput[5]))
Clear_List()
MsgBox(262208, "Success!", "Customer has been added... ", 1)
EndFunc ;==>Save_Button

Func Clear_List()
FileDelete($data_Location & "CustomerInfo.bak")
FileDelete(@TempDir & "\new.ini")
FileCopy($File_Location, $data_Location & "CustomerInfo.bak", 1)
FileWriteLine(@TempDir & "\new.ini", "[CustomerInfo]")
$t = 0
$length = _FileCountLines($File_Location)
For $x = 1 To $length - 1
$temp_file = IniRead($File_Location, "CustomerInfo", $x, "Not Found")
If $temp_file = "Not Found" Then Return
$temp_split = StringSplit($temp_file, ",")
If $temp_split[1] = "" Then ContinueLoop
$t = $t + 1
IniWrite(@TempDir & "\new.ini", "CustomerInfo", $t, $temp_split[1] & "," & $temp_split[2] & "," & $temp_split[3] & "," & $temp_split[4] & "," & $temp_split[5])
Next
FileCopy(@TempDir & "\new.ini", $File_Location, 1)
EndFunc

Func Remove_Entry()
If GUICtrlRead($Input[1]) = "" then 
MsgBox(262208, "Sorry...", "No Customer Found/Selected... ", 1)
Return
EndIf
IniWrite($File_Location, "CustomerInfo", $num, ",,,,,,,,,,,,,")
FileDelete($data_Location & $num &".dat")
for $x = 1 to 5
GUICtrlSetData($Input[$x], "")
Next
Clear_List()
MsgBox(262208, "Alert!", "Customer Removed from the Database! ", 1)
EndFunc
Edited by billthecreator

[font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap

Share this post


Link to post
Share on other sites



Add

Dim $aInput[6]oÝ÷ ÙÊ&éí¢ëh®·¦¢÷ºÚ"µÍÜ
    ][ÝÑÕRSÛ][[ÙI][ÝËJHÈÚ[ÙHÈÛ][[ÙBoÝ÷ ØZ¦®Ëajܨ¹Ú'¢ØZ½æ§ÉëÞ۲ʫ^w­*.­Ê'¶º%±©ÝÊ«±Êâ¦Ø¬jZÞiÜ¡×~ÚÈ%¢©àzØ^ë,j¥¢m¡«­¢+Ø)]¡¥±Ä(ÀÌØí¤ôÕ¥Ñ5Í Ä¤(M±Ð(
ÍÀÌØí¥lÁtôÀÌØíU%}Y9Q}
1=M¹ÀÌØí¥lÅtôÀÌØíÕ¤(íøMÙ±¥ÍÑÙ¥ÜÑ¥¹Ñ¼Ñ¡¥¹¤¥±½É±½Í¥¹(á¥Ð(íøÍÉ Õ¹Ñ¥½¸(
ÍÀÌØí¥lÁtôÀÌØí  ÕÑѽ¹|È(ÀÌØí½¹¥É´ô5Í   ½à аÅÕ½Ðí±ÑÅÕ½Ðì°ÅÕ½ÐíÉå½ÔÍÕÉå½ÔݹÐѼ±ÑüÅÕ½Ðì¤(%ÀÌØí½¹¥É´ôØQ¡¸(}U%
Ñɱ1¥ÍÑY¥Ý±Ñ%ѵÍM±Ñ ÀÌØí1¥ÍФ(¹%(
ÍÀÌØí¥lÁtôÀÌØí  ÕÑѽ¹|Ð(U%MÑMÑÑ¡M]}M!=°ÀÌØíդ̤(
ÍÀÌØí¥lÁtôÀÌØí  ÕÑѽ¹|È(U%MÑMÑÑ¡M]}!¥°ÀÌØíդ̤(
ÍÀÌØí¥lÁtôÀÌØí  ÕÑѽ¹|Ä((íøMÙ̹ܥѴ¥¸Ñ¡±¥ÍÑÙ¥Ü(U%MÑMÑÑ¡M]}!%°ÀÌØíդ̤(
ÍÀÌØí¥lÁtôÀÌØíU%}Y9Q}
1=M¹ÀÌØí¥lÅtôÀÌØíÕ¤Ì(U%MÑMÑÑ¡M]}!%°ÀÌØíդ̤(
ÍÀÌØí¥lÁtôÀÌØí1¥ÍÐ(}U%
Ñɱ1¥ÍÑY¥ÝM½ÉÐ ÀÌØí1¥ÍаÀÌØí }M
9%9°U%
ÑɱÑMÑÑ ÀÌØí1¥ÍФ¤(¹M±Ð)]¹(

The zero element of the array ($i[0]) contains the event/ctrlId

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