Jump to content

This one is driving me crazy!


Recommended Posts

  • Developers

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

CC

In general don't try to read everything in a thread because there are not enough hours in a day for that. :)

Try solving it with the info given and when all still fails post a snippet showing your problem.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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

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

did you try my fixed bits of code?

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()
Link to comment
Share on other sites

Yes I did. here is the modified script.

CODE
#include <GUIConstants.au3>

#include <array.au3>

#include <Misc.au3>

#include "_MylistView.au3"

Global $ed1

Global $dblv

Global $dblistview

Global $dbselect

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

GUIDelete()

ExitLoop

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

$loopvar = 1

While $loopvar

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

GUIDelete()

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)

$loopvar = 0

GUIDelete($GUI)

EndFunc

Func CLOSEClicked()

Exit

EndFunc

Func GoodBye()

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

Exit

EndFunc

Thanks CC

Link to comment
Share on other sites

Yes I did. here is the modified script.

CODE
#include <GUIConstants.au3>

#include <array.au3>

#include <Misc.au3>

#include "_MylistView.au3"

Global $ed1

Global $dblv

Global $dblistview

Global $dbselect

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

GUIDelete()

ExitLoop

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

$loopvar = 1

While $loopvar

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

GUIDelete()

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)

$loopvar = 0

GUIDelete($GUI)

EndFunc

Func CLOSEClicked()

Exit

EndFunc

Func GoodBye()

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

Exit

EndFunc

Thanks CC
looks fairly rather unefficient and horrible, but glad it works. You should put the GUI in a function, so you can just call that function anytime you want it, also you have a few while loops, which, there is really no reason for, you should only need one

also you left the following code in, which serves no purpose. the while loops generally are there to keep that part of the code up and running, or a GUI up instead of closing/finishing. If you put it in a function you wont have to worry about keeping it up.

While 1
    Sleep(100); Idle around
WEnd
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()
Link to comment
Share on other sites

/edit corrected ADO creators name.

As far a the code being a mess, I absolutely agree. What you are seeing is snippets of code from various places. This particular script is the one I am having the hardest time getting to function. The UDF is a modified version of a suggestion I found mentioned in a link that provided GEOSoft's ADO udf. The original suggestion is still listed in the ADO thread for GEOSoft's ADO udf.

Because I do not know scripting very well yet I modified his version, and with the help of Martin (Thanks again Martin!!) got the query to work and display my DB records in the GUI window.

I don't believe it should be this difficult. But like I said i not very good at this yet.

Assume I want to scrap my script altogether. Where would you point me to start point to create the GUI lookup? I have overcome all of my other issues with the exception of the GUI DB lookup. This is the single issue that has caused the most frustration for me. I have found if you know what you are doing the help is very useful. If you don't have yet good skills the help file is not a beneficial.

I appreciate your feedback and previous assistance.

CC

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