Sign in to follow this  
Followers 0
CheapoDepot

File Menu and Database Help

4 posts in this topic

Hi,

I've done some searching but am still having trouble understanding and applying these concepts.

I want my script to be able to do the following.

* Save the data that a user inputs into a file.

* I want the file to be easily readable or manipulated from notepad, etc.

* Should this file be an *ini, *.csv, *.txt, etc?

* Open the previously saved data file and populate the script with that saved data.

* Fix the script such that when a file is opened, the Results_Group auto updates instead of having to reselect each item for it to work.

* Learn how to input and use large amounts of data in a user friendly database and have my script read it.

* What database can handle large amounts of data that is easy to view, input, and modify?

* SQLite, MS Access, etc?

Any help is much appreciated.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#Include <WinAPI.au3>


Global Const $DebugIt = 1

Global Const $CBN_EDITCHANGE = 5;
Global Const $CBN_SELCHANGE = 1;
Global Const $CBN_EDITUPDATE = 6;

#Region ### START Koda GUI section ### Form=c:\program files (x86)\autoit3\koda_1.7.3.0\forms\fender design.kxf
$Form1_1 = GUICreate("Fender Design", 623, 449, 194, 115)

; Menu Items
$filemenu = GUICtrlCreateMenu("&File")
    $newitem = GUICtrlCreateMenuItem("New", $filemenu)
    $openitem = GUICtrlCreateMenuItem("Open", $filemenu)
    $closeitem = GUICtrlCreateMenuItem("Close", $filemenu)
    $saveitem = GUICtrlCreateMenuItem("Save", $filemenu)
    $saveasitem = GUICtrlCreateMenuItem("Save As...", $filemenu)
    $menubar1item = GUICtrlCreateMenuItem("", $filemenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
$fenderselectionmenu = GUICtrlCreateMenu("F&ender Selection")
    $scnitem = GUICtrlCreateMenuItem("Super Cone", $fenderselectionmenu)
    $sckitem = GUICtrlCreateMenuItem("Cell", $fenderselectionmenu)
    $ueitem = GUICtrlCreateMenuItem("Unit Element", $fenderselectionmenu)
    $mvitem = GUICtrlCreateMenuItem("MV Element", $fenderselectionmenu)
    $mi2000item = GUICtrlCreateMenuItem("MI-2000", $fenderselectionmenu)
    $mi2000sitem = GUICtrlCreateMenuItem("MI-2000S", $fenderselectionmenu)
    $menubar2item = GUICtrlCreateMenuItem("", $fenderselectionmenu)
    $sgitem = GUICtrlCreateMenuItem("Sea Guard", $fenderselectionmenu)
    $scitem = GUICtrlCreateMenuItem("Sea Cushion", $fenderselectionmenu)
    $donutitem = GUICtrlCreateMenuItem("Donut", $fenderselectionmenu)
$panel_designmenu = GUICtrlCreateMenu("&Panel Design")
$helpmenu = GUICtrlCreateMenu("&Help")
    $aboutitem = GUICtrlCreateMenuItem("About...", $helpmenu)

; Fender Selection Input Structure
$scn_group = GUICtrlCreateGroup("Super Cone", 8, 0, 609, 425)
GUICtrlCreateLabel("Height", 24, 24, 35, 17)
$Height_List = GUICtrlCreateList("", 24, 40, 113, 58)
GUICtrlSetData($Height_List, "_|300|350|400|500|550", "_"); default "_"
GUICtrlCreateLabel("Compound", 280, 24, 55, 17)
$Compound_List = GUICtrlCreateList("", 280, 40, 113, 58)
GUICtrlSetData($Compound_List, "_|0.9|1.0|1.1|1.2|1.3", "_"); default "_"
GUICtrlCreateLabel("Quantity", 408, 24, 43, 17)
$Quantity_Input = GUICtrlCreateInput("", 408, 40, 49, 21)
GUICtrlCreateLabel("Length", 152, 24, 37, 17)
$Length_List = GUICtrlCreateList("", 152, 40, 113, 58)
$Adjustment_Factors_Group = GUICtrlCreateGroup("Adjustment Factors", 16, 128, 481, 89)
GUICtrlCreateLabel("Angle Factors", 24, 152, 69, 17)
GUICtrlCreateLabel("AFl", 24, 168, 19, 17)
$AFl_input = GUICtrlCreateInput("", 24, 184, 41, 21)
GUICtrlCreateLabel("AFh", 96, 168, 23, 17)
$AFh_input = GUICtrlCreateInput("", 96, 184, 41, 21)
GUICtrlCreateLabel("Temperature", 168, 152, 64, 17)
GUICtrlCreateLabel("Factor", 168, 168, 34, 17)
$TF_input = GUICtrlCreateInput("", 168, 184, 41, 21)
GUICtrlCreateLabel("Velocity", 240, 152, 41, 17)
GUICtrlCreateLabel("Factor", 240, 168, 34, 17)
$VF_input = GUICtrlCreateInput("", 240, 184, 41, 21)

; Fender Selection Results Structure
$Results_Group = GUICtrlCreateGroup("Results_Group", 16, 224, 481, 121)
$Result_List = GUICtrlCreateEdit("", 24, 248, 233, 84, $ES_AUTOVSCROLL + $WS_VSCROLL)
GUICtrlSetState($Result_List, $GUI_DISABLE)                ;Greys out Control
    $r_text = GUICtrlSetData($Result_List, "SCN" & " " & GUICtrlRead($Height_List) & " E" & GUICtrlRead($Compound_List) & @CRLF & _
            "    Energy = " & "" & "kNm [" & "" & " ft-kip]" & @CRLF & _
            "    Reaction = " & "" & "kN [" & "" & " kip]" & @CRLF & _
            "    Rated Deflection = " & "" & "%")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")


    While 1
        $msg = GUIGetMsg()


        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop

            Case $msg = $openitem
                    $message = ("Open")
                    $var = FileOpenDialog($message, @ScriptDir & "\", "INI (*.ini)|All Files (*.*)")
                    $file = FileRead($var)
                    GUICtrlSetData($Height_List, $file)

                    
            Case $msg = $saveasitem
                    $file = FileSaveDialog("Save As", @ScriptDir, "INI (*.ini)|All Files (*.*)", 18, "Fender Design.ini")
                    $xFile = FileOpen($file, 8 + 2)
                    FileWrite($xFile, GUICtrlRead($Height_List))


            Case $msg = $exititem
                ExitLoop

            Case $msg = $aboutitem
                MsgBox(0, "About", "Program to assist in the development of fender systems.")
        EndSelect
    WEnd


Func _Data_Changed()
    GUICtrlSetData($Result_List, "SCN" & " " & GUICtrlRead($Height_List) & " E" & GUICtrlRead($Compound_List) & @CRLF & _
            "    Energy = " & "" & "kNm [" & "" & " ft-kip]" & @CRLF & _
            "    Reaction = " & "" & "kN [" & "" & " kip]" & @CRLF & _
            "    Rated Deflection = " & "" & "%")
EndFunc   ;==>_Data_Changed

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)
    Local $hCtrl = $lParam

    Switch $nID
        Case $Quantity_Input
            Switch $nNotifyCode
                Case $EN_CHANGE
                    _Data_Changed()
            EndSwitch
        Case $Height_List, $Compound_List
            Switch $nNotifyCode
                Case $CBN_EDITUPDATE, $CBN_EDITCHANGE ; when user types in new data
                    _Data_Changed()
                Case $CBN_SELCHANGE ; item from drop down selected
                    _Data_Changed()
            EndSwitch
    EndSwitch
    ; Proceed the default Autoit3 internal message commands.
    ; You also can complete let the line out.
    ; !!! But only 'Return' (without any value) will not proceed
    ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

Func _DebugPrint($r_text)
    $r_text = StringReplace($r_text, @LF, @LF & "-->")
    ConsoleWrite("!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $r_text & @LF & _
            "+===========================================================" & @LF)
EndFunc   ;==>_DebugPrint


Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc   ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord

Share this post


Link to post
Share on other sites



If you use an .ini file, there is no need for FileOpen(), FileRead(), etc. Just look up the INI functions in the help file like IniRead() and IniWrite().

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

If I use IniRead() and IniWrite(), can I still save and open multiple INI files with different file names?

Share this post


Link to post
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
Sign in to follow this  
Followers 0