Jump to content

advice in storing an 2-dimensional array in a file


Bert
 Share

Recommended Posts

I have a script that makes and displays data. Pretty basic. What it does is allows you to make a short string of data for a title, then make a long string that can be a paragraph if you like. Example:

short string: Called user

Long string: Called user, left voice mail. Waiting for user to call back. Sent user email to notify them of receiving of ticket.

My question is this: I need a method of storing the data so that can be added to a array when the script runs. I thought of using an CSV file, but if the user doesn't have Office installed, that wouldn't work. I thought of using an INI, but I do not know how to handle things such as carriage returns, and if the user put in a "=" sign in his long or short string, that would cause a failure. If I use string split, and the user uses what I use to split the string, then a failure occurs there also. :)

If you need to see the script, I'm happy to post it, but I think in this case it isn't needed. I simply need a method of storing the data for future retrieval in an 2-dimensional array without any failures. Thoughts?

Link to comment
Share on other sites

I have a script that makes and displays data. Pretty basic. What it does is allows you to make a short string of data for a title, then make a long string that can be a paragraph if you like. Example:

short string: Called user

Long string: Called user, left voice mail. Waiting for user to call back. Sent user email to notify them of receiving of ticket.

My question is this: I need a method of storing the data so that can be added to a array when the script runs. I thought of using an CSV file, but if the user doesn't have Office installed, that wouldn't work. I thought of using an INI, but I do not know how to handle things such as carriage returns, and if the user put in a "=" sign in his long or short string, that would cause a failure. If I use string split, and the user uses what I use to split the string, then a failure occurs there also. :)

If you need to see the script, I'm happy to post it, but I think in this case it isn't needed. I simply need a method of storing the data for future retrieval in an 2-dimensional array without any failures. Thoughts?

Why do you need Office installed for a CSV? You only need Office installed if you want to open the CSV in excel.

You could store all of the data in a CSV then I assume you want to look at this data later on from th saved file yes?

Then just write another program which imports the data back from the CSV file and displayes it however you want evnen using array display if you can't be bothered to write your own GUI

Link to comment
Share on other sites

Why do you need Office installed for a CSV? You only need Office installed if you want to open the CSV in excel.

You could store all of the data in a CSV then I assume you want to look at this data later on from th saved file yes?

Then just write another program which imports the data back from the CSV file and displayes it however you want evnen using array display if you can't be bothered to write your own GUI

Oh and reading your post above, if using the CSV file method then encapsulate the data in Speach marks then if you have a comma in a sentence it won't matter, just do a string replace on " with 2 single ' ones before writing to the CSV to avoid breaking the encapsulation in speach marks

Link to comment
Share on other sites

I've already have written the GUI last night. I ran into this problem, and been thinking of a method to solve it.

;#cs
#include <GUIConstants.au3>
HotKeySet("{esc}","_exit")
Opt("GUIDataSeparatorChar","|") ;testing
$Form1_1 = GUICreate("", 889, 403, 193, 110)
$List1 = GUICtrlCreateList("", 16, 8, 210, 340)
$Input1 = GUICtrlCreateInput("", 16, 28, 210, 21)
GUICtrlSetState($input1, $GUI_HIDE)
GUICtrlSetData($List1,"Item1|Item2|Item3","") ;testing
$edit1 = GUICtrlCreateEdit("", 248, 8, 625, 377)
$Button1 = GUICtrlCreateButton("Close", 88, 352, 65, 33, 0)
$Button2 = GUICtrlCreateButton("Edit", 168, 352, 57, 33, 0)
$Button3 = GUICtrlCreateButton("Add", 16, 352, 57, 33, 0)
$Button4 = GUICtrlCreateButton("Save", 16, 352, 57, 33, 0)
$Button5 = GUICtrlCreateButton("Cancel", 88, 352, 65, 33, 0)
GUICtrlSetState($Button4, $GUI_HIDE)
GUICtrlSetState($Button5, $GUI_HIDE)
$lable1 = GUICtrlCreateLabel("title", 16, 8, 23, 20)
$lable2 = GUICtrlCreateLabel("text:", 200, 180, 20, 21)
GUICtrlSetState($lable1, $GUI_HIDE)
GUICtrlSetState($lable2, $GUI_HIDE)
GUISetState()
While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE or $nMsg = $Button1           
            Exit
        Case $nMsg = $Button2
            _edit1()
            $GCR = GUICtrlRead($List1)
            ;--------testing
            if $GCR = "Item1" then 
                GUICtrlSetData($edit1,"Item1 is highlighted","")
                GUICtrlSetData($Input1,"Item1")
            EndIf   
            if $GCR = "Item2" then 
                GUICtrlSetData($edit1,"Item2 is highlighted...","")
                GUICtrlSetData($Input1,"Item2")
            EndIf   
            if $GCR = "Item3" then 
                GUICtrlSetData($edit1,"Item3 is highlighted>>>>>","")
                GUICtrlSetData($Input1,"Item3")
            endif
            _edit1()
        Case $nMsg = $Button5
            _return()
        Case $nMsg = $List1
            $GCR = GUICtrlRead($List1)
            if $GCR = "Item1" then GUICtrlSetData($edit1,"Item1 is highlighted","")
            if $GCR = "Item2" then GUICtrlSetData($edit1,"Item2 is highlighted...","")  
            if $GCR = "Item3" then GUICtrlSetData($edit1,"Item3 is highlighted>>>>>","")    
    EndSelect
WEnd

func _exit()
    Exit
EndFunc

func _edit1()
    GUICtrlSetState($list1, $GUI_HIDE)
    GUICtrlSetState($Button1, $GUI_HIDE)    
    GUICtrlSetState($Button2, $GUI_HIDE)
    GUICtrlSetState($Button3, $GUI_HIDE)
    GUICtrlSetState($Button4, $GUI_SHOW)
    GUICtrlSetState($Button5, $GUI_SHOW)
    GUICtrlSetState($input1, $GUI_SHOW)
    GUICtrlSetState($lable1, $GUI_SHOW)
    GUICtrlSetState($lable2, $GUI_SHOW) 
EndFunc 

func _return()
    GUICtrlSetState($list1, $GUI_SHOW)
    GUICtrlSetState($Button1, $GUI_SHOW)
    GUICtrlSetState($Button2, $GUI_SHOW)
    GUICtrlSetState($Button3, $GUI_SHOW)
    GUICtrlSetState($Button4, $GUI_HIDE)
    GUICtrlSetState($Button5, $GUI_HIDE)
    GUICtrlSetState($input1, $GUI_HIDE)
    GUICtrlSetState($lable1, $GUI_HIDE)
    GUICtrlSetState($lable2, $GUI_HIDE)
EndFunc         
;#ce
Link to comment
Share on other sites

Have you looked at _CSVLib_V1.3.au3 from the examples forum

Thats a good idea. I wasn't sure on the CSV approach, but seeing how you don't need Excel loaded to make it work, it should solve the problem. My thanks to everyone who gave suggestions!
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...