Jump to content

TelephoneList


Recommended Posts

Hi,

I've written al litte Telephone tool with a simple Listview function.

There is a litle bug within, but I don't find it.

I hope, someone find it out.

I've translated the basic funktions so that it easier for you to check my sourcecode.

My Problem:

after "accept" & "refresh" there is a problem with the first entry of the listview.

If you "doubleclick" The first entry of the listview, the last edited listviewitem was doubled in the listview, but I don't know the reason for this.

PLEASE HELP ME !

#include <file.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#include <GuiListview.au3>

Opt("TrayIconDebug", 1); zeigt am trayicon welchen Befehl  das Script gerade Ausführt

dim $aRecords, $x, $listview, $name, $vorname, $tel, $mobil, $handy, $einfuegen, $Button1, $Button2, $accept, $nr, $x_n
Global Const $THRESHOLD = Number(RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "DoubleClickSpeed"))
Global $TIMER = TimerInit()

$file = "C:\publictelefon.csv"


GUICreate("Telefonlisten",540,315, 100,200,$WS_OVERLAPPEDWINDOW)
$listview   = GUICtrlCreateListView ("LastName            |FirstVorname           |Telefon|Schnurlos|Handy  ",10,10,520,230)
$edit = GUICtrlCreateButton("edit Data",10,250,80,20)
$save   = GUICtrlCreateButton("save Data",100,250,80,20)
$new    = GUICtrlCreateButton("new Data",190,250,100,20)
$delete     = GUICtrlCreateButton("delete Data",300,250,100,20)
$array      = GUICtrlCreateButton("show Array ",410,250,100,20)

;---Editfeld
$name       = GUICtrlCreateInput("LastName",10, 280,80,20,-1 ,$WS_EX_CLIENTEDGE )
$vorname    = GUICtrlCreateInput("FirstName",100, 280,80,20,-1 ,$WS_EX_CLIENTEDGE )
$tel        = GUICtrlCreateInput("Telefon",190, 280,80,20,-1 ,$WS_EX_CLIENTEDGE )
$mobil      = GUICtrlCreateInput("Schnurlos",280, 280,80,20,-1 ,$WS_EX_CLIENTEDGE )
$handy      = GUICtrlCreateInput("Handy",370, 280,80,20,-1 ,$WS_EX_CLIENTEDGE )
$Button1    = GUICtrlCreateButton("",1460,280,70,20); Buttons should be invisible first
$Button2    = GUICtrlCreateButton("",1460,280,70,20); Buttons should be invisible first
GUISetState()


;--- PROGRAMM steps

If Not _FileReadToArray($file, $aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf



;~ _ArrayDisplay($aRecords,"")
For $x = 1 to $aRecords[0]
    if $aRecords[$x] = "" Then 
        _ArrayDelete($aRecords,$x)
        $help = $aRecords[0]
        $aRecords[0]= $help-1
    Else    
        GUICtrlCreateListViewItem($aRecords[$x],$listview)
    EndIf
Next

; Ich zerstöre diese direkt wieder , weil sonnst immer direkt die Funktion für Button1 ausgeführt wird
; Vielleicht weiß jemand warum ?
GUICtrlDelete($Button1)
GUICtrlDelete($Button2)

While 1
$msg = GuiGetMsg()

Select
Case $msg = $GUI_EVENT_CLOSE
    ExitLoop

Case $msg = $GUI_EVENT_PRIMARYDOWN
      _getLVItem_dbclick($listview)
    
case $msg = $edit
edit()  
    
case $msg = $save
save()

Case $msg = $new
new()

Case $msg = $Button1
accept()

Case $msg = $Button2
hinzufuegen()

Case $msg = $delete
delete()    

case $msg = $array
    _ArrayDisplay($aRecords, "Array Anzeigen")

Case Else
;~  ;;;
EndSelect

WEnd

;--- PROGRAMM Steps end





;--- FUNKTIONEN


func edit()
$Button1 = GUICtrlCreateButton("übernehmen",460,280,70,20)
$nr = ControlListView("","",$listview,"GetSelected")
$nr = $nr+1
;~ MsgBox(0,"",$aRecords[$nr])
$Datensatz = StringSplit($aRecords[$nr],"|")
;~ MsgBox(0,"Datensatz hat n Elemente, n= ",$Datensatz[0])
If $Datensatz[0] > 0 Then GUICtrlSetData($name,$Datensatz[1])
If $Datensatz[0] > 1 Then GUICtrlSetData($vorname,$Datensatz[2])
If $Datensatz[0] > 2 Then GUICtrlSetData($tel,$Datensatz[3])
If $Datensatz[0] > 3 Then GUICtrlSetData($mobil,$Datensatz[4])
If $Datensatz[0] > 4 Then GUICtrlSetData($handy,$Datensatz[5])
;~ _ArrayDisplay($Datensatz,"")
EndFunc


Func save()
FileOpen($file,2 )
For $x = 1 to $aRecords[0]
FileWriteLine($file,$aRecords[$x])
FileClose($file)
Next    
EndFunc


func new()
    MsgBox(4096,"Datensatz new","Bitte die entsprechenden Felder füllen" & @CR & @CR & 'Dann "hinzufügen" auswählen')
$Button2 = GUICtrlCreateButton("hinzufügen",460,280,70,20) 


EndFunc 

Func hinzufuegen()
$name_read      = GUICtrlRead($name)
$vorname_read   = GUICtrlRead($vorname)
$tel_read       = GUICtrlRead($tel)
$mobil_read     = GUICtrlRead($mobil)
$handy_read     = GUICtrlRead($handy)
$new = $aRecords[0]+1
_ArrayInsert($aRecords,$new,$name_read & "|" & $vorname_read & "|" & $tel_read   & "|" & $mobil_read  & "|" & $handy_read)
$aRecords[0] = $new 
refresh()   
EndFunc 



Func accept()
$name_read      = GUICtrlRead($name)
$vorname_read   = GUICtrlRead($vorname)
$tel_read       = GUICtrlRead($tel)
$mobil_read     = GUICtrlRead($mobil)
$handy_read     = GUICtrlRead($handy)

;~ MsgBox(0,"",$name_read & "|" & $vorname_read & "|" & $tel_read    & "|" & $mobil_read  & "|" & $handy_read)
_ArrayDelete($aRecords,$nr)
_ArrayInsert($aRecords,$nr,$name_read & "|" & $vorname_read & "|" & $tel_read    & "|" & $mobil_read  & "|" & $handy_read)
;~ _ArrayDisplay($aRecords,"")
refresh()
EndFunc



Func delete()
$nr = ControlListView("","",$listview,"GetSelected")
$nr = $nr+1 
$new = $aRecords[0]-1

_ArrayDelete($aRecords,$nr) 
;~ _ArrayDisplay($aRecords,"")
$aRecords[0] = ""
;~ _ArraySort($aRecords)
$aRecords[0] = $new
;~ _ArrayDisplay($aRecords,"")
refresh()
EndFunc 


func refresh()
$new = $aRecords[0]
$aRecords[0] = ""
_ArraySort($aRecords)
$aRecords[0] = $new

GUICtrlDelete($listview)
GUICtrlDelete($Button1)
GUICtrlDelete($Button2)
$listview = GUICtrlCreateListView ("Name              |Vorname            |Telefon|Schnurlos|Handy  ",10,10,500,230);,$LVS_SORTDESCENDING)
For $x = 1 to $aRecords[0]
GUICtrlCreateListViewItem($aRecords[$x],$listview)
Next
EndFunc




Func _getLVItem_dbclick(ByRef $lvctrl)
Dim $MousePos = GUIGetCursorInfo()
If ($MousePos[4] == $lvctrl And GUICtrlRead($lvctrl) > 0 And _GUICtrlListViewGetHotItem ($lvctrl) = _GUICtrlListViewGetCurSel ($lvctrl)) Then
    $timerdiff = TimerDiff($TIMER)  
    If $timerdiff <= $THRESHOLD Then
        $TIMER = TimerInit()
        edit()
    EndIf
 $TIMER = TimerInit()
EndIf

EndFunc
Link to comment
Share on other sites

Hide/Show the controls, not create/delete, the problem stems from deleting button_1 and button_2

#include <file.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#include <GuiListview.au3>

Opt("TrayIconDebug", 1); zeigt am trayicon welchen Befehl  das Script gerade Ausführt

Dim $aRecords, $x, $listview, $name, $vorname, $tel, $mobil, $handy, $einfuegen, $Button1, $Button2, $accept, $nr, $x_n
Global Const $THRESHOLD = Number(RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "DoubleClickSpeed"))
Global $TIMER = TimerInit()

$file = @ScriptDir & "\publictelefon.csv"


GUICreate("Telefonlisten", 540, 315, 100, 200, $WS_OVERLAPPEDWINDOW)
$listview = GUICtrlCreateListView("Last Name              |First Name             |Telefon|Schnurlos|Handy  ", 10, 10, 520, 230)
$edit = GUICtrlCreateButton("edit Data", 10, 250, 80, 20)
$save = GUICtrlCreateButton("save Data", 100, 250, 80, 20)
$new = GUICtrlCreateButton("new Data", 190, 250, 100, 20)
$delete = GUICtrlCreateButton("delete Data", 300, 250, 100, 20)
$array = GUICtrlCreateButton("show Array ", 410, 250, 100, 20)

;---Editfeld
$name = GUICtrlCreateInput("LastName", 10, 280, 80, 20, -1, $WS_EX_CLIENTEDGE)
$vorname = GUICtrlCreateInput("FirstName", 100, 280, 80, 20, -1, $WS_EX_CLIENTEDGE)
$tel = GUICtrlCreateInput("Telefon", 190, 280, 80, 20, -1, $WS_EX_CLIENTEDGE)
$mobil = GUICtrlCreateInput("Schnurlos", 280, 280, 80, 20, -1, $WS_EX_CLIENTEDGE)
$handy = GUICtrlCreateInput("Handy", 370, 280, 80, 20, -1, $WS_EX_CLIENTEDGE)
$Button1 = GUICtrlCreateButton("übernehmen", 460, 280, 70, 20); Buttons should be invisible first
GUICtrlSetState($Button1, $GUI_HIDE)
$Button2 = GUICtrlCreateButton("hinzufügen", 460, 280, 70, 20); Buttons should be invisible first
GUICtrlSetState($Button2, $GUI_HIDE)
GUISetState()


;--- PROGRAMM steps

If Not _FileReadToArray($file, $aRecords) Then
   MsgBox(4096, "Error", " Error reading log to Array    error:" & @error)
   Exit
EndIf

 

;~ _ArrayDisplay($aRecords,"")
For $x = 1 To $aRecords[0]
   If $aRecords[$x] = "" Then
      _ArrayDelete($aRecords, $x)
      $help = $aRecords[0]
      $aRecords[0] = $help - 1
   Else
      GUICtrlCreateListViewItem($aRecords[$x], $listview)
   EndIf
Next

; Ich zerstöre diese direkt wieder , weil sonnst immer direkt die Funktion für Button1 ausgeführt wird
; Vielleicht weiß jemand warum ?

While 1
   $msg = GUIGetMsg()
   
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
         
      Case $msg = $GUI_EVENT_PRIMARYDOWN
         _getLVItem_dbclick($listview)
         
      Case $msg = $edit
         edit()
         
      Case $msg = $save
         save()
         
      Case $msg = $new
         new()
         
      Case $msg = $Button1
         accept()
         
      Case $msg = $Button2
         hinzufuegen()
         
      Case $msg = $delete
         delete()
         
      Case $msg = $array
         _ArrayDisplay($aRecords, "Array Anzeigen")
         
      Case Else
;~  ;;;
   EndSelect
   
WEnd
;--- PROGRAMM Steps end

;--- FUNKTIONEN
Func edit()
 GUICtrlSetState($Button1, $GUI_SHOW)
   $nr = ControlListView("", "", $listview, "GetSelected")
   $nr = $nr + 1
;~ MsgBox(0,"",$aRecords[$nr])
   $Datensatz = StringSplit($aRecords[$nr], "|")
;~ MsgBox(0,"Datensatz hat n Elemente, n= ",$Datensatz[0])
   If $Datensatz[0] > 0 Then GUICtrlSetData($name, $Datensatz[1])
   If $Datensatz[0] > 1 Then GUICtrlSetData($vorname, $Datensatz[2])
   If $Datensatz[0] > 2 Then GUICtrlSetData($tel, $Datensatz[3])
   If $Datensatz[0] > 3 Then GUICtrlSetData($mobil, $Datensatz[4])
   If $Datensatz[0] > 4 Then GUICtrlSetData($handy, $Datensatz[5])
;~ _ArrayDisplay($Datensatz,"")
EndFunc  ;==>edit

Func save()
   FileOpen($file, 2)
   For $x = 1 To $aRecords[0]
      FileWriteLine($file, $aRecords[$x])
      FileClose($file)
   Next
EndFunc  ;==>save

Func new()
   MsgBox(4096, "Datensatz new", "Bitte die entsprechenden Felder füllen" & @CR & @CR & 'Dann "hinzufügen" auswählen')
 GUICtrlSetState($Button2, $GUI_SHOW)
EndFunc  ;==>new

Func hinzufuegen()
   $name_read = GUICtrlRead($name)
   $vorname_read = GUICtrlRead($vorname)
   $tel_read = GUICtrlRead($tel)
   $mobil_read = GUICtrlRead($mobil)
   $handy_read = GUICtrlRead($handy)
   $new = $aRecords[0] + 1
   _ArrayInsert($aRecords, $new, $name_read & "|" & $vorname_read & "|" & $tel_read & "|" & $mobil_read & "|" & $handy_read)
   $aRecords[0] = $new
   refresh()
EndFunc  ;==>hinzufuegen

Func accept()
   $name_read = GUICtrlRead($name)
   $vorname_read = GUICtrlRead($vorname)
   $tel_read = GUICtrlRead($tel)
   $mobil_read = GUICtrlRead($mobil)
   $handy_read = GUICtrlRead($handy)
   
;~ MsgBox(0,"",$name_read & "|" & $vorname_read & "|" & $tel_read     & "|" & $mobil_read  & "|" & $handy_read)
   _ArrayDelete($aRecords, $nr)
   _ArrayInsert($aRecords, $nr, $name_read & "|" & $vorname_read & "|" & $tel_read & "|" & $mobil_read & "|" & $handy_read)
;~ _ArrayDisplay($aRecords,"")
   refresh()
EndFunc  ;==>accept

Func delete()
   $nr = ControlListView("", "", $listview, "GetSelected")
   $nr = $nr + 1
   $new = $aRecords[0] - 1
   
   _ArrayDelete($aRecords, $nr)
;~ _ArrayDisplay($aRecords,"")
   $aRecords[0] = ""
;~ _ArraySort($aRecords)
   $aRecords[0] = $new
;~ _ArrayDisplay($aRecords,"")
   refresh()
EndFunc  ;==>delete

Func refresh()
   $new = $aRecords[0]
   $aRecords[0] = ""
   _ArraySort($aRecords)
   $aRecords[0] = $new
   
   GUICtrlDelete($listview)
 GUICtrlSetState($Button1, $GUI_HIDE)
 GUICtrlSetState($Button2, $GUI_HIDE)
   $listview = GUICtrlCreateListView("Last Name           |First Name             |Telefon|Schnurlos|Handy  ", 10, 10, 500, 230);,$LVS_SORTDESCENDING)
   For $x = 1 To $aRecords[0]
      GUICtrlCreateListViewItem($aRecords[$x], $listview)
   Next
EndFunc  ;==>refresh

Func _getLVItem_dbclick(ByRef $lvctrl)
   Dim $MousePos = GUIGetCursorInfo()
   If ($MousePos[4] == $lvctrl And GUICtrlRead($lvctrl) > 0 And _GUICtrlListViewGetHotItem ($lvctrl) = _GUICtrlListViewGetCurSel ($lvctrl)) Then
      $timerdiff = TimerDiff($TIMER)
      If $timerdiff <= $THRESHOLD Then
         $TIMER = TimerInit()
         edit()
      EndIf
      $TIMER = TimerInit()
   EndIf
   
EndFunc  ;==>_getLVItem_dbclick

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Hide/Show the controls, not create/delete, the problem stems from deleting button_1 and button_2

#include <file.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#include <GuiListview.au3>

Opt("TrayIconDebug", 1); zeigt am trayicon welchen Befehl  das Script gerade Ausführt

Dim $aRecords, $x, $listview, $name, $vorname, $tel, $mobil, $handy, $einfuegen, $Button1, $Button2, $accept, $nr, $x_n
Global Const $THRESHOLD = Number(RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "DoubleClickSpeed"))
Global $TIMER = TimerInit()

$file = @ScriptDir & "\publictelefon.csv"
GUICreate("Telefonlisten", 540, 315, 100, 200, $WS_OVERLAPPEDWINDOW)
$listview = GUICtrlCreateListView("Last Name              |First Name             |Telefon|Schnurlos|Handy  ", 10, 10, 520, 230)
$edit = GUICtrlCreateButton("edit Data", 10, 250, 80, 20)
$save = GUICtrlCreateButton("save Data", 100, 250, 80, 20)
$new = GUICtrlCreateButton("new Data", 190, 250, 100, 20)
$delete = GUICtrlCreateButton("delete Data", 300, 250, 100, 20)
$array = GUICtrlCreateButton("show Array ", 410, 250, 100, 20)
.....
Hi ,

is it possible to sort my Listview by clicking on "First Name" ?

I don´t know witch $msg appears when I clicked on the ITEM "Firstname"

greetings

wolke

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...