Post by Tasp on Dec 17, 2023 13:06:56 GMT -5
I'm stuck with a listbox and array.
The Reminder section is the focus of this question. But it was easier to post the whole code.
When you open the Reminder window it reads a list from Reminder.txt, each time you, edit, add, or delete it updates the array and then saves it when you close the Reminder window.
The program will, add, edit, delete fine, unless you try to delete 2 items from the Reminder listbox consecutively.
I've tried various way of geting this to work. But failing. You might see that the update array and save array to file are diiferent, this is just where I've been testing different approaches. I know the solution is simple, I just cannot find it and now I've got code blindness and cannot work out the simplest thing.
There are other issue with the code, they not important, I'll resolve them later.
The Reminder section is the focus of this question. But it was easier to post the whole code.
When you open the Reminder window it reads a list from Reminder.txt, each time you, edit, add, or delete it updates the array and then saves it when you close the Reminder window.
The program will, add, edit, delete fine, unless you try to delete 2 items from the Reminder listbox consecutively.
I've tried various way of geting this to work. But failing. You might see that the update array and save array to file are diiferent, this is just where I've been testing different approaches. I know the solution is simple, I just cannot find it and now I've got code blindness and cannot work out the simplest thing.
There are other issue with the code, they not important, I'll resolve them later.
'NOMAINWIN
' delete from middle of the list doesnt work, deletes everything after, not moving down - ?index
' uncomment TIMER call before EXEing
GOSUB [structdef]
GLOBAL LOGDATE$, UKDATE$, LogFolder$, SpaceLeft$, index
DIM info$(1, 1)
DIM Movies$(30000)
DIM Reminder$(1000)
MoviesFolder$ = "t:\"
SeriesFolder$ = "t:/"
LogFolder$ = DefaultDir$ + "\Log\log.txt"
ReminderFile$ = DefaultDir$ + "\Reminder.txt"
index = 0
log = 0
CONFIRM "Create test Reminder.txt file?";answer$
IF answer$ = "yes" THEN
OPEN ReminderFile$ FOR OUTPUT AS #file
FOR f = 1 TO 10
#file, f
NEXT
CLOSE #file
END IF
CALL UKDate
WindowWidth = 400 : WindowHeight = 260
UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)
STYLEBITS #m, _DS_CENTER,0,_WS_EX_TOPMOST,0 'centers dialog modal window and sets Z order to topmost
STATICTEXT #m.s3, "Ready.", 10, 70, 200, 30
STATICTEXT #m.s1, "", 210, 70, 300, 25
STATICTEXT #m.s2, "", 10, 100, 300, 25
STATICTEXT #m.s4, "HARD DRIVE SPACE AVAILABLE", 10, 210, 300, 25
TEXTBOX #m.t1, 10, 10, 370, 45
BUTTON #m.default, "Check", [checkforfile], UL, 250, 140, 125, 55
BUTTON #m.b2, "Reminder", [SeriesReminder], UL, 10, 140, 125, 55
BUTTON #m.b3, "Log", [DisplayLog], UL, 370, 210, 10, 10
OPEN "Movie Databaser v0.9" FOR DIALOG AS #m
#m, "trapclose [close]"
#m.t1, "!setfocus"
#m.t1, "!Font size 24"
#m.s1, "!Font size 18"
#m.s2, "!Font size 12"
#m.s3, "!Font size 18"
#m.s4, "!Font size 10"
#m.b2, "!Font size 14"
#m.default, "!font size 14"
IF log THEN CALL Log "Program Started"
'TIMER 3000, [CheckSpace]
WAIT
[CheckSpace]
CALL FreeSpace MoviesFolder$
#m.s4, "Free: "; SpaceLeft$
WAIT
[close]
IF ReminderWindowOpen = 1 THEN CLOSE #r
IF AddWinOpen = 1 THEN CLOSE #e
IF log THEN CALL Log "Program Ended" + CHR$(13)
CLOSE #m
STOP
[DisplayLog]
RUN "notepad.exe " + LogFolder$
WAIT
[checkforfile]
movies = 0 : series = 0
#m.t1, "!Contents? SearchFileName$";
SearchFileName$ = LOWER$(SearchFileName$)
IF SearchFileName$ = "" THEN WAIT
IF log THEN CALL Log "Searching for ";SearchFileName$
#m.default, "!DISABLE" : #m.t1, "!DISABLE"
#m.s3, "Prepping Files"
IF log THEN CALL Log "Prepping files."
FILES MoviesFolder$, info$()
#m.s3, "Searching..."
totfiles = val(info$(0,0))
totsubs = val(info$(0,1))
IF log THEN CALL Log "Searching Movies files."
FOR i=totfiles+1 to totfiles+totsubs
movies = movies + 1
Movies$(i) = info$(i,1)
#m.s1, i
TotalFiles = i
#m.s2, "Movie - "; info$(i,1)
IF instr(LOWER$(info$(i,1)), SearchFileName$) > 0 THEN
NOTICE "Match Found in MOVIES!" + CHR$(13) + "Item:" + STR$(i) + CHR$(13) + CHR$(13) + info$(i,1)
IF log THEN CALL Log "Match Found in MOVIES! Item: " + STR$(i) + " " + info$(i,1)
'EXIT FOR
END IF
NEXT
'Do it again for the series drive
#m.s3, "Prepping Files"
FILES SeriesFolder$, info$()
#m.s3, "Searching..."
totfiles = val(info$(0,0))
totsubs = val(info$(0,1))
IF log THEN CALL Log "Searching Series files."
FOR i=totfiles + 1 to totfiles+totsubs
series = series + 1
#m.s1, TotalFiles + i
#m.s2, "Series - "; info$(i,1)
IF instr(LOWER$(info$(i,1)), SearchFileName$) > 0 THEN
NOTICE "Match Found in SERIES!" + CHR$(13) + "Item:" + STR$(TotalFiles + i) + CHR$(13) + CHR$(13) + info$(i,1)
IF log THEN CALL Log "Match Found in SERIES! Item: " + STR$(TotalFiles + i) + " " + info$(i,1)
'EXIT FOR
END IF
NEXT
#m.s3, "Searched"
#m.s2, "Completed - Movies: " ; movies ; " - Series: "; series
IF log THEN CALL Log "Search Complete"
#m.default, "!ENABLE" : #m.t1, "!ENABLE"
WAIT
'============ REMINDER CODE ================
[SeriesReminder]
TIMER 0
REDIM Reminder$(1000)
IF log THEN CALL Log "Reminder facility Opening"
index = 0
IF ReminderWindowOpen = 1 THEN WAIT
OPEN ReminderFile$ FOR INPUT AS #file
WHILE not(eof(#file))
LINE INPUT #file, Reminder$(index)
CALL Log "Item ";index;": " + Reminder$(index)
index = index + 1
WEND
CLOSE #file
hWnd = hWnd(#m)
a = GetWindowPlacement(hWnd)
UpperLeftX = WINDOWPLACEMENT.rcNormalPositionLeft.struct + 400
UpperLeftY = WINDOWPLACEMENT.rcNormalPositionTop.struct
WindowHeight = 450 : WindowWidth = 600
STATICTEXT #r, "Series episode is the next one required", 450,100,100,48
STYLEBITS #r, 0,0,_WS_EX_TOPMOST,0 'centers dialog modal window and sets Z order to topmost
BUTTON #r.1, "Add", [AddItem], UL, 450, 10, 100, 50
LISTBOX #r.l, Reminder$(), [listboxeventhandler], 10, 10, 400, 400
OPEN "Download Reminders" FOR DIALOG AS #r
ReminderWindowOpen = 1
#r, "trapclose [Quit.Reminder]"
#r.l, "font Arial 14"
WAIT
[AddItem]
IF log THEN CALL Log "Adding Item to reminder list"
hWnd = hWnd(#r)
a = GetWindowPlacement(hWnd)
UpperLeftX = WINDOWPLACEMENT.rcNormalPositionLeft.struct + 600
UpperLeftY = WINDOWPLACEMENT.rcNormalPositionTop.struct
WindowHeight = 120 : WindowWidth = 300
BUTTON #e.b1, "Save", [SaveAddItem], UL, 10,50
TEXTBOX #e.t1, 10,10,270,25
OPEN "Add Item" FOR DIALOG AS #e
AddWinOpen = 1
#e, "Trapclose [CloseEditWin]"
#e.t1, "!Setfocus"
WAIT
[SaveAddItem]
index = index + 1
#e.t1, "!contents? AddItem$"
Reminder$(index) = AddItem$
CALL ReloadListBox
IF log THEN CALL Log "Saving item to reminder, ";AddItem$
AddWinOpen = 0
CLOSE #e
WAIT
[listboxeventhandler] 'Item was double clicked
IF AddWinOpen THEN WAIT
hWnd = hWnd(#r)
a = GetWindowPlacement(hWnd)
UpperLeftX = WINDOWPLACEMENT.rcNormalPositionLeft.struct + 600
UpperLeftY = WINDOWPLACEMENT.rcNormalPositionTop.struct
WindowHeight = 120 : WindowWidth = 300
BUTTON #e.b1, "Save", [SaveItem], UL, 10,50
BUTTON #e.b2, "Delete", [DeleteItem], UL, 100, 50
TEXTBOX #e.t1, 10,10,270,25
OPEN "Edit Item" FOR DIALOG AS #e
AddWinOpen = 1
#e, "Trapclose [CloseEditWin]"
#r.l, "selectionindex? editindex"
print "editindex-1 :"; editindex-1
IF editindex = 0 THEN WAIT
Item$ = Reminder$(editindex-1)
#e.t1, Item$
'Put caret at end of text
handle = hWnd(#e.t1)
CALLDLL #user32, "SendMessageA", handle as ulong, _EM_SETSEL as long, 100 as long, 100 as long, r as long
WAIT
[DeleteItem]
#r.l, "selectionindex? Deleteindex";
Reminder$(Deleteindex-1) = ""
IF log THEN CALL Log "Deleting item from Reminder list, item "; Deleteindex-1
index = index - 1
CALL ReloadListBox
AddWinOpen = 0
CLOSE #e
WAIT
[SaveItem]
#e.t1, "!Contents? SaveItem$";
IF SaveItem$ = "" THEN WAIT
Reminder$(index) = SaveItem$
IF log THEN CALL Log "Saving item in Reminder list ";SaveItem$
CALL ReloadListBox
[CloseEditWin]
AddWinOpen = 0
CLOSE #e
WAIT
[Quit.Reminder]
a = 0
CLOSE #r
ReminderWindowOpen = 0
IF log THEN CALL Log "Closing and saving Reminder file"
OPEN ReminderFile$ FOR OUTPUT AS #file
FOR i = 0 TO index
IF Reminder$(i) <> "" THEN
#file, Reminder$(i)
print Reminder$(i)
CALL Log "Item ";i;": " + Reminder$(i)
END IF
'a = a + 1
NEXT
CLOSE #file
'Turn back on timer that updates Hard Drive space
'TIMER 3000, [CheckSpace]
WAIT
SUB ReloadListBox
print "index: ";index
FOR i = 0 TO index
IF Reminder$(i) <> "" THEN
Reminder$(i) = Reminder$(i)
print "Pos:";i;" = "; Reminder$(i)
END IF
NEXT
#r.l, "reload"
END SUB
SUB UKDate
day$ = MID$(DATE$("mm/dd/yy"), 4, 2)
month$ = LEFT$(DATE$("mm/dd/yy"), 2)
year$ = RIGHT$(DATE$("mm/dd/yy"), 2)
UKDATE$ = day$ + "/" + month$ + "/" + year$
LOGDATE$ = day$ + "_" + month$ + "_" + year$
IF log THEN CALL Log "Creating date in UK format"
END SUB
SUB Log LogMessage$
OPEN LogFolder$ FOR APPEND AS #log
CurrentDate$ = UKDATE$ + " " + TIME$() + " " + LogMessage$ + "."
#log, CurrentDate$
CLOSE #log
END SUB
SUB FreeSpace DriveLetter$
STRUCT lpFree, BytesL As ulong, BytesH As ulong
STRUCT lpTotal, BytesL As ulong, BytesH As ulong
STRUCT lpTotFree, BytesL As ulong, BytesH As ulong
CALLDLL #kernel32, "GetDiskFreeSpaceExA", DriveLetter$ As ptr, lpFree As struct, lpTotal As struct, lpTotFree As struct, ret As long
SpaceLeft$ = InUnits$(lpTotFree.BytesH.struct * HexDec("100000000") + lpTotFree.BytesL.struct)
END SUB
FUNCTION InUnits$(Bytes)
InUnits$ = TRIM$(Using("#####.##", Bytes / (1024 * 1024 * 1024)); " GB")
END FUNCTION
FUNCTION GetWindowPlacement(hWnd)
CallDLL #user32, "GetWindowPlacement", hWnd as ulong, WINDOWPLACEMENT as struct, GetWindowPlacement as long
END FUNCTION
FUNCTION SetWindowPlacement(hWnd)
CallDLL #user32, "SetWindowPlacement", hWnd as ulong, WINDOWPLACEMENT as struct, SetWindowPlacement as long
END FUNCTION
FUNCTION SetWindowText(hWnd, text$)
CallDLL #user32, "SetWindowTextA", hWnd as ulong, text$ as ptr, SetWindowText as long
END FUNCTION
[structdef]
struct WINDOWPLACEMENT, length as ulong, flags as long, showCmd as long, ptMinPositionX as long, ptMinPositionY as long, ptMaxPositionX as long, ptMaxPositionY as long, rcNormalPositionLeft as long, rcNormalPositionTop as long, rcNormalPositionRight as long, rcNormalPositionBottom as long
WINDOWPLACEMENT.length.struct = len(WINDOWPLACEMENT.struct)
global MONITOR.DEFAULTTONEAREST, MONITOR.DEFAULTTONULL, MONITOR.DEFAULTTOPRIMARY
return
'include lb45func.bas