Jump to content

Variables set from DoubleClick


IvanCodin
 Share

Recommended Posts

:D I am having a hard time finding where I should set my variables returned from the doubleclick. My first guess is the stringscript would be placed in the main script and not the udf. I put this is several places in the script to test but can not find the right location. Lines 41 thru 44 are were it appears it should be placed. A button on the DBListView may all that I need but I do not know if it should be placed in the UDF or the script.

ANY help would be appreciated.

What I am trying to accomplish is when the user doubles clicks the record they wish to use I would like to set variables for the database fields and have the script continue. Would a cancel or OK button on the DBListView do this? I also wanted to use the splitstring function to set the variables. I do not know if the code should be placed in the UDF or my script. Is my train of thought or method I am using is correct?

Here is the scripts I have created to set variables from a splitstring function. This is what I would like to use the set the variables returned for the doubleclick in my application. Am I using the right methods to do this?

CODE
#include <array.au3>

; code used to set returned value from doubleclick. use $ed1 or $dblv?????

; Blank the entry

$CompanyName = ""

$CompanyAddress = ""

$CompanyCity = ""

$CompanyState = ""

Dim $Test[5] = [3, 1, StringSplit("CompanyName|CompanyAddress1|CompanyCity|CompanyState", "|"), Cos(0)]

$ArrayInArray = $Test[2]

MsgBox(0, "", "First value is = " & $ArrayInArray[1])

MsgBox(0, "", "Second value is = " & $ArrayInArray[2])

MsgBox(0, "", "Second value is = " & $ArrayInArray[3])

MsgBox(0, "", "Second value is = " & $ArrayInArray[4])

$CompanyName = $ArrayInArray[1]

$CompanyAddress1 = $ArrayInArray[2]

$CompanyCity = $ArrayInArray[3]

$CompanyState = $ArrayInArray[4]

MsgBox( 0,"My Info", "I now have " & $CompanyName & $CompanyAddress1 & @CR & @LF & $CompanyCity & $CompanyState, 8)

; Variables were set correctly. Continue on with the script

Here is the main code:

CODE
#include <GUIConstants.au3>

#include "_DBlistView.au3"

#include <array.au3>

Do

$strName = InputBox("Input","Enter all or part of a company name to search for:",""," M")

Until $strName <> ""

; MsgBox(0,"Info", "You entered " & $strname, 8)

Opt("GUIOnEventMode", 1); OnEvent mode

Dim $title="Access db Viewer";gui title

Dim $gui = GUICreate($title, 600, 600)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$DB = @ScriptDir & "\test.mdb"

$Query= "SELECT CompanyName,CompanyAddress1,CompanyCity,CompanyState FROM CompanyName WHERE CompanyName LIKE " & "'" & $strName & "%' " & "ORDER BY CompanyName Asc"

; MsgBox(0,"Info", $Query, 8)

$Number_of_Records_to_Display = 20

$Listview_Left = 100

$Listview_Top = 50

$Listview_Width = 600

$Listview_Height = 400

$Listview_style = $GUI_SS_DEFAULT_LISTVIEW;default is -1

$Listview_exStyle = $LVS_EX_FULLROWSELECT + $LVS_EX_GRIDLINES;default is -1

$dblv = _createDBlistView($DB,$Query,$Number_of_Records_to_Display,$Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height,$Listview_style,$Listview_exStyle)

$ed1 = GUICtrlCreateEdit('',$Listview_Left,$Listview_Top + $Listview_Height,$Listview_Width,100)

GUISetState ()

$selected = -1

$lastselected = -1

GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

; While 1

; Sleep(100); Idle around

; WEnd

;Func ListView_DoubleClick()

;ConsoleWrite("Button_DblClick" & @LF)

;Local $itemIndex = _GUICtrlListView_GetNextItem ($dblv)

Local $text ,$ItText

$text = GUICtrlRead($ed1);read the text in the edit

$ItText = _GUICtrlListView_GetItemTextString($dblv,-1);read the items in the row double clicked

;Item text could be spilt into its parts using stringsplit

$text &= $ItText;add the items string to the text

GUICtrlSetData($ed1,$text & @CRLF);write the text into the edit;

;EndFunc ;==>Button_Click

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)

#forceref $hWndGUI, $MsgID, $wParam

Local $tagNMHDR, $event

$tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)

If @error Then Return

$event = DllStructGetData($tagNMHDR, 3)

Select

Case $wParam = $dblv

Select

Case $event = $NM_CLICK

;ListView_Click();func could be written to handle this

Case $event = $NM_DBLCLK

ListView_DoubleClick()

EndSelect

EndSelect

$tagNMHDR = 0

$event = 0

$lParam = 0

EndFunc ;

Func CLOSEClicked()

Exit

EndFunc

And here is the UDF:

CODE
#Include <GuiListView.au3>

#Include <array.au3>

Dim $conn,$DB,$Query,$rs,$tableField_Names,$data

Dim $dblistview,$Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height

Dim $prev_Button,$next_Button,$pageing_label,$i_StartingRecord=0,$i_OffsetRecord=0,$iStop,$iRows

Dim $table

Func Build_ListViewItems()

; If $dblistview Then _GUICtrlListView_DeleteAllItems ($dblistview)

If $dblistview Then DeleteAllItems ($dblistview)

$iRows = UBound($data, 1)-1

$iCols = UBound($data, 2)-1

If $iRows > ($i_OffsetRecord + $i_StartingRecord) Then

$iStop = $i_OffsetRecord + $i_StartingRecord - 1

Else

$iStop = $iRows

EndIf

For $iRowLoop = $i_StartingRecord to $iStop

$builcols=""

For $iColLoop = 0 to $iCols

$builcols&=$data[$iRowLoop][$iColLoop] & "|"

Next

GUICtrlCreateListViewItem($builcols, $dblistview)

GUICtrlSetOnEvent(-1, "")

;add your on-click function here

Next

GUICtrlSetData($pageing_label,"Viewing " & $i_OffsetRecord & " records starting at record " & $i_StartingRecord)

EndFunc

Func ListView_DoubleClick()

;ConsoleWrite("Button_DblClick" & @LF)

;Local $itemIndex = _GUICtrlListView_GetNextItem ($dblv)

Local $text ,$ItText

$text = GUICtrlRead($ed1);read the text in the edit

$ItText = _GUICtrlListView_GetItemTextString($dblv,-1);read the items in the row double clicked

;Item text could be spilt into its parts using stringsplit

$text &= $ItText;add the items string to the text

GUICtrlSetData($ed1,$text & @CRLF);write the text into the edit;

EndFunc ;==>Button_Click

Func next_button_clicked()

if $iStop < $iRows then

$i_StartingRecord=$i_StartingRecord + $i_OffsetRecord

Build_ListViewItems()

EndIf

EndFunc

Func prev_button_clicked()

if $i_StartingRecord > 0 then

$i_StartingRecord=$i_StartingRecord - $i_OffsetRecord

Build_ListViewItems()

EndIf

EndFunc

Func _createDBlistView($DB,$Query,$Records_to_Display,$Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height,$Listview_style,$Listview_exStyle)

$data=dbselect($Query)

$headers=$tableField_Names

$i_OffsetRecord = $Records_to_Display

If $prev_Button Then

GUICtrlDelete($prev_Button)

GUICtrlDelete($next_Button)

EndIf

GUICtrlCreateButton("<<Prev",$Listview_Left,$Listview_Top-30,50,25)

GUICtrlSetOnEvent(-1, "prev_button_clicked")

GUICtrlCreateButton("Next>>",$Listview_Left + 51,$Listview_Top-30,50,25)

GUICtrlSetOnEvent(-1, "next_button_clicked")

$pageing_label=GUICtrlCreateLabel("label",$Listview_Left+105,$Listview_Top-25,300,25)

If $dblistview Then

DeleteAllItems($dblistview)

;_GUICtrlListView_DeleteAllItems ($dblistview)

GUICtrlDelete($dblistview)

EndIf

$dblistview = GUICtrlCreateListView ($headers, $Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height,$Listview_style,$Listview_exStyle)

Build_ListViewItems()

return $dblistview ; This is what you have determine was needed

EndFunc

Func DeleteAllItems($dblistview)

Local $ctrlID

For $index = _GUICtrlListView_GetItemCount($dblistview) - 1 To 0 Step -1

$ctrlID = _GUICtrlListView_GetItemParam($dblistview, $index)

If $ctrlID Then GUICtrlDelete($ctrlID)

Next

EndFunc

Func DB_Open()

$conn=ObjCreate("ADODB.Connection")

$conn.Provider="Microsoft.Jet.OLEDB.4.0"

$conn.Open($DB)

$conn.CursorLocation = 3

Return $conn

EndFunc

Func dbselect($query)

DB_Open()

$rs = ObjCreate("ADODB.recordset")

$rs.Open ($query, $conn)

$tableField_Names=""

For $tablefield in $rs.fields

$tableField_Names &= $tablefield.name & "|"

next

$getRows_Data=$rs.GetRows()

$rs.close

DB_Close()

return $getRows_Data ;=>_createDBlistView()

EndFunc

Func DB_Close()

$conn.close()

EndFunc

Link to comment
Share on other sites

Just a comment on a couple of things.

This line-

Dim $Test[5] = [3, 1, StringSplit("CompanyName|CompanyAddress1|CompanyCity|CompanyState", "|"), Cos(0)]

will give you an array for the third element of $Test, is that what you intended? You have dimensioned it to have 5 elements but only initialised it with 4. The 4th element is Cos(0); why not just 1?

Regarding whether to put something in a UDF or not then it is entirely up to you if it's your UDF. In genereal I would say that a UDF should contain functions which might be needed by a variety of different scripts. So if you think an extra button say will be useful in other applications which will use the UDF then put it in the UDF, and make the function versatile enough to deal with whatever you think might be required. But if it's a button for a special requirement then put it in your main script.

But instead of an OK or Cancel button maybe it would be simpler to just use a MsgBox with Ok and Cancel buttons.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

This function uses the dblclick code you helped me with earlier. What I wanted to do is read the returned data from the doubleclick. I can not figure out whether it would be $text or $ITtext. This dblclick returned value is what I want to read it to an array and then set my variables. I put my test code at various places in my script but can't get it to function.

I figured I needed a DIM function in the script to do what I wanted. I did some research an discovered the DIM will return one more value than the returned items. To see the first item start at 2. Obviously my code is wrong, I want the first item, 2 not 3.

Working with the DIM function I wanted to see what I needed to do in my code to set the variables. I read the Help File and saw the an example and came up with my code which I modified for my array. It doesn't describe the COS settings and there effect. Because my script runs and displays the correct information I thought it was correct. Obviously I was wrong once again!!! However nothing beats learning new skills!! I can not find any description as to what the Cos(0) does or what effect 0 or 1 has on it?

My test script ran and displayed the information I wanted. Why does my example produce the output I expected?

BTW I still haven't given up on this!!! I definitely need to do some more work with my GUI. Not pretty but so far it functions correctly. The last piece I have it

CC

Link to comment
Share on other sites

BTW I assumed I could take the returned value from the double click event and send it to the DIM array;

Like:

<-- Assuming the Dblclick returns $text -->

Dim $text[5] = [2, 1, StringSplit("CompanyName|CompanyAddress1|CompanyCity|CompanyState", "|"), Cos(0)]

$ArrayInArray = $Test[2]

$CompanyName = $ArrayInArray[1]

$CompanyAddress1 = $ArrayInArray[2]

$CompanyCity = $ArrayInArray[3]

$CompanyState = $ArrayInArray[4]

MsgBox( 0,"My Info", "I now have " & $CompanyName & $CompanyAddress1 & @CR & @LF & $CompanyCity & $CompanyState, 8)

Link to comment
Share on other sites

I allready see an error in my logic. What I really need to do is read the dblclick $text into an DIM array. My example allready had the item values set. How would I convert the $text, containing thew values returned from the dblclick, into a DIM that then sets the correct values? I am going to be looking for a way to resolve this.

CC

Link to comment
Share on other sites

I allready see an error in my logic. What I really need to do is read the dblclick $text into an DIM array. My example allready had the item values set. How would I convert the $text, containing thew values returned from the dblclick, into a DIM that then sets the correct values? I am going to be looking for a way to resolve this.

CC

I am not sure I understand but you don't need to declare the array again with a Dim statement to change the values in the elements. The elements are just variables. So if you have got your $IText by reading the ListView item you can say

$test[2] = StringSplit($text,'|')

or

$ArrayinArray = StringSplit($text,'|')

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Martin,

Sorry I don't understand :D your response either. You already helped me with the doubleclick (tahnks again). I think it returns $text. It looks like you are indicating $text should have the database record with values I expect like: CompanyName|CompanyAddress1|CompanyCity|CompanyState

To test this I would put a msgbox and dosplay the information to see if the result is correct. I can not figure out where a msgbox would be placed to test this however.

This is difficult for me to describe because I may not be using sound programming techniques. But in a nutshell the doubleclick should set variables for all of the database files when clicked. I played around with your suggestion a bit and came up with this as a best guess. Is this what you a trying to explain to me?

Here is the code I think may do the trick:

#include <array.au3>

$InputString = "CompanyName|CompanyAddress1|CompanyCity|CompanyState" ; simulated result of the dblclcik event.

Local $text = $InputString ; use same variable name as expected variable from dblclick

; Local $aArray = StringSplit ( $String, '|' )

$ArrayinArray = StringSplit($text,'|')

_ArrayDisplay ( $text )

$CompanyName = $ArrayInArray[1]

$CompanyAddress1 = $ArrayInArray[2]

$CompanyCity = $ArrayInArray[3]

$CompanyState = $ArrayInArray[4]

MsgBox( 0,"My Info", "I now have " & $CompanyName & $CompanyAddress1 & @CR & @LF & $CompanyCity & $CompanyState & " to set as variables", 8) ; sloppy formating but displays info

;created my file

$script = "test.scp"

$script = @ScriptDir & "\test.scp"

$scriptpath = @ScriptDir

$file = FileOpen($script, 10) ; Check if file is opened for writing successfully

If $file = -1 Then

MsgBox(0, "Error", "Unable to the script file." & $file)

Exit

EndIf

FileWrite($file, " The Company Name is $CompanyName " & @CRLF)

FileWrite($file, " The address is $CompanyAddress1" & @CRLF)

; etc... To make my text file.

Does this clear up what I am attempting? As aleways thanks for your patience and assiatance.

CC

Link to comment
Share on other sites

Martin,

Sorry I don't understand :D your response either. You already helped me with the doubleclick (tahnks again). I think it returns $text. It looks like you are indicating $text should have the database record with values I expect like: CompanyName|CompanyAddress1|CompanyCity|CompanyState

To test this I would put a msgbox and dosplay the information to see if the result is correct. I can not figure out where a msgbox would be placed to test this however.

This is difficult for me to describe because I may not be using sound programming techniques. But in a nutshell the doubleclick should set variables for all of the database files when clicked. I played around with your suggestion a bit and came up with this as a best guess. Is this what you a trying to explain to me?

Here is the code I think may do the trick:

#include <array.au3>

$InputString = "CompanyName|CompanyAddress1|CompanyCity|CompanyState" ; simulated result of the dblclcik event.

Local $text = $InputString ; use same variable name as expected variable from dblclick

; Local $aArray = StringSplit ( $String, '|' )

$ArrayinArray = StringSplit($text,'|')

_ArrayDisplay ( $text )

$CompanyName = $ArrayInArray[1]

$CompanyAddress1 = $ArrayInArray[2]

$CompanyCity = $ArrayInArray[3]

$CompanyState = $ArrayInArray[4]

MsgBox( 0,"My Info", "I now have " & $CompanyName & $CompanyAddress1 & @CR & @LF & $CompanyCity & $CompanyState & " to set as variables", 8) ; sloppy formating but displays info

;created my file

$script = "test.scp"

$script = @ScriptDir & "\test.scp"

$scriptpath = @ScriptDir

$file = FileOpen($script, 10) ; Check if file is opened for writing successfully

If $file = -1 Then

MsgBox(0, "Error", "Unable to the script file." & $file)

Exit

EndIf

FileWrite($file, " The Company Name is $CompanyName " & @CRLF)

FileWrite($file, " The address is $CompanyAddress1" & @CRLF)

; etc... To make my text file.

Does this clear up what I am attempting? As aleways thanks for your patience and assiatance.

CC

I would put a message box, or a consolewrite, at the start of your double click function.

The rest of what you put in your last post looks ok to me. (Though maybe I would use FileWriteLn to save the & @CR)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thanks again Martin!! :D

I still have something I can't figure out. Sorry but my head is fifty miles deep in the code but here is what I have......

A GUI window is presented to the user that displays the companyname based on the result of the query. The user then double clicks the GUI window selection for the companyname they wish to select. The double click returns the result to the GUIwindow.

I do not want the user to view the returned data (the password are not to be seen by users, security issue!!). Currently the returned information is display in the bottom of the GUI window. What can I do to prevent this from being displayed to the user? I commented my code so that I can see where the info is returned. The information is being returned to the GUI window when this runs:

GUICtrlSetData($ed1,$text & @CRLF);write the text into the edit;

I have attached a screen shot of the window I am describing.

When the users double clicks the selection I want it to immediately close the window. I tried adding a $GUI_EVENT_CLOSE but it errors out with a "cannot assign values to constants". I only want the use to see a msgbox that states "You have selected {companyname} and let them select OK to continue.

CC

Edited by IvanCodin
Link to comment
Share on other sites

Edit.... I was finally able to create created a GUI OK button.

I tried editing the UDF to create an OK and Cancel buttons but have not been successful in displaying them in the GUI window. I successfully created the GUI OK button and trying to determine how it would be set to continue the script. Here is the remodified UDF code.

CODE
#Include <GuiListView.au3>

#Include <array.au3>

Dim $conn,$DB,$Query,$rs,$tableField_Names,$data

Dim $dblistview,$Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height

Dim $ok_button,$prev_Button,$next_Button,$pageing_label,$i_StartingRecord=0,$i_OffsetRecord=0,$iStop,$iRows

Dim $table

Func Build_ListViewItems()

; MsgBox(0, "ts", "Build_ListViewItems Line 9", 3)

; If $dblistview Then _GUICtrlListView_DeleteAllItems ($dblistview)

If $dblistview Then DeleteAllItems ($dblistview)

$iRows = UBound($data, 1)-1

$iCols = UBound($data, 2)-1

If $iRows > ($i_OffsetRecord + $i_StartingRecord) Then

$iStop = $i_OffsetRecord + $i_StartingRecord - 1

Else

$iStop = $iRows

EndIf

For $iRowLoop = $i_StartingRecord to $iStop

$builcols=""

For $iColLoop = 0 to $iCols

$builcols&=$data[$iRowLoop][$iColLoop] & "|"

Next

GUICtrlCreateListViewItem($builcols, $dblistview)

GUICtrlSetOnEvent(-1, "")

; MsgBox(0, "ts", "guictrlsetonevent line 27", 4)

;add your on-click function here

Next

GUICtrlSetData($pageing_label," Viewing " & $i_OffsetRecord & " records starting at record " & $i_StartingRecord)

EndFunc

Func ListView_DoubleClick()

; MsgBox(0, "ts", "Begin Dblclick", 0)

;ConsoleWrite("Button_DblClick" & @LF)

;Local $itemIndex = _GUICtrlListView_GetNextItem ($dblv)

Local $text ,$ItText

$text = GUICtrlRead($ed1);read the text in the edit

$ItText = _GUICtrlListView_GetItemTextString($dblv,-1);read the items in the row double clicked

;Item text could be spilt into its parts using stringsplit

; MsgBox(0, "ts", "text to itext line 42", 4)

$text &= $ItText ;add the items string to the text

; MsgBox(0, "ts", "ed1 to text line 44", 4)

GUICtrlSetData($ed1,$text & @CRLF) ;write the text into the edit;

; MsgBox(0, "ts", "array from stringsplit", 4)

$ArrayinArray = StringSplit($text,'|')

; _ArrayDisplay ( $text )

$CompanyName = $ArrayInArray[1]

$CompanyAddress1 = $ArrayInArray[2]

$CompanyCity = $ArrayInArray[3]

$CompanyState = $ArrayInArray[4]

MsgBox( 0,"My Info", "I now have (line52) " & $CompanyName & " " & $CompanyAddress1 & @CR & @LF & $CompanyCity & " " & $CompanyState & " to set as variables", 8)

EndFunc ;==>Button_Click

Func next_button_clicked()

; MsgBox(0, "ts", "next clicked" , 4)

if $iStop < $iRows then

$i_StartingRecord=$i_StartingRecord + $i_OffsetRecord

Build_ListViewItems()

EndIf

EndFunc

Func prev_button_clicked()

; MsgBox(0, "ts", "previous btn clicked", 4)

if $i_StartingRecord > 0 then

$i_StartingRecord=$i_StartingRecord - $i_OffsetRecord

Build_ListViewItems()

EndIf

EndFunc

Func ok_button_clicked()

MsgBox(0, "OK", "OK clicked", 4)

EndFunc

Func cancel_buton_clicked()

; MsgBox(0, "Cancel", "You canceled the scrtip .... Goodbye!", 4)

Exit

EndFunc

Func _createDBlistView($DB,$Query,$Records_to_Display,$Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height,$Listview_style,$Listview_exStyle)

; MsgBox(0, "ts", "prequery line 69 ", 4)

$data=dbselect($Query)

$headers=$tableField_Names

$i_OffsetRecord = $Records_to_Display

If $prev_Button Then

GUICtrlDelete($prev_Button)

GUICtrlDelete($next_Button)

GUICtrlDelete($ok_Button)

EndIf

GUICtrlCreateButton("OK",$Listview_Left,$Listview_Top-30,50,25)

GUICtrlCreateButton("<<Prev",$Listview_Left + 50,$Listview_Top-30,50,25)

GUICtrlSetOnEvent(-1, "prev_button_clicked")

GUICtrlCreateButton("Next>>",$Listview_Left + 101,$Listview_Top-30,50,25)

GUICtrlSetOnEvent(-1, "next_button_clicked")

$pageing_label=GUICtrlCreateLabel("label",$Listview_Left+155,$Listview_Top-25,300,25)

If $dblistview Then

DeleteAllItems($dblistview)

;_GUICtrlListView_DeleteAllItems ($dblistview)

GUICtrlDelete($dblistview)

EndIf

$dblistview = GUICtrlCreateListView ($headers, $Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height,$Listview_style,$Listview_exStyle)

Build_ListViewItems()

return $dblistview ; This is what you have determine was needed

$GUI_EVENT_CLOSE

; MsgBox(0, "GUI Event", "line 85 CLOSE! Exiting...")

EndFunc

Func DeleteAllItems($dblistview)

; MsgBox(0, "ts", "deleteallitems line 93", 4)

Local $ctrlID

For $index = _GUICtrlListView_GetItemCount($dblistview) - 1 To 0 Step -1

$ctrlID = _GUICtrlListView_GetItemParam($dblistview, $index)

If $ctrlID Then GUICtrlDelete($ctrlID)

Next

EndFunc

Func DB_Open()

; MsgBox(0, "ts", "dbopen line 101", 4)

$conn=ObjCreate("ADODB.Connection")

$conn.Provider="Microsoft.Jet.OLEDB.4.0"

$conn.Open($DB)

$conn.CursorLocation = 3

Return $conn

EndFunc

Func dbselect($query)

; MsgBox(0, "ts", "dbselect line 109", 4)

DB_Open()

$rs = ObjCreate("ADODB.recordset")

$rs.Open ($query, $conn)

$tableField_Names=""

For $tablefield in $rs.fields

$tableField_Names &= $tablefield.name & "|"

next

$getRows_Data=$rs.GetRows()

; if @error 'Or Not IsArray($getRows_data)' then

; Msgbox(0,"Error", "No records exist with this string.", 8)

; exit

;endif

$rs.close

DB_Close()

return $getRows_Data ;=>_createDBlistView()

EndFunc

Func DB_Close()

; MsgBox(0, "ts", "dbclose line 123", 4)

$conn.close()

EndFunc

I am still learning this scripting language. The relationship between the UDP and variables confuses me at times. I read my earlier post and realized what an idiot I was :-)!!! IE a splitstring returns and array. It is not necessary to create one merely read the values set from the splitstring. Even with the frustration I have with this script i find AutoIT enjoyable. I may be wearing this out but thanks again for you assistance I do appreciate the help.

CC

Edited by IvanCodin
Link to comment
Share on other sites

I was finally able to create the GUI OK button. I can not find out how to make the OK button automatically close the GUI window and continue the script. I left my attempts to accomplish in the code but comment them out.

Does anyone have ideas as to how I can do this? My earlier posts have not got may responses. Is my request meeting the forum requirements for information needed? If not what else do I need to provide? Remember I am not a programmer and my not be doing this in the most efficient manor.

Here is the script;

CODE
#include <GUIConstants.au3>

#include "_DBlistView.au3"

#include <array.au3>

Opt("GUIOnEventMode", 1); OnEvent mode

Dim $title="Access db Viewer";gui title

Dim $gui = GUICreate($title, 600, 600)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

; did not resolve ok pressed then close gui window

; $ok1 = GUICtrlCreateButton ("OK", 5, 25, 45)

; GUICtrlSetOnEvent(-1, "OKPressed")

; GUISetState(@SW_SHOW)

; While 1

; Sleep(10)

; Wend

$DB = @ScriptDir & "\test.mdb"

$Query= "SELECT CompanyName,CompanyAddress1,CompanyCity,CompanyState FROM CompanyName ORDER BY CompanyName Asc"

$Number_of_Records_to_Display = 20

$Listview_Left = 100

$Listview_Top = 50

$Listview_Width = 600

$Listview_Height = 400

$Listview_style = $GUI_SS_DEFAULT_LISTVIEW;default is -1

$Listview_exStyle = $LVS_EX_FULLROWSELECT + $LVS_EX_GRIDLINES;default is -1

$dblv = _createDBlistView($DB,$Query,$Number_of_Records_to_Display,$Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height,$Listview_style,$Listview_exStyle)

$ed1 = GUICtrlCreateEdit('',$Listview_Left,$Listview_Top + $Listview_Height,$Listview_Width,100)

GUISetState ()

$selected = -1

$lastselected = -1

GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

While 1

Sleep(100); Idle around

WEnd

Local $text ,$ItText

$text = GUICtrlRead($ed1);read the text in the edit

$ItText = _GUICtrlListView_GetItemTextString($dblv,-1);read the items in the row double clicked

;Item text could be spilt into its parts using stringsplit

$text &= $ItText;add the items string to the text

GUICtrlSetData($ed1,$text & @CRLF);write the text into the edit;

;EndFunc ;==>Button_Click

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)

#forceref $hWndGUI, $MsgID, $wParam

Local $tagNMHDR, $event

$tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)

If @error Then Return

$event = DllStructGetData($tagNMHDR, 3)

Select

Case $wParam = $dblv

Select

Case $event = $NM_CLICK ;ListView_Click();func could be written to handle this

Case $event = $NM_DBLCLK

ListView_DoubleClick()

EndSelect

EndSelect

$tagNMHDR = 0

$event = 0

$lParam = 0

EndFunc

Func OKPressed()

MsgBox(0, "OK Pressed", "OK Pressed", 4)

EndFunc

Func CLOSEClicked()

Exit

EndFunc

;While 1

; $msg = GUIGetMsg()

; Select

; Case $msg = $ok_button

; MsgBox(0, "GUI in UDF event", "You pressed OK!")

; Case $msg = $GUI_EVENT_CLOSE

; MsgBox(0, "GUI Event in UDF", "You clicked close!! Exiting...")

; ExitLoop

; EndSelect

; WEnd

MsgBox(4096, "GUI Exited", "GUI window was exited by pessing OK button", 4)

Exit

Here is the UDF with my modified code. I made various attempts and left them in the code but commented out.

CODE
#Include <GuiListView.au3>

#Include <array.au3>

Dim $conn,$DB,$Query,$rs,$tableField_Names,$data

Dim $dblistview,$Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height

Dim $ok_button,$prev_Button,$next_Button,$pageing_label,$i_StartingRecord=0,$i_OffsetRecord=0,$iStop,$iRows

Dim $table

Func Build_ListViewItems()

; MsgBox(0, "ts", "Build_ListViewItems Line 9", 3)

; If $dblistview Then _GUICtrlListView_DeleteAllItems ($dblistview)

If $dblistview Then DeleteAllItems ($dblistview)

$iRows = UBound($data, 1)-1

$iCols = UBound($data, 2)-1

If $iRows > ($i_OffsetRecord + $i_StartingRecord) Then

$iStop = $i_OffsetRecord + $i_StartingRecord - 1

Else

$iStop = $iRows

EndIf

For $iRowLoop = $i_StartingRecord to $iStop

$builcols=""

For $iColLoop = 0 to $iCols

$builcols&=$data[$iRowLoop][$iColLoop] & "|"

Next

GUICtrlCreateListViewItem($builcols, $dblistview)

GUICtrlSetOnEvent(-1, "")

; MsgBox(0, "ts", "guictrlsetonevent line 27", 4)

;add your on-click function here

Next

GUICtrlSetData($pageing_label," Viewing " & $i_OffsetRecord & " records starting at record " & $i_StartingRecord)

EndFunc

Func ListView_DoubleClick()

; MsgBox(0, "ts", "Begin Dblclick", 0)

;ConsoleWrite("Button_DblClick" & @LF)

;Local $itemIndex = _GUICtrlListView_GetNextItem ($dblv)

Local $text ,$ItText

$text = GUICtrlRead($ed1);read the text in the edit

$ItText = _GUICtrlListView_GetItemTextString($dblv,-1);read the items in the row double clicked

;Item text could be spilt into its parts using stringsplit

; MsgBox(0, "ts", "text to itext line 42", 4)

$text &= $ItText ;add the items string to the text

; MsgBox(0, "ts", "ed1 to text line 44", 4)

GUICtrlSetData($ed1,$text & @CRLF) ;write the text into the edit;

; MsgBox(0, "ts", "array from stringsplit", 4)

$ArrayinArray = StringSplit($text,'|')

; _ArrayDisplay ( $text )

$CompanyName = $ArrayInArray[1]

$CompanyAddress1 = $ArrayInArray[2]

$CompanyCity = $ArrayInArray[3]

$CompanyState = $ArrayInArray[4]

; MsgBox( 0,"My Info", "I now have (line52) " & $CompanyName & " " & $CompanyAddress1 & @CR & @LF & $CompanyCity & " " & $CompanyState & " to set as variables", 8)

EndFunc ;==>Button_Click

Func next_button_clicked()

; MsgBox(0, "ts", "next clicked" , 4)

if $iStop < $iRows then

$i_StartingRecord=$i_StartingRecord + $i_OffsetRecord

Build_ListViewItems()

EndIf

EndFunc

Func prev_button_clicked()

; MsgBox(0, "ts", "previous btn clicked", 4)

if $i_StartingRecord > 0 then

$i_StartingRecord=$i_StartingRecord - $i_OffsetRecord

Build_ListViewItems()

EndIf

EndFunc

Func ok_button_clicked()

; GUISetState(@SW_HIDE) ; closes the guiwindow but script pauses and does not Continue

; MsgBox(0, "OK", "OK clicked", 4) ; msgbox runs scuuessfully when ok is clicked in main gui page

; $GUI_EVENT_CLOSE ; error cannot assign variables to constants

; $continue = "Yes" ; try to use a variable to exit gui window

; MsgBox(0, "Info", "OK was clicked and was set to " & $continue , 4) ; show feedback to user and where it was being sent from

; GUIDelete(); close gui but olny pauses script and does not continue

; GUISetState($gui, @SW_HIDE) ; does nt appear to do anything

EndFunc

Func cancel_buton_clicked()

; MsgBox(0, "Cancel", "You canceled the scrtip .... Goodbye!", 4)

Exit

EndFunc

Func _createDBlistView($DB,$Query,$Records_to_Display,$Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height,$Listview_style,$Listview_exStyle)

; MsgBox(0, "ts", "prequery line 69 ", 4)

$data=dbselect($Query)

$headers=$tableField_Names

$i_OffsetRecord = $Records_to_Display

If $prev_Button Then

GUICtrlDelete($prev_Button)

GUICtrlDelete($next_Button)

GUICtrlDelete($ok_Button)

EndIf

GUICtrlCreateButton("OK",$Listview_Left,$Listview_Top-30,50,25)

GUICtrlSetOnEvent(-1, "ok_button_clicked")

GUICtrlCreateButton("<<Prev",$Listview_Left + 50,$Listview_Top-30,50,25)

GUICtrlSetOnEvent(-1, "prev_button_clicked")

GUICtrlCreateButton("Next>>",$Listview_Left + 101,$Listview_Top-30,50,25)

GUICtrlSetOnEvent(-1, "next_button_clicked")

$pageing_label=GUICtrlCreateLabel("label",$Listview_Left+155,$Listview_Top-25,300,25)

If $dblistview Then

DeleteAllItems($dblistview)

;_GUICtrlListView_DeleteAllItems ($dblistview)

GUICtrlDelete($dblistview)

EndIf

$dblistview = GUICtrlCreateListView ($headers, $Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height,$Listview_style,$Listview_exStyle)

Build_ListViewItems()

return $dblistview ; This is what you have determine was needed

$GUI_EVENT_CLOSE

; MsgBox(0, "GUI Event", "line 85 CLOSE! Exiting...")

EndFunc

Func DeleteAllItems($dblistview)

; MsgBox(0, "ts", "deleteallitems line 93", 4)

Local $ctrlID

For $index = _GUICtrlListView_GetItemCount($dblistview) - 1 To 0 Step -1

$ctrlID = _GUICtrlListView_GetItemParam($dblistview, $index)

If $ctrlID Then GUICtrlDelete($ctrlID)

Next

EndFunc

Func DB_Open()

; MsgBox(0, "ts", "dbopen line 101", 4)

$conn=ObjCreate("ADODB.Connection")

$conn.Provider="Microsoft.Jet.OLEDB.4.0"

$conn.Open($DB)

$conn.CursorLocation = 3

Return $conn

EndFunc

Func dbselect($query)

; MsgBox(0, "ts", "dbselect line 109", 4)

DB_Open()

$rs = ObjCreate("ADODB.recordset")

$rs.Open ($query, $conn)

$tableField_Names=""

For $tablefield in $rs.fields

$tableField_Names &= $tablefield.name & "|"

next

$getRows_Data=$rs.GetRows()

; attempt to capture no records found based on query

; if @error 'Or Not IsArray($getRows_data)' then

; Msgbox(0,"Error", "No records exist with this string.", 8)

; exit

;endif

$rs.close

DB_Close()

return $getRows_Data ;=>_createDBlistView()

EndFunc

Func DB_Close()

; MsgBox(0, "ts", "dbclose line 123", 4)

$conn.close()

EndFunc

As always thaks for the assist.

CC

Edited by IvanCodin
Link to comment
Share on other sites

Bump No responses?? I know there is someone out there that can assist! I want the OK button to close the GUI window and continue the script. Kinda like this:

CODE
#include <GUIConstants.au3>

Msgbox(0, "Info", "this is the program beginning", 4)

GUICreate("Hello World", 200, 100)

GUICtrlCreateLabel("Hello world! How are you?", 30, 10)

$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()

Select

Case $msg = $okbutton

MsgBox(0, "GUI Event", "You pressed OK!")

ExitLoop

Case $msg = $GUI_EVENT_CLOSE

MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")

ExitLoop

EndSelect

WEnd

Msgbox(0, "Info", "this is the program continuing", 4)

$value = InputBox("Testing", "Enter the 1 or 2 character code.", "", " M2")

MsgBox(0, "info", "You typed " & $value, 4)

I got the button to appear in the gui window but can't figure out where the code needs to be modified to make this happen. Someone ... Anyone have a suggestion?

CC

Link to comment
Share on other sites

#include <GUIConstants.au3>

MsgBox(0, "Info", "this is the program beginning", 4)
GUICreate("Hello World", 200, 100)
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $okbutton
            MsgBox(0, "GUI Event", "You pressed OK!")
            ExitLoop

        Case $msg = $GUI_EVENT_CLOSE
            MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
            ExitLoop
    EndSelect
WEnd
GUIDelete()
MsgBox(0, "Info", "this is the program continuing", 4)
$value = InputBox("Testing", "Enter the 1 or 2 character code.", "", " M2")
MsgBox(0, "info", "You typed " & $value, 4)

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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