Ich habe den Code mal ein bisschen aufgeräumt und die unnötigen Schleifen entfernt. Bitte schau dir das mal an und beschreibe uns nochmals, wo genau der hase im pfeffer liegt. Wir besitzen leider die excel datei nicht, und können daher nur syntaktisch suchen, nicht aber logisch.
Lieben Dank.
Hier der Code:
Spoiler anzeigen
AutoIt
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.14.2
Author: Björn Alles
Script Function:
Template AutoIt script.
#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <Excel.au3>
#Region Neuer Fall
$GUI_Neuer_Fall = GUICreate("F4 - Erfassung eines neuen Falls", 710, 624, 192, 124)
$Miete_text = GUICtrlCreateLabel("Miete:", 16, 16, 33, 25)
$Miete_input = GUICtrlCreateInput("", 56, 16, 49, 21)
$NKO = GUICtrlCreateLabel("NKO:", 136, 16, 30, 17)
$nko_input = GUICtrlCreateInput("", 168, 16, 65, 21)
$Whg_Nr_txt = GUICtrlCreateLabel("Whg#Teil#:", 272, 16, 61, 17)
$Whg_Nr = GUICtrlCreateInput("", 336, 16, 113, 21)
$Priv_Nr_Txt = GUICtrlCreateLabel("Priv#:", 472, 16, 32, 17)
$Priv_Nr_Input = GUICtrlCreateInput("", 504, 16, 33, 21)
$Datum_txt = GUICtrlCreateLabel("Datum:", 552, 16, 38, 17)
$Datum_Input = GUICtrlCreateInput("", 592, 16, 65, 21)
$Status_Txt = GUICtrlCreateLabel("Status:", 8, 48, 37, 17)
$tButton = GUICtrlCreateButton("Test",200,200)
$tButton2 = GUICtrlCreateButton("Excel",300,300)
GUISetBkColor(0xA6CAF0)
GUISetState(@SW_DISABLE, $GUI_Neuer_Fall)
#EndRegion Neuer Fall
#Region Grundfenster
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Grundfenster = GUICreate("F4 - Startfenster", 615, 437, 192, 124)
$neuer_fall = GUICtrlCreateButton("Neuer Fall", 24, 24, 145, 41)
$fall_suchen = GUICtrlCreateButton("Fall Suchen", 24, 72, 145, 41)
GUISetBkColor(0xA6CAF0)
GUISetState(@SW_SHOW,$Grundfenster)
#EndRegion Grundfenster
#Region Variablen
$filepath = 'U:\test2.xlsx' ; Pfad der Exceldatei
;-------------------------------------ARRAYS ERZEUGEN----------------------------------------;
Dim $array_Miete[1] ;dynamisches Array wird erzeugt ------ MIETE
Dim $array_NKO[1] ;dynamisches Array wird erzeugt ------ NKO
Dim $array_Priv[1];dynamisches Array wird erzeugt ------ PRIV
Dim $array_Date[1];dynamisches Array wird erzeugt ------ DATE
Dim $array_Status[1];dynamisches Array wird erzeugt ------ STATUS
Dim $array_Asyla[1];dynamisches Array wird erzeugt ------ ASYLA
Dim $array_Folge[1];dynamisches Array wird erzeugt ------ FOLGE
Dim $array_Tel[1];dynamisches Array wird erzeugt ------ TEL
Dim $array_PKSneu[1];dynamisches Array wird erzeugt ------ PKSneu
Dim $array_Schuld[1];dynamisches Array wird erzeugt ------ SCHULD
Dim $array_Geb[1];dynamisches Array wird erzeugt ------ GEB
Dim $array_PKSalt[1];dynamisches Array wird erzeugt ------ nationalitaet
Dim $array_Personen_Ges[1];dynamisches Array wird erzeugt ------ PERSONEN_GES
Dim $array_Attest[1];dynamisches Array wird erzeugt ------ ATTEST
Dim $array_Buchungsstelle[1];dynamisches Array wird erzeugt ------ Buchungsstelle
Dim $array_Abg_Bz[1];dynamisches Array wird erzeugt ------ ABG_BZ
Dim $array_Heim[1];dynamisches Array wird erzeugt ------ HEIM
Dim $array_Buchungsstelle_Neu[1];dynamisches Array wird erzeugt ------ BUCHUNGSSTELLE_NEU
Dim $array_Ordnungsverf[1];dynamisches Array wird erzeugt ------ ORDNUNGSVERFUEGUNG
Dim $array_Selbstzahl[1];dynamisches Array wird erzeugt ------ SELBSTZAHL
Dim $array_Wohnhaft_Ab[1];dynamisches Array wird erzeugt ------ WOHNHAFT_AB
Dim $array_Auszug_Zum[1];dynamisches Array wird erzeugt ------ AUSZUG_ZUM
Dim $array_Verz_Von[1];dynamisches Array wird erzeugt ------ VERZ_VON
Dim $array_Monatssoll[1];dynamisches Array wird erzeugt ------ MONATSSOLL
Dim $array_Datum_Frage[1];dynamisches Array wird erzeugt ------ DATUM_FRAGE
Dim $array_Ort1[1];dynamisches Array wird erzeugt ------ ORT_1
#EndRegion Variablen
#Region Excel
Local $oExcel = _Excel_Open('false') ; öffnet Excel ohne das der User es sieht
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended); Error handling
Local $oWorkbook = _Excel_BookOpen($oExcel,$filepath); öffnet die Excel ohne das der User es sieht
If @error Then
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended); Error handling
_Excel_Close($oExcel); Schließt die Exceldatei
Exit
EndIf
$array_Miete = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A"), 2) ; liest die Daten der Spalte A in das Array ein
$array_NKO = _Excel_RangeRead($oWorkbook,Default,$oWorkbook.ActiveSheet.Usedrange.Columns("B:B"),2)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 3", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended);Error Handling
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 3", "Data successfully read." & @CRLF & "Please click 'OK' to display all formulas in column A.");Error Handling
_Excel_Close($oExcel)
_ArrayDisplay($array_Miete, "Excel UDF: _Excel_RangeRead Example 3 - Formulas in column A");Gibt das Array mit den eingelesenen Daten aus
#EndRegion Excel
While 1
$nMsg = GUIGetMsg(1)
Switch $nMsg[0]
Case $GUI_EVENT_CLOSE
Switch $nMsg[1]
Case $Grundfenster
Exit
Case Else
GUISetState(@SW_SHOW, $Grundfenster)
GUISetState(@SW_HIDE, $nMsg[1])
GUISetState(@SW_DISABLE, $nMsg[1])
GUISwitch($Grundfenster)
EndSwitch
Case $neuer_fall ;
If @error Then
MsgBox(1,"ERROR","ERROR")
Else
_GUI_Neuer_Fall()
EndIf
Case $tButton
_Array_Fuellen()
Case $tButton2
_Array_Speichern()
EndSwitch
WEnd
;---------------------------------------FUNKTION NEUER FALL---------------------------;
Func _GUI_Neuer_Fall()
GUISetState(@SW_ENABLE, $GUI_Neuer_Fall)
GUISwitch($GUI_Neuer_Fall)
GUISetState(@SW_SHOW)
EndFunc
;-------------------------------------ARRAY FUELLEN------------------------------------;
Func _Array_Fuellen()
;Miete
$mieteData = GUICtrlRead($Miete_input) ; Legt das Feld fest, das in das Array eingelesen werden soll
If $mieteData <> '' Then ;falls das Feld Leer ist wird der Ubound nicht erhöht
if $array_Miete[UBound($array_Miete)-1] Then ;Erweiterung des dynamischen Arrays
ReDim $array_Miete[UBound($array_Miete)+1] ; erzeugt eine neue Spalte im dynamischen Array
EndIf
$array_Miete[UBound($array_Miete)-1] = $mieteData ;Schreibt in die neue Spalte
EndIf
;NKO
$nkoData = GUICtrlRead($nko_input) ; Legt das Feld fest, das in das Array eingelesen werden soll
If $nkoData <> '' Then ;falls das Feld Leer ist wird der Ubound nicht erhöht
if $array_NKO[UBound($array_NKO)-1] Then ;Erweiterung des dynamischen Arrays
ReDim $array_NKO[UBound($array_NKO)+1] ; erzeugt eine neue Spalte im dynamischen Array
EndIf
$array_NKO[UBound($array_NKO)-1] = $nkoData ;Schreibt in die neue Spalte
EndIf
_ArrayDisplay($array_NKO);Zeigt das gefüllte Array mit den vorher kopierten Daten an
EndFunc
Func _Array_Speichern()
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $array_Miete); Schreibt das Array in die Exceldatei
_Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, $array_NKO, 'B1')
If @error Then Exit
;~ MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 2", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended); Error handling
;~ MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 2", "1D array successfully written.")
_Excel_BookSave($oWorkbook) ;Workbook wird gespeichert
_Excel_BookClose($oWorkbook)
EndFunc
Alles anzeigen