Sign in to follow this  
Followers 0
IvanCodin

This one is driving me crazy!

25 posts in this topic

#1 ·  Posted (edited)

I have posted a similar script previously but have not been able to figure this one out. I want the OK button to close the gui and then continue on with the script. I have not included the UDP because I believe the work needs to be done in the main script. I can't believe it would be as difficult but could be wrong.

I new to the scripting so my skills are kinda like me driving a car down the freeway with a bag over my head. Your responses help me steer in the right direction but I do not always head in the right direction however :) .

I am as interested in learning why the answer is correct as I am in getting this script functioning.

If you can help me a double Mocha Latte is yours ;) !!!!

Here is the script. Please I beggin ya!!!

CODE
#include <GUIConstants.au3>

#include <array.au3>

#include <Misc.au3>

#include "_MylistView.au3"

MsgBox(0, "Info", " The scripts starts", 4)

$my_ver = "Ver 0.91.9"

If WinExists($my_ver) Then

MsgBox(4096,"Info", "Only one copy of this script can be run at once!!!" & @CRLF & @CRLF & " Program will now exit.", 6)

Exit

Else

EndIf

AutoItWinSetTitle($my_ver)

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

If FileExists ($DB) Then

; continue on

Else

MsgBox(4096, "Error", $DB & " Does NOT exist!!!!")

Exit

EndIf

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

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

$rasscriptpath = @ScriptDir & "\"

Opt("GUIOnEventMode", 1); OnEvent mode

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

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

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$ok1 = GUICtrlCreateButton ("OK",95, 20, 50)

GUICtrlSetOnEvent(-1, "OKClicked")

GUISetState(@SW_SHOW)

$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")

;GUISetState()

;While 1

; $msg = GuiGetMsg()

; Select

; Case $msg = $GUI_EVENT_CLOSE

; Exit

; Case $msg = $ok1

; ExitLoop

; Exit

;WEnd

;While 1

; $msg = GUIGetMsg()

;Select

;Case $msg = $ok1

; MsgBox(0, "TS", "Got from whle loop", 4)

; ExitLoop

;Case $msg = $GUI_EVENT_CLOSE

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

; ExitLoop

;EndSelect

;WEnd

While 1

Sleep(100); Idle around

WEnd

Local $text ,$ItText

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

$ItText = _GUICtrlListView_GetItemTextString($dblv,-1)

$text &= $ItText

GUICtrlSetData($ed1,$text & @CRLF)

MsgBox(4096, "Info", " Script continues", 3)

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

Case $event = $NM_DBLCLK

ListView_DoubleClick()

EndSelect

EndSelect

$tagNMHDR = 0

$event = 0

$lParam = 0

EndFunc

Func OKClicked()

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

EndFunc

Func CLOSEClicked()

Exit

EndFunc

Func GoodBye()

MsgBox(4096,"", "Goodbye!")

Exit

EndFunc

As always thanks for the assistance!!

CC

Edited by IvanCodin

Share this post


Link to post
Share on other sites



I have posted a similar script previously but have not been able to figure this one out. I want the OK button to close the gui and then continue on with the script. I have not included the UDP because I believe the work needs to be done in the main script. I can't believe it would be as difficult but could be wrong.

I new to the scripting so my skills are kinda like me driving a car down the freeway with a bag over my head. Your responses help me steer in the right direction but I do not always head in the right direction however :) .

I am as interested in learning why the answer is correct as I am in getting this script functioning.

If you can help me a double Mocha Latte is yours ;) !!!!

Here is the script. Please I beggin ya!!!

CODE
#include <GUIConstants.au3>

#include <array.au3>

#include <Misc.au3>

#include "_MylistView.au3"

MsgBox(0, "Info", " The scripts starts", 4)

$my_ver = "Ver 0.91.9"

If WinExists($my_ver) Then

MsgBox(4096,"Info", "Only one copy of this script can be run at once!!!" & @CRLF & @CRLF & " Program will now exit.", 6)

Exit

Else

EndIf

AutoItWinSetTitle($my_ver)

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

If FileExists ($DB) Then

; continue on

Else

MsgBox(4096, "Error", $DB & " Does NOT exist!!!!")

Exit

EndIf

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

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

$rasscriptpath = @ScriptDir & "\"

Opt("GUIOnEventMode", 1); OnEvent mode

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

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

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$ok1 = GUICtrlCreateButton ("OK",95, 20, 50)

GUICtrlSetOnEvent(-1, "OKClicked")

GUISetState(@SW_SHOW)

$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")

;GUISetState()

;While 1

; $msg = GuiGetMsg()

; Select

; Case $msg = $GUI_EVENT_CLOSE

; Exit

; Case $msg = $ok1

; ExitLoop

; Exit

;WEnd

;While 1

; $msg = GUIGetMsg()

;Select

;Case $msg = $ok1

; MsgBox(0, "TS", "Got from whle loop", 4)

; ExitLoop

;Case $msg = $GUI_EVENT_CLOSE

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

; ExitLoop

;EndSelect

;WEnd

While 1

Sleep(100); Idle around

WEnd

Local $text ,$ItText

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

$ItText = _GUICtrlListView_GetItemTextString($dblv,-1)

$text &= $ItText

GUICtrlSetData($ed1,$text & @CRLF)

MsgBox(4096, "Info", " Script continues", 3)

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

Case $event = $NM_DBLCLK

ListView_DoubleClick()

EndSelect

EndSelect

$tagNMHDR = 0

$event = 0

$lParam = 0

EndFunc

Func OKClicked()

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

EndFunc

Func CLOSEClicked()

Exit

EndFunc

Func GoodBye()

MsgBox(4096,"", "Goodbye!")

Exit

EndFunc

As always thanks for the assistance!!

CC

Perhaps you can look up and read the help file for GUIdelete


func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Well the help file reads like this:

#include <GUIConstants.au3>

GUICreate("My GUI"); will create a dialog box that when displayed is centered

GUISetState ()   ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

GUIDelete();  ; will return 1

This isn't a whole lotta help to me yet until I understand more of this script language. From the help file example I tried this. BTW You can view all of my attempts starting on line 57 of the script. I haven't posted without trying to make the script function.

I added this to my script at Line 55 but it didn't work either:

GUISetState ()

While 1

$msg = GUIGetMsg()

if $msg = $ok1 Then GUIDelete()

WEnd

I also tried this:

GUISetState()

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg = $ok1

ExitLoop

GUIDelete()

Exit

EndSelect

WEnd

Any Suggestions?

CC

Edited by IvanCodin

Share this post


Link to post
Share on other sites

Well the help file reads like this:

#include <GUIConstants.au3>

GUICreate("My GUI"); will create a dialog box that when displayed is centered

GUISetState ()  ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

GUIDelete(); ; will return 1

This isn't a whole lotta help to me yet until I understand more of this script language. From the help file example I tried this. BTW You can view all of my attempts starting on line 57 of the script. I haven't posted without trying to make the script function.

I added this to my script at Line 55 but it didn't work either:

I also tried this:

Any Suggestions?

CC

Try something like this

#include <GUIConstants.au3>

$GUIID = GUICreate("My GUI"); will create a dialog box that when displayed is centered

GUISetState ()  ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

GUIDelete($GUIID); ; will return 1

func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()

Share this post


Link to post
Share on other sites

;use _Singleton here
If WinExists($my_ver) Then
MsgBox(4096,"Info", "Only one copy of this script can be run at once!!!" & @CRLF & @CRLF & " Program will now exit.", 6)
Exit
Else ;what goes between the else and the endif? need to remove else.
EndIf

I think he is trying to close the gui only and then continue on with the rest of his code after the OK button is hit. dont think he is worried about having dual scripts running at once.


func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()

Share this post


Link to post
Share on other sites

Thanks for the advice but I still can't get it to work.

He is what I did:

Based on your request I determined the GUI ID was based on two factors. Line 28 and 30 of the of the script. I not positive but I believe this is correct.

Line 28 was this:

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

I changed it to this

Dim $title="DBViewer";gui title

Line 30 is Dim $gui = GUICreate($title, 600, 600) so I figured the GUI name I needed to deleted, based on your suggestion, was DBViewer so I added this to the script:

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

GUIDelete($GUI)

No joy!!

CC

Share this post


Link to post
Share on other sites

Thanks for the advice but I still can't get it to work.

He is what I did:

Based on your request I determined the GUI ID was based on two factors. Line 28 and 30 of the of the script. I not positive but I believe this is correct.

Line 28 was this:

I changed it to this

Line 30 is Dim $gui = GUICreate($title, 600, 600) so I figured the GUI name I needed to deleted, based on your suggestion, was DBViewer so I added this to the script:

No joy!!

CC

Can you post more of your script? i can get it to compile by commenting out, but still dont have the .mdb file, so it will be easier to help if the whole script was available


func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

No problem. I'll attach the script, udf and database. I can't upload a file with a .mdb extension so you'll have to rename my uploaded file.

Here is the _MyListView.au3 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 $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 successfully 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 only pauses script and does not continue

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

;EndFunc

Func cancel_button_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

And here is the script:

CODE
#include <GUIConstants.au3>

#include <array.au3>

#include <Misc.au3>

#include "_MylistView.au3"

MsgBox(0, "Info", " The scripts starts", 4)

$my_ver = "Ver 0.91.9"

If WinExists($my_ver) Then

MsgBox(4096,"Info", "Only one copy of this script can be run at once!!!" & @CRLF & @CRLF & " Program will now exit.", 6)

Exit

Else

EndIf

AutoItWinSetTitle($my_ver)

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

If FileExists ($DB) Then

; continue on

Else

MsgBox(4096, "Error", $DB & " Does NOT exist!!!!")

Exit

EndIf

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

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

$rasscriptpath = @ScriptDir & "\"

Opt("GUIOnEventMode", 1); OnEvent mode

Dim $title="DBViewer";gui title

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

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$ok1 = GUICtrlCreateButton ("OK",95, 20, 50)

GUICtrlSetOnEvent(-1, "OKClicked")

GUISetState(@SW_SHOW)

$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)

$selected = -1

$lastselected = -1

GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

GUISetState ()

; While 1

; $msg = GUIGetMsg()

; if $msg = $ok1 Then GUIDelete()

;WEnd

GUISetState()

;While 1

; $msg = GuiGetMsg()

; Select

; Case $msg = $GUI_EVENT_CLOSE

; Exit

; Case $msg = $ok1

; ExitLoop

; GUIDelete()

; Exit

; EndSelect

;WEnd

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

GUIDelete($GUI)

;While 1

; $msg = GUIGetMsg()

;Select

;Case $msg = $ok1

; MsgBox(0, "TS", "Got from whle loop", 4)

; ExitLoop

;Case $msg = $GUI_EVENT_CLOSE

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

; ExitLoop

;EndSelect

;WEnd

While 1

Sleep(100); Idle around

WEnd

Local $text ,$ItText

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

$ItText = _GUICtrlListView_GetItemTextString($dblv,-1)

$text &= $ItText

GUICtrlSetData($ed1,$text & @CRLF)

MsgBox(4096, "Info", " Script continues", 3)

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

Case $event = $NM_DBLCLK

ListView_DoubleClick()

EndSelect

EndSelect

$tagNMHDR = 0

$event = 0

$lParam = 0

EndFunc

Func OKClicked()

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

EndFunc

Func CLOSEClicked()

Exit

EndFunc

Func GoodBye()

MsgBox(4096,"", "Goodbye!")

Exit

EndFunc

and the attached file is the database. Rename it to test.mdb for the script to function.

Thanks

CC

Edited by IvanCodin

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I had issues getting this to run, but if i continue past the errors it works.

I was able to close the GUI by hitting ok and the script continues, but it looks after the script is closed it just goes into a continous loop that you have no way of getting out of except closing.

What exactly did you want to happen after the gui closed?

$loopvar = 1
While $loopvar
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop; you might want to change this to just exit, so you have a way of closing the whole script
WEnd
GUIDelete($GUI)

;While 1
; $msg = GUIGetMsg()
;Select
;Case $msg = $ok1
; MsgBox(0, "TS", "Got from whle loop", 4)
; ExitLoop

;Case $msg = $GUI_EVENT_CLOSE
; MsgBox(0, "GUI Event", "You clicked Close! Exiting ...")
; ExitLoop
;EndSelect
;WEnd


;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!SCRIPT will get stuck here with no way of getting out!
While 1
Sleep(100); Idle around ;
WEnd

Func OKClicked()
MsgBox(0, "OK Pressed", "OK Pressed", 4)
$loopvar = 0
GUIDelete($GUI)
EndFunc
Edited by Yeik

func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I am running version 3.2.10.0.

CC

Edited by IvanCodin

Share this post


Link to post
Share on other sites

I am running version 3.2.10.0. Where are you seeing the error?

CC

I updated my last post, i get lots of errors, but it runs if i hit continue anyway


func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()

Share this post


Link to post
Share on other sites

I ran it on my second laptop and got the script to run. I had included the array.au3 in my script and the UDF. I removed the UDP array.au3 include.

When it started the script all I saw was a GUI window and a OK button. I waited a second and the database query was displayed in the gui window. I don't know why it was slow but it did function if I waited.

CC

Share this post


Link to post
Share on other sites

I ran it on my second laptop and got the script to run. I had included the array.au3 in my script and the UDF. I removed the UDP array.au3 include.

When it started the script all I saw was a GUI window and a OK button. I waited a second and the database query was displayed in the gui window. I don't know why it was slow but it did function if I waited.

CC

just shows a lot of undefined variables and functions at first. It runs slow because that is the nature of any programming language similar to Autoit, its highlevel and made easy instead of for efficiency and speed.


func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()

Share this post


Link to post
Share on other sites

I am most likely wrong here but the variables should be in the include file. The errors for $ed1, $dblv, $dblistview, and $dbselect are defined in the UDF.

If a variables is defined in a UDF but called in a script is this acceptable or do I need to declare any variable in my script a global variable? I tried adding this

Global $ed1

Global $dblv

Global $dblistview

Global $dbselect

to the script but it didn't eliminate the errors.

This is only a smaller portion of a larger script I created. When you run this script and doubleclick on a database entry it will set several variables. I want the script to then continue and have the ability to read the variables created from the double click later in the script. When the scrip continues I run a RAS script that query connects to the remote system.

CC

Share this post


Link to post
Share on other sites

Think of it this way: the defined file in the #include statement is inserted at the line where the #include is defined, thus will be an integral part of it.

:)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

So I chewed on this for a while, nothing like a meal in a sentence :) , and believe I understand your comment. Don't set the include at the top of my main script. Go to the line in my script where the function will be called and use the #include <my_function> at that point in the script.

So in my script I would remove the #Include "_MyListview.au3" on line 4 and move it to line 41. Did I understand you correctly?

CC

Share this post


Link to post
Share on other sites

Yeik

I tried your suggestion and it does not continue the script. The GUIDelete function correctly, GUI is not visible and script is still running, but the script does not continue to the next step. What I am trying to do is show MsgBox Script is running, run the DB query and set values based on the double clicked item, show MSGBox Script continues text.

CC

Share this post


Link to post
Share on other sites

So I chewed on this for a while, nothing like a meal in a sentence :) , and believe I understand your comment. Don't set the include at the top of my main script. Go to the line in my script where the function will be called and use the #include <my_function> at that point in the script.

So in my script I would remove the #Include "_MyListview.au3" on line 4 and move it to line 41. Did I understand you correctly?

CC

Cannot answer it unless i have the script and know the exact problem but its really as simple as I stated it. You could easily simulate it by doing a Cut&paste of the Included file replacing the "#include <yourfile>" line.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I have posted my script, UDF, and database in one of the previously replies. Do you want me to send it again?

CC

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