Jump to content

Quotable Quotes


sleepydvdr
 Share

Recommended Posts

I don't know why this project gave me so many problems in the past. I started it about 2 years ago and have looked at it several times since then. I took another look at it last Friday and was able to sort it out very easily and finish it. It's so simple, I feel ashamed that I struggled with it.

Anyways, I condensed to code to be pretty efficient. I think my best accomplishment with it was something new that I wrote. It is an error checking script for the quotations. I found lots of errors with it and was able to fix them. I first had it check for badly formatted lines. Then it checks for stings that are too long to fit into the constraints of the GUI. Then it checks for multiple lines concactanated on one line (the database had lots of those). Finally, I added a screen capture function and made it check for invalid characters in default file names. This error checking script would only be useful if you want to add more quotes to the database. You can add more if you like. The main script adapts to more lines. You only have to have the quote separated by a "|- " (without quotes) to the author's name.

On a side note, this project has been named "Notable Quotes" since the beginning. But I thought "Quotable Quotes" was easier to find (if you are looking for something about quotes, it should start with a Q) and a bit more catchy, so I just renamed the project today. I kept my .nqd extension (abbvr for "notable quotes database") out of nostalgia.

Here's the main script:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <ScreenCapture.au3>
#NoTrayIcon

$myDocs = @MyDocumentsDir
If Not FileExists(@ScriptDir & "preferences.ini") Then
    _FileCreate(@ScriptDir & "preferences.ini")
    IniWrite(@ScriptDir & "preferences.ini", "LastSaved", "Location", $myDocs)
EndIf

$dataFile = @ScriptDir & "data.nqd"
If Not FileExists($dataFile) Then
    MsgBox(0, "Problem", "Quote data file missing. Please re-install this application")
    Exit
EndIf

$lineCount = _FileCountLines($dataFile)
$Form1 = GUICreate("Quotable Quotes .: www.fusionsolid.com", 456, 610, -1, -1, $WS_SYSMENU)
$random = Random(1, $lineCount)
$random = Round($random, 0)
$readLine = FileReadLine($dataFile, $random)
$quote = StringSplit($readLine, "|")
$Pic1 = GUICtrlCreatePic(@ScriptDir & "Scroll.jpg", 0, 0, 453, 580, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
$Label = GUICtrlCreateLabel($quote[1] & @CRLF & @CRLF & $quote[2], 40, 90, 375, 400)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 16, 800, 2, "Trebuchet MS")
$Label2 = GUICtrlCreateLabel("www.fusionsold.com", 344, 558, 101, 17)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetCursor(-1, 0)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Button_1 = GUICtrlCreateButton("Another Quote", 15, 545, 100)
$Button_2 = GUICtrlCreateButton("Save This One", 120, 545, 100)

GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $Button_1
            _NewQuote()
        Case $nMsg = $Label2
            ShellExecute("http://www.fusionsolid.com")
        Case $nMsg = $Button_2
            _SaveCopy()
    EndSelect
WEnd
Exit

Func _NewQuote()
    $random = Random(1, $lineCount)
    $random = Round($random, 0)
    $data1 = FileReadLine($dataFile, $random)
    $quote = StringSplit($data1, "|")
    GUICtrlSetData($Label, $quote[1] & @CRLF & @CRLF & $quote[2])
EndFunc   ;==>_NewQuote

Func _SaveCopy()
    $lastSaved = IniRead(@ScriptDir & "preferences.ini", "LastSaved", "Location", $myDocs)
    $save = FileSaveDialog("Save this file", $lastSaved, "Image File (*.jpg)", "", "Quotable Quotes " & $quote[2] & " - " & @MON & "-" & @MDAY & "-" & @YEAR & "@" & @HOUR & "." & @MIN & ".jpg")
    Dim $szDrive, $szDir, $szFName, $szExt
    $path = _PathSplit($save, $szDrive, $szDir, $szFName, $szExt)
    IniWrite(@ScriptDir & "preferences.ini", "LastSaved", "Location", $szDrive & $szDir)
    $pos = WinGetPos("Quotable Quotes .: www.fusionsolid.com")
    _ScreenCapture_Capture($save, $pos[0] + 16, $pos[1] + 45, $pos[0] + 445, $pos[1] + 574, False)
EndFunc   ;==>_SaveCopy

Here's my error checking code:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <array.au3>

$lineCount = _FileCountLines("data.nqd")

Dim $array[$lineCount+1 ][2]

;~ ;;;;;;;;;;;;; Check for bad lines ;;;;;;;;;;;;;;;;;;;;;

For $i = 1 to $lineCount Step 1
    $line = FileReadLine("data.nqd", $i)
    $quote = StringSplit($line, "|")
    if @error then
        MsgBox(0, "", "Error at: " & $i)
    Endif
    $array[$i-1][0] = $quote[1]
    $array[$i-1][1] = $quote[2]
Next


;~ ;;;;;;;;;;;;; Check for string lengths ;;;;;;;;;;;;;;;;;;;;;

If FileExists("array.csv") Then
    FileDelete("array.csv")
EndIf
For $i = 1 to $lineCount Step 1
    $line = FileReadLine("data.nqd", $i)
    $stringLength = StringLen($line)
    if @error then
        MsgBox(0, "", "stopped at: " & $i)
    Endif
    FileWrite("array.csv", $stringLength & "," & $i & @CRLF)
Next


;~ ;;;;;;;;;;;;; Make CSV of multiple quotes on one line ;;;;;;;;;;;;;;;;;;;;;

If FileExists("splits.csv") Then
    FileDelete("splits.csv")
EndIf
For $i = 1 to $lineCount Step 1
    $line = FileReadLine("data.nqd", $i)
    $stringsplit = StringSplit($line, "|")
    if @error then
        MsgBox(0, "", "stopped at: " & $i)
    Endif
    If $stringsplit > 2 Then
    FileWrite("splits.csv", $stringsplit[0] & "," & $i)
    EndIf
Next

;~ ;;;;;;;;;;;;; check for invalid characters for file names ;;;;;;;;;;;;;;;;;;;;;

For $i = 1 to $lineCount Step 1
    $line = FileReadLine("data.nqd", $i)
    $quote = StringSplit($line, "|")
    if @error then
        MsgBox(0, "", "Error at: " & $i)
    Endif
    FileWrite("characters", $quote[2])
Next

_ArrayDisplay($array)

This is the data file I created (it has over 4000 quotes):

http://www.fusionsolid.com/Projects/Quotable_Quotes/data.zip

The background picture:

http://www.fusionsolid.com/Projects/Quotable_Quotes/scroll.jpg

Finally, here's my website page to download the installer and have everything in one package.

http://www.fusionsolid.com/Projects/Quotable_Quotes/Quotable_Quotes.html

Edited by sleepydvdr

#include <ByteMe.au3>

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