Jump to content

Help or collaboration on a project I'm working on


Recommended Posts

I'm making a generic commandline utility that can be extended using a builtin editor. I'm currently having trouble linking a 2-dimension array, listbox, and the editbox. Those three things need to be as closely linked as can be for the editor to function correctly.

I'm new to AutoIt, though not new to scripting. I'm making this utility to help simplify what I am having to do with vbscript, wscript, and batch files.

Here is the editor code, including functions I'm not using yet but have implemented.

#include <GuiConstants.au3>
#include <string.au3>
#include <array.au3>
;#include <lb_wrappers_self-contained.au3>

Global $keys[5][2]

;$keys Sample Data
$keys[0][0] = "Item 1"
$keys[0][1] = "Line1" & @CR & @LF & "Line2" & @CR & @LF & "Line3" & @CR & @LF & "Line4" & @CR & @LF & "Line5" & @CR & @LF & "Line6" & @CR & @LF & "Line7"
$keys[1][0] = "Item 2"
$keys[1][1] = "Item 2 -- " & "Line1" & @CR & @LF & "Line2" & @CR & @LF & "Line3" & @CR & @LF & "Line4" & @CR & @LF & "Line5" & @CR & @LF & "Line6" & @CR & @LF & "Line7"
$keys[2][0] = "Item 3"
$keys[2][1] = "Item 3 -- " & "Line1" & @CR & @LF & "Line2" & @CR & @LF & "Line3" & @CR & @LF & "Line4" & @CR & @LF & "Line5" & @CR & @LF & "Line6" & @CR & @LF & "Line7"
$keys[3][0] = "Item 4"
$keys[3][1] = "Item 4 -- " & "Line1" & @CR & @LF & "Line2" & @CR & @LF & "Line3" & @CR & @LF & "Line4" & @CR & @LF & "Line5" & @CR & @LF & "Line6" & @CR & @LF & "Line7"
$keys[4][0] = "Item 5"
$keys[4][1] = "Item 5 -- " & "Line1" & @CR & @LF & "Line2" & @CR & @LF & "Line3" & @CR & @LF & "Line4" & @CR & @LF & "Line5" & @CR & @LF & "Line6" & @CR & @LF & "Line7"


Func _regread()
    Local $i
    $i = 0
    While 1
        ReDim $keys[(UBound($keys)+1)][1]
        $keys[$i][0] = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Util1", $i)
        If @error = -1 Then ExitLoop
        If @error = 1 Then _regsetup()
        $i = $i + 1

    WEnd
    $i = 0
    While 1
        $string = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Util1", $i)
        If @error = -1 Then ExitLoop
        If @error = 1 Then _regsetup()
        $keys[$i][1] = _StringEncrypt(0, $string, "Utility", 1)
        $i = $i + 1
    WEnd
EndFunc  ;==>_regread

Func _regwrite()
    For $i = 1 To UBound($keys)
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Util1", $keys[$i][0], "REG_SZ", _StringEncrypt(1, $keys[$i][1], "Utility", 1))
    Next
EndFunc  ;==>_regwrite

Func _additem()
    $newName = InputBox("New Item","New Item","New Item")
    _ArrayAdd($keys,"New Item")
    GuiCtrlSendMsg($List_2, 0x0180, 0, $newName)
   ;Refresh Listbox code goes here
   ;Refresh Editbox code goes here
EndFunc  ;==>_additem

Func _renameitem()
    $index = GuiCtrlSendMsg($List_2, 0x0188, 0, 0)
    $newName = InputBox("Rename Item","Rename Item",GuiCtrlRecvMsg($List_2, 0x0189, $index, 1))
    GuiCtrlSendMsg($List_2, 0x0182, $index, 0);LB_DELETESTRING
    GuiCtrlSendMsg($List_2, 0x181, $index, $newName);LB_INSERTSTRING
EndFunc  ;==>_renameitem

Func _regsetup()
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Util1")
    _regread()
EndFunc  ;==>_regsetup

Func Editor()
    
EndFunc  ;==>Editor
#region --- GuiBuilder code Start ---
GuiCreate("Debug Window", 176, 316,0, (@DesktopHeight-316)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$Label_ticks = GuiCtrlCreateLabel("Label1", 0, 0, 60, 20)
$Label_msg = GuiCtrlCreateLabel("Label1", 0, 20, 60, 20)
$Label_buffer = GuiCtrlCreateLabel("Label1", 0, 60)
$Label_index = GuiCtrlCreateLabel("Label1", 0, 40,60,20)
$Label_bufferhits = GuiCtrlCreateLabel("Label1", 0, 80, 60, 20)

GuiSetState()
#endregion --- GuiBuilder generated code End ---
#region --- GuiBuilder code Start ---

GUICreate("Commandline Editor", 628, 349, (@DesktopWidth - 628) / 2, (@DesktopHeight - 349) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$Edit_1 = GUICtrlCreateEdit("Edit1", 180, 0, 450, 330)
$List_2 = GUICtrlCreateList("List2", 0, 0, 180, 330, $LBS_NOINTEGRALHEIGHT);$LBS_SORT + $LBS_NOINTEGRALHEIGHT
$add = GUICtrlCreateButton("Add", 0, 330, 60, 20)
$rename = GUICtrlCreateButton("Rename", 60, 330, 60, 20)
$delete = GUICtrlCreateButton("Delete", 120, 330, 60, 20)
$save = GUICtrlCreateButton("Save", 500, 330, 60, 20)
$close = GUICtrlCreateButton("Close", 570, 330, 60, 20)
$label = GuiCtrlCreateLabel("Label", 280, 330, 60, 20)
GUICtrlSetData ( $Edit_1, "")
GUICtrlSetState($Edit_1,$GUI_DISABLE)
GUICtrlSetData ( $List_2, "")
for $i = 0 To (UBound($keys)-1)
    GuiCtrlSendMsg($List_2, 0x0180, 0, $keys[$i][0])
Next

;GUICtrlSetState($List_2,$GUI_DISABLE)
GUISetState()

GuiCtrlSendMsg($List_2, 0x0185, 1, 0)

Global $Prev_Selected = 0, $Selected, $buffer = 0, $ticks = 0, $index = 0, $Pindex = 0, $bufferHits = 0, $edit_enabled
While 1
    $ticks = $ticks + 1
    GUICtrlSetData($label,$ticks,0)
    $msg = GUIGetMsg()
    $buffer = GUICtrlRead($Edit_1)
    
    if $index <> -1 And Not $edit_enabled then
        GUICtrlSetState($Edit_1,$GUI_ENABLE)
        $edit_enabled = 1
    EndIf
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $List_2
            GUICtrlSetData ( $Edit_1, $keys[$index][1])
            $Pindex = $index
        ;MsgBox(4096,"ListBox item Selected:",$Selected)
        Case $msg = $Edit_1
            $keys[$Pindex][1] = $buffer
            $bufferHits = $bufferHits + 1
        ;MsgBox(4096,"Edit Message","Editbox Event Sent")
        Case $msg = $add
            _additem()
        Case $msg = $rename         
            _renameitem()
        Case Else
            $index = GuiCtrlSendMsg($List_2, 0x0188, 0, 0)
        ;;;
        EndSelect
        GUICtrlSetData ( $Label_ticks, "Ticks: " & $ticks)
        GUICtrlSetData ( $Label_msg, "Msg: " & $msg)
        GUICtrlSetData ( $Label_buffer, "Buffer: " & $buffer)
        GUICtrlSetData ( $Label_index, "Index: " & $index)
        GUICtrlSetData ( $Label_bufferhits, "Buffer Hits: " & $bufferHits)
WEnd
Exit
#endregion --- GuiBuilder generated code End ---
;#include <AutoSense.au3>
Link to comment
Share on other sites

a quick sidenote, "& @CR & @LF &" = "& @CRLF &"

and you can shorten :

;$keys Sample Data
$keys[0][0] = "Item 1"
$keys[0][1] = "Line1" & @CR & @LF & "Line2" & @CR & @LF & "Line3" & @CR & @LF & "Line4" & @CR & @LF & "Line5" & @CR & @LF & "Line6" & @CR & @LF & "Line7"
$keys[1][0] = "Item 2"
$keys[1][1] = "Item 2 -- " & "Line1" & @CR & @LF & "Line2" & @CR & @LF & "Line3" & @CR & @LF & "Line4" & @CR & @LF & "Line5" & @CR & @LF & "Line6" & @CR & @LF & "Line7"
$keys[2][0] = "Item 3"
$keys[2][1] = "Item 3 -- " & "Line1" & @CR & @LF & "Line2" & @CR & @LF & "Line3" & @CR & @LF & "Line4" & @CR & @LF & "Line5" & @CR & @LF & "Line6" & @CR & @LF & "Line7"
$keys[3][0] = "Item 4"
$keys[3][1] = "Item 4 -- " & "Line1" & @CR & @LF & "Line2" & @CR & @LF & "Line3" & @CR & @LF & "Line4" & @CR & @LF & "Line5" & @CR & @LF & "Line6" & @CR & @LF & "Line7"
$keys[4][0] = "Item 5"
$keys[4][1] = "Item 5 -- " & "Line1" & @CR & @LF & "Line2" & @CR & @LF & "Line3" & @CR & @LF & "Line4" & @CR & @LF & "Line5" & @CR & @LF & "Line6" & @CR & @LF & "Line7"

;$keys Sample Data
$i=0 to 4
     $keys[$i][0] = "Item " & $i + 1
     $keys[$i][1] = Stringreplace("Line1|Line2|Line3|Line4|Line5|Line6|Line7","|",@CRLF)
Next

Just having fun condencing code. :(

Sometimes I just use pipe seperated values for editing, and display it with them substituted by @crlf. I also use some very different delimitors if I think I might need a pipe, like þ which is alt+0254.

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Thanks for the tip... now I am having a wierd error with StringReplace when calling _iniwrite(). Here is the code for the functions that deal with the ini file.

Func _iniread()
    $keys = IniReadSection("cmdcon.ini", "Commands")
    If @error Then _inisetup()
    for $i = 1 To (UBound($keys)-1)
        $keys[$i][1] = Stringreplace($keys[$i][1],"þ",@CRLF);Decrypt($keys[$i][1])
        ConsoleWrite($i & @crlf)
    Next
EndFunc

Func _iniwrite()
    for $i = 1 To (UBound($keys)-1)
    ;IniWrite ( "cmdcon.ini", "Commands", $keys[$i][0], Encrypt($keys[$i][1]))
        IniWrite ( "cmdcon.ini", "Commands", $keys[$i][0], Stringreplace($keys[$i][1],@CRLF,"þ");Decrypt($keys[$i][1]))
    Next
EndFunc

Func _inisetup()
    IniWrite ( "cmdcon.ini", "Commands", "Item 1", "Item 1þLine1þLine2þLine3þLine4þLine5þLine6þLine7")
    IniWrite ( "cmdcon.ini", "Commands", "Item 2", "Item 2þLine1þLine2þLine3þLine4þLine5þLine6þLine7")
    IniWrite ( "cmdcon.ini", "Commands", "Item 3", "Item 3þLine1þLine2þLine3þLine4þLine5þLine6þLine7")
    IniWrite ( "cmdcon.ini", "Commands", "Item 4", "Item 4þLine1þLine2þLine3þLine4þLine5þLine6þLine7")
    IniWrite ( "cmdcon.ini", "Commands", "Item 5", "Item 5þLine1þLine2þLine3þLine4þLine5þLine6þLine7")
    _iniread()
EndFunc

Edit: I'm getting the following error:

IniWrite ( "cmdcon.ini", "Commands", $keys[$i][0], Stringreplace($keys[$i][1],@CRLF,"þ");Decrypt($keys[$i][1])) 
IniWrite ( "cmdcon.ini", "Commands", $keys[$i][0], Stringreplace($keys[$i][1],@CRLF,"þ"^ ERROR

Heh... nevermind.... unclosed parathences

Edited by amanda089
Link to comment
Share on other sites

pretty much. though now I am having an error that I can't track down. the second list-item, when run, the data in the array for it gets replaced with 0.

attached is the current code

Edit: I forgot to comment out an unused include in the attached file, fixed now.

Editor.au3

Edited by amanda089
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...