Page 1 of 1

CSV delimited database help

Posted: 11 Aug 2018, 07:14
by Mike199028
Hello,

I'm currently making a basic clipboard manager, I've got the basics working, copy, display, save and delete. However, has the text file is CSV delimited:

SHORT TITLE, DATE AND TIME, FULL CLIPBOARD TEXT

I'm struggling to be able to allow commas and line breaks in my clipboard content, otherwise the loop sees it has more delimited text. So say i copy "hi, im mike" the listview only shows "hi"

I've tried using an if on the a_index to break the loop after 3 so it doesnt look for anymore delimiters.

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

^m::
Gui -MinimizeBox -MaximizeBox
Gui Add, ListView, x8 y8 w297 h170 gClipboardData, Clipboard|Date Added|D
Gui Add, Button, x232 y384 w50 h25 gDeleteEntry, Delete
Gui Add, Button, x32 y384 w50 h25 gCopyContent, Copy
Gui Add, Edit, x8 y207 w297 h170 vContent
Gui Add, Text, x8 y180 w95 h23 +0x200, Clipboard Content:

Gui Show, w481 h460 AutoSize, Clipboard Manager

LV_ModifyCol("3","0")
Loop, Read, clipboard.txt
{
    Loop, parse, A_LoopReadLine, CSV
    {
        Row%A_Index% := A_LoopField
        if A_Index >= 3
        {
            break
        }
    }
    LV_Add("",Row1,Row2,Row3)
    LV_ModifyCol("1","AutoHdr")
}
return

ClipboardData:
    if A_GuiEvent = DoubleClick
    {
        LV_GetText(clipdata, A_EventInfo, 3)
        GuiControl, Text, Content, %clipdata%
        return
    }
    
CopyContent:
    Gui, Submit, NoHide
    clipboard := Content
    MsgBox Content saved to Clipboard!
    return
    
DeleteEntry:
    Loop
    {
        row := LV_GetNext(row -1)
        if not row
            return
        LV_Delete(row)
        GuiControl, Text, Content, 
    }
    return
    
^b::
Send, ^c
copied := Clipboard
;~ replace := StrReplace(copied, ",", " ", All)
FormatTime, DateAdded, A_Now, dd/MM/yyyy
FileAppend, Entry..`,%DateAdded%`,%copied%, clipboard.txt
return
    
GuiClose:
FileDelete, clipboard.txt
Loop % LV_GetCount()
{
    RowNum := A_Index
    Loop, 3
    {
        LV_GetText(save, RowNum, A_Index)
        FileAppend, %save%`,, clipboard.txt
    }
    LV_GetText(save, RowNum, 4)
    FileAppend, %save%`n, clipboard.txt
}
Gui, Destroy

Re: CSV delimited database help

Posted: 11 Aug 2018, 08:08
by garry
just short answer , try to use another delimiter ( then comma )

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
f1=%a_scriptdir%\clipboard.txt
ifnotexist,%f1%
{
e4x=
(Ltrim join`r`n
"hi, im mike"$bbb$cccc1
2aaaa$bbbb$ccc2
3aaaaaa$bbbb$ccc3
)
fileappend,%e4x%,%f1%
}
Gui -MinimizeBox -MaximizeBox
Gui Add, ListView, x8 y8 w297 h170 gClipboardData, Clipboard|Date Added|D
;Gui Add, Button, x232 y384 w50 h25 gDeleteEntry, Delete
;Gui Add, Button, x32 y384 w50 h25 gCopyContent, Copy
Gui Add, Edit, x8 y207 w297 h170 vContent
Gui Add, Text, x8 y180 w95 h23 +0x200, Clipboard Content:
Gui Show, w481 h460 AutoSize, Clipboard Manager
LV_ModifyCol("3","0")

fileread,aac,%f1%
Loop,parse,aac,`n,`r
{
x:=a_loopfield
if x=
  continue
  B1=
  B2=
  B3=
  stringsplit,b,x,$,
  LV_Add("",b1,b2,b3)
}
aac=
return
Guiclose:
exitapp

ClipboardData:
    if A_GuiEvent = DoubleClick
    {
        LV_GetText(clipdata, A_EventInfo, 3)
        GuiControl, Text, Content, %clipdata%
        return
    }
return

Re: CSV delimited database help

Posted: 11 Aug 2018, 10:44
by Mike199028
That’s worked, could do with finding a “rare” delimiter that won’t be used by many people.

I’m fairly new to AHK. I learn best by putting myself into projects and learning that way.

Also, how would I allow line breaks in it?

Re: CSV delimited database help

Posted: 11 Aug 2018, 10:51
by jethrow
How are the fields with commas/line breaks identified? Typically they are enclosed in double quotes. In the past I've parsed on un-escaped double quotes first to identify the fields, then substituted the commas/line breaks in the fields.

Re: CSV delimited database help

Posted: 11 Aug 2018, 11:22
by Mike199028
Row1 and 2 are exempt from this but row3(the copied content) are in a parsed loop like this:

Row%A_Index% := A_LoopField

Then they are added into the ListView with col 3 containing row3(copied data)

Re: CSV delimited database help

Posted: 12 Aug 2018, 16:16
by Mike199028
Anyone? I’ve been trying to fix this and everytime there’s a line break it breaks the ListView and the txt file

Re: CSV delimited database help

Posted: 17 Aug 2018, 11:38
by Mike199028
I’ve managed the line breaks now, figured if I replace the line breaks in the csv with $(until I find a proper rare character) then when displaying it I’ll replace the $ with line breaks

Re: CSV delimited database help

Posted: 17 Aug 2018, 14:57
by garry
hello Mike199028, you have the solution ?
just some old basic listview examples :
https://autohotkey.com/board/topic/4279 ... rlprogram/

Re: CSV delimited database help

Posted: 18 Aug 2018, 11:54
by burque505
@Mike199028, I use this character quite a bit: ʬ (decimal 684, hex 0x02AC), primarily because I've NEVER seen it ANYWHERE ELSE that I can recall.

Code: Select all

;:*:wwww::ʬ
Also, if you can download the Symbola font, you can use this code below to pick a character you like as a quick-and-dirty tool:

Code: Select all

Gui, -DpiScale
Gui, Font, Bold Symbola
Gui, Add, Text, ,Pick a Unicode Character
Gui Add, Edit, x5 y+25 w100 r1
gui Add, Text, x+5 vInteger, Enter Unicode (decimal or hex)
Gui Add, Edit, x5 y+25 w100 r1 +ReadOnly
Gui Add, Text, x+5, Copy Unicode from here
gui Add, Button, x5 y+25 gSubmit Default, Submit
Gui, Show

return

GuiClose:
Escape::
ExitApp

Submit:
ControlGetText, out, Edit1
ControlSetText, Edit2, % Chr(out)
return
regards,
burque505