Hi,
entweder hab ich grad nen Brett vorm Kopf oder ich komm einfach nicht auf die Lösung.
Eigentlich möchte ich nur in einem Script die _FileWriteToLine funktion nutzen, aber es klappt einfach nicht.
Ich habe die Funktion bereits in anderen Scripts erfolgreich verwendet, aber bei diesem komme ich nicht weiter.
Was macht das Script: Es liest die Daten aus einer .php Datei in eine Liste, da kann man diese bearbeiten und die Funktion _writeData soll diese wieder in die Datei einfügen.
Ich habe mir mal eine MSG Box eingebaut, die mir @error, den Inhalt von $i und die Anzahl der Zeilen ausgibt.
@error ist 1, also: File has less lines than $iLine
$i ist 26 und die Zeilenzahl 54
Demnach verstehe ich das Problem jetzt nicht so ganz
Ich bin für jede Hilfe dankbar
#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include "Forms\gui.isf"
; -- Created with ISN Form Studio 2 for ISN AutoIt Studio -- ;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiButton.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <FTPEx.au3>
Global $aArray
Global $start
Global $ende
$gui = GUICreate("Update Events",722,523,-1,-1,-1,-1)
$btn_hoch = GUICtrlCreateButton("Hoch",588,401,100,30,-1,-1)
$btn_runter = GUICtrlCreateButton("Runter",588,450,100,30,-1,-1)
Global $liste = GUICtrlCreatelistview("Titel |Text ",40,190,534,309,-1,512)
$inp_titel = GUICtrlCreateInput("",80,57,290,21,-1,512)
GUICtrlCreateLabel("Titel:",50,60,26,15,-1,-1)
GUICtrlSetBkColor(-1,"-2")
GUICtrlCreateLabel("Text:",50,100,24,15,-1,-1)
GUICtrlSetBkColor(-1,"-2")
GUICtrlSetStyle($liste, $LVS_REPORT, $LVS_EX_FULLROWSELECT)
$inp_text = GUICtrlCreateInput("",80,97,289,20,-1,512)
$btn_add = GUICtrlCreateButton("Hinzufügen",420,75,100,30,-1,-1)
$btn_upload = GUICtrlCreateButton("Upload",590,140,100,30,-1,-1)
$btn_del = GUICtrlCreateButton("Löschen",589,320,100,30,-1,-1)
GUISetState(@SW_SHOW,$gui)
_importData ()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $btn_add
GUICtrlCreateListViewItem(GUICtrlRead($inp_titel) & "|" & GUICtrlRead($inp_text), $liste)
Case $btn_del
_GUICtrlListView_DeleteItemsSelected($liste)
Case $btn_runter
_GUICtrlListView_MoveItems($liste,1)
Case $btn_hoch
_GUICtrlListView_MoveItems($liste,-1)
Case $btn_upload
_writeData ()
EndSwitch
Sleep(10)
WEnd
Func _importData()
_FileReadToArray(@ScriptDir& "\events.php", $aArray)
If @error Then
MsgBox(0, "", "Fehler beim einlesen der Datei. Fehler: " & @error)
Exit
EndIf
; Start und Ende finden
$start = _ArraySearch($aArray, "<!--Start-->",0, 0, 0, 1)
If @error Then
MsgBox(0, "", "Fehler beim der Suche nach dem Startpunk. Fehler: " & @error)
Exit
EndIf
$ende = _ArraySearch($aArray, "<!--Ende-->",0, 0, 0, 1)
If @error Then
MsgBox(0, "", "Fehler beim der Suche nach dem Endpunk. Fehler: " & @error)
Exit
EndIf
For $i = $start To $ende
If stringinstr($aArray[$i], '<p class="pcont2">') Then
$tmp = StringTrimLeft ($aArray[$i], 18)
$tmp = StringTrimRight($tmp, 10)
$tmp2 = StringTrimRight($aArray[$i+1], 6)
GUICtrlCreateListViewItem($tmp & "|" & $tmp2, $liste)
Endif
Next
EndFunc
Func _writeData ()
Local $asplit
Local $file2 = "events.php"
$delanzahl = ($ende) - ($start+1)
For $i = 1 to $delanzahl
_FileWriteToLine($file2, $start+1, "", 1)
If @error Then
MsgBox(0, "", "Fehler beim löschen der Zeilen in der Datei. Fehler: " & @error)
Exit
EndIf
Next
Local $itemc = _GUICtrlListView_GetItemCount ($liste)
$start2 = $start+1
For $i = 1 To $itemc
$tmp = _GUICtrlListView_GetItemTextString ($liste, $i-1)
$asplit = StringSplit($tmp, "|")
_FileWriteToLine($file2, $start2, '<p class="pcont2">' & $asplit[1] & '</p><br />', 0)
If @error Then
MsgBox(0, "", "Fehler beim schreiben in die Datei. Fehler: " & @error)
Exit
EndIf
$start2 +=1
_FileWriteToLine($file2, $start2, $asplit[2] & '<br />', 0)
If @error Then
MsgBox(0, "", "Fehler beim schreiben in die Datei. Fehler: " & @error)
Exit
EndIf
$start2 +=1
_FileWriteToLine($file2, $start2, '<hr class="hr1" /> ', 0)
If @error Then
MsgBox(0, "", "Fehler beim schreiben in die Datei. Fehler: " & @error)
Exit
EndIf
$start2 +=1
Next
EndFunc
;===============================================================================
; Function Name: _GUICtrlListView_MoveItems()
; Description: Moves Up or Down selected item(s) in ListView.
;
; Parameter(s): $hListView - ControlID or Handle of ListView control.
; $iDirection - Define in what direction item(s) will move:
; -1 - Move Up.
; 1 - Move Down.
;
; Requirement(s): AutoIt 3.3.0.0
;
; Return Value(s): On seccess - Move selected item(s) Up/Down and return 1.
; On failure - Return "" (empty string) and set @error as following:
; 1 - No selected item(s).
; 2 - $iDirection is wrong value (not 1 and not -1).
; 3 - Item(s) can not be moved, reached last/first item.
;
; Note(s): * If you select like 15-20 (or more) items, moving them can take a while (second or two).
;
; Author(s): G.Sandler a.k.a CreatoR
;===============================================================================
Func _GUICtrlListView_MoveItems($hListView, $iDirection)
Local $aSelected_Indices = _GUICtrlListView_GetSelectedIndices($hListView, 1)
If UBound($aSelected_Indices) < 2 Then Return SetError(1, 0, "")
If $iDirection <> 1 And $iDirection <> -1 Then Return SetError(2, 0, "")
Local $iTotal_Items = _GUICtrlListView_GetItemCount($hListView)
Local $iTotal_Columns = _GUICtrlListView_GetColumnCount($hListView)
Local $iUbound = UBound($aSelected_Indices)-1, $iNum = 1, $iStep = 1
[/autoit][autoit][/autoit][autoit]Local $iCurrent_Index, $iUpDown_Index, $sCurrent_ItemText, $sUpDown_ItemText
Local $iCurrent_Index, $iCurrent_CheckedState, $iUpDown_CheckedState
Local $iImage_Current_Index, $iImage_UpDown_Index
If ($iDirection = -1 And $aSelected_Indices[1] = 0) Or _
($iDirection = 1 And $aSelected_Indices[$iUbound] = $iTotal_Items-1) Then Return SetError(3, 0, "")
ControlListView($hListView, "", "", "SelectClear")
[/autoit][autoit][/autoit][autoit]If $iDirection = 1 Then
$iNum = $iUbound
$iUbound = 1
$iStep = -1
EndIf
For $i = $iNum To $iUbound Step $iStep
$iCurrent_Index = $aSelected_Indices[$i]
$iUpDown_Index = $aSelected_Indices[$i]+1
If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i]-1
$iCurrent_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iCurrent_Index)
$iUpDown_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iUpDown_Index)
_GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index)
[/autoit][autoit][/autoit][autoit]For $j = 0 To $iTotal_Columns-1
$sCurrent_ItemText = _GUICtrlListView_GetItemText($hListView, $iCurrent_Index, $j)
$sUpDown_ItemText = _GUICtrlListView_GetItemText($hListView, $iUpDown_Index, $j)
If _GUICtrlListView_GetImageList($hListView, 1) <> 0 Then
$iImage_Current_Index = _GUICtrlListView_GetItemImage($hListView, $iCurrent_Index, $j)
$iImage_UpDown_Index = _GUICtrlListView_GetItemImage($hListView, $iUpDown_Index, $j)
_GUICtrlListView_SetItemImage($hListView, $iCurrent_Index, $iImage_UpDown_Index, $j)
_GUICtrlListView_SetItemImage($hListView, $iUpDown_Index, $iImage_Current_Index, $j)
EndIf
_GUICtrlListView_SetItemText($hListView, $iUpDown_Index, $sCurrent_ItemText, $j)
_GUICtrlListView_SetItemText($hListView, $iCurrent_Index, $sUpDown_ItemText, $j)
Next
_GUICtrlListView_SetItemChecked($hListView, $iUpDown_Index, $iCurrent_CheckedState)
_GUICtrlListView_SetItemChecked($hListView, $iCurrent_Index, $iUpDown_CheckedState)
_GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index, 0)
Next
For $i = 1 To UBound($aSelected_Indices)-1
$iUpDown_Index = $aSelected_Indices[$i]+1
If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i]-1
_GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index)
Next
Return 1
EndFunc
events.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="de" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Test</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="header">
<? include ("head.php"); ?>
</div>
<div id="navi">
<? include ("nav.php"); ?>
</div>
<div id="content" align="center">
<? include ("head.php"); ?>
<div id="content2" align="center">
<hr class="hr1" />
<!--Start-->
<p class="pcont2">Testevent1</p><br />
von November 2013 - Dezember 2013, 123 teststadt<br />
<hr class="hr1" />
<p class="pcont2">Testevent2</p><br />
von November 2013 - Dezember 2013, 124 teststadt<br />
<hr class="hr1" />
<p class="pcont2">Testevent3</p><br />
von November 2013 - Dezember 2013, 125 teststadt<br />
<hr class="hr1" />
<p class="pcont2">Testevent4</p><br />
von November 2013 - Dezember 2013, 126 teststadt<br />
<hr class="hr1" />
<p class="pcont2">Testevent5</p><br />
von November 2013 - Dezember 2013, 127 teststadt<br />
<hr class="hr1" />
<p class="pcont2">Testevent6</p><br />
von November 2013 - Dezember 2013, 128 teststadt<br />
<hr class="hr1" />
<!--Ende-->
<br />
</div>
</div>
</div>
</body>
</html>
Alles anzeigen