glasglow Posted August 27, 2008 Share Posted August 27, 2008 I have a browse button and am looking for some logic on this. $btn2 = GUICtrlCreateButton ("Browse", 200, 90, 60, 20) While 1 $msg = GUIGetMsg() Select Case $msg = $btn2 ;stuff here GUICtrlCreateEdit($RS.Fields(0).Value = "", 10, 10, 300, 70, BitOR($WS_VSCROLL, $ES_MULTILINE)) ;close here EndSelect Wend So you can see, I am getting $RS.Fields(0).Value = "" from the database. I get the first value in the database but need to go onto the next value in the database (hopefully) by pressing the same button again. I thought of a $x + 1 but I don't know the logic with the $RS.Fields(0).Value and counting out the actual number of records. Link to comment Share on other sites More sharing options...
ResNullius Posted August 27, 2008 Share Posted August 27, 2008 I have a browse button and am looking for some logic on this. $btn2 = GUICtrlCreateButton ("Browse", 200, 90, 60, 20) While 1 $msg = GUIGetMsg() Select Case $msg = $btn2 ;stuff here GUICtrlCreateEdit($RS.Fields(0).Value = "", 10, 10, 300, 70, BitOR($WS_VSCROLL, $ES_MULTILINE)) ;close here EndSelect Wend So you can see, I am getting $RS.Fields(0).Value = "" from the database. I get the first value in the database but need to go onto the next value in the database (hopefully) by pressing the same button again. I thought of a $x + 1 but I don't know the logic with the $RS.Fields(0).Value and counting out the actual number of records.If you mean you want to get the value from the next record in the database, not the value of the next field in the current record, then $RS.MoveNext will move to the next record. Not sure why you are using $RS.Fields(0).Value = "" you just need $RS.Fields(0).Value to get the value. $RS.Fields(0).Value = "" will either set the field to "" or tests whether the value is ""and put that result (True/False) in the edit. To make sure you stop when at the end of the database, you need to do something like: Warning: Untested! $btn2 = GUICtrlCreateButton("Browse", 200, 90, 60, 20) $edit = GUICtrlCreateEdit("", 10, 10, 300, 70, BitOR($WS_VSCROLL, $ES_MULTILINE)) $recNum = 0 While 1 $msg = GUIGetMsg() Select Case $msg = $btn2 ;stuff here If $recNum <> 0 Then;if not on the first record If Not $RS.EOF Then $RS.MoveNext; if not at the End Of the recordset then move to the next record $recNum += 1;increment our record count for display $data = $RS.Fields(0).Value Else $data = "Record # " & $recNum & " was the last record" & @CRLF & & CRLF & "No more records to dispaly") EndIf GUICtrlSetData($edit, $data) ;close here EndSelect WEnd Also note, we create the edit control only once, and then use the GuiCtrlSetData() command to update it. Makes for smother transitions. Link to comment Share on other sites More sharing options...
glasglow Posted August 28, 2008 Author Share Posted August 28, 2008 (edited) If you mean you want to get the value from the next record in the database, not the value of the next field in the current record, then $RS.MoveNext will move to the next record. Not sure why you are using $RS.Fields(0).Value = "" you just need $RS.Fields(0).Value to get the value. $RS.Fields(0).Value = "" will either set the field to "" or tests whether the value is ""and put that result (True/False) in the edit. To make sure you stop when at the end of the database, you need to do something like: Warning: Untested! $btn2 = GUICtrlCreateButton("Browse", 200, 90, 60, 20) $edit = GUICtrlCreateEdit("", 10, 10, 300, 70, BitOR($WS_VSCROLL, $ES_MULTILINE)) $recNum = 0 While 1 $msg = GUIGetMsg() Select Case $msg = $btn2 ;stuff here If $recNum <> 0 Then;if not on the first record If Not $RS.EOF Then $RS.MoveNext; if not at the End Of the recordset then move to the next record $recNum += 1;increment our record count for display $data = $RS.Fields(0).Value Else $data = "Record # " & $recNum & " was the last record" & @CRLF & & CRLF & "No more records to dispaly") EndIf GUICtrlSetData($edit, $data) ;close here EndSelect WEnd Also note, we create the edit control only once, and then use the GuiCtrlSetData() command to update it. Makes for smother transitions. Thanks for that .. Yes I found the true/false mistake yesterday and also did some research to get the movenext.. Thank you though for the feedback. The method I'm using now to allow manual movement and stopping is something like this: (Where $active is set on a hot key) $active=1 $radek = 0 While 1 If @Error Then Exitloop Do If @Error Then Exitloop If $RS.EOF Then Exitloop GUICtrlCreateEdit($RS.Fields(0).Value, 10, 10, 300, 70, BitOR($WS_VSCROLL, $ES_MULTILINE)) Send("{F5}") $RS.MoveNext Until $active = 0 Wend However it's not exactly what I was looking for I guess. It's cool to go through the records though I suppose. Is there a better way where I can use the $btn2 click again and again to make changes.. or is that what you did here? Thanks for any suggestions. Edited August 28, 2008 by glasglow Link to comment Share on other sites More sharing options...
ResNullius Posted August 28, 2008 Share Posted August 28, 2008 Is there a better way where I can use the $btn2 click again and again to make changes..Do you mean you want to be able to input something in the edit box and when $btn2 is clicked it will update the value in the database (and then move to the next record)? Link to comment Share on other sites More sharing options...
glasglow Posted August 29, 2008 Author Share Posted August 29, 2008 Do you mean you want to be able to input something in the edit box and when $btn2 is clicked it will update the value in the database (and then move to the next record)?No the update is already all set. But actually moving from record to record is what I'm facing now. I have it now set so that for example $active = 1 or NOT. Right now I got a keyboard button set as the hotkey and a send() key to stop the loop automatically stopping after the record change , then I can physically release it. That's what my previous code is used for. However I was wondering how I could instead of using the hotkey the way I am use the $btn2 itself to move to the next record. So $btn2 shows the first record, then I click $btn2 again and it moves to the next record. I have been trying, which I thought would work is instead of a CASE using SELECT CASE so it's always paying attention, but even in doing that it will just bring me back to the first record after hitting the $btn2. I haven't figured out how to make the button relative to where it already is. Link to comment Share on other sites More sharing options...
ResNullius Posted August 29, 2008 Share Posted August 29, 2008 Is there a better way where I can use the $btn2 click again and again to make changes.. or is that what you did here? Thanks for any suggestions.However I was wondering how I could instead of using the hotkey the way I am use the $btn2 itself to move to the next record. So $btn2 shows the first record, then I click $btn2 again and it moves to the next record.Yes, that is what my code posted should do. Provided it's in your main Gui loop. If that's not the result you're getting using the code as I posted it, then you'll have to post more of your script so I can see what's going on. Link to comment Share on other sites More sharing options...
glasglow Posted August 29, 2008 Author Share Posted August 29, 2008 Yes, that is what my code posted should do. Provided it's in your main Gui loop. If that's not the result you're getting using the code as I posted it, then you'll have to post more of your script so I can see what's going on. I guess I'm not getting the actual loop of your code there. Nothing to relate the $recNum = 0 to $RS.Fields(0).Value. Should I use a different query to get the actual record number of the record that I'm looking at? I have right now: Case $msg = $btn2 ;;;readdata;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $dbname = "database" $tblname = "network" $T = "distribution" $addfld = ObjCreate("ADODB.Connection") $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname) $RS =ObjCreate("ADODB.Recordset") $RS.ActiveConnection = $addfld $RS.Open ("Select " & $T & " From " & $tblname ) ;;; PART A $active=1 $radek = 0 While 1 If @Error Then Exitloop Do If @Error Then Exitloop If $RS.EOF Then Exitloop GUICtrlCreateEdit($RS.Fields(0).Value, 10, 10, 300, 70, BitOR($WS_VSCROLL, $ES_MULTILINE)) Send("{F5}") $RS.MoveNext Until $active = 0 Wend ;;;END OF PART A $RS.Close $addfld.Close ;;;endreaddata;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EndSelect And it looks like with yours I would add the $recNum = 0 to the top and replace what I labeled PART A with the code below and it would be all set given my original edit was called $edit. But it always goes around the $recNum<> 0 to 0 record output. Because there is no connection putting a value as to which $RS.Fields it is currently on. See what I mean there? Sorry to ask so many questions and I certainly do appreciate your feedback. If $recNum <> 0 Then;if not on the first record If Not $RS.EOF Then $RS.MoveNext; if not at the End Of the recordset then move to the next record $recNum += 1;increment our record count for display $data = $RS.Fields(0).Value Else $data = "Record # " & $recNum & " was the last record" & @CRLF & @CRLF & "No more records to display" EndIf GUICtrlSetData($edit, $data) Link to comment Share on other sites More sharing options...
ResNullius Posted August 29, 2008 Share Posted August 29, 2008 So are you looking to move to and display the next field value of the same record? Or the same field, $RS.Fields(0).Value, of the next record?Consider a database that looks like this: Field_0 Field_1 Field_2 Record#1 Joe Smith 34 Record#2 Jane Johnson 25 Record#3 Sam Boswell 75Each time you press $btn2, are you wanting to just move through the database looking at all the field_0 values: Joe, then Jane, then Sam or do you want to start with record#1 and view Joe, then Smith, then 34 ?And if the latter, after you've viewed all the fields in the current record (one at a time), do you want to press $btn2 again, and that will move to the next record and start all over again, moving through each field every time you press $btn2?And/or in the end, do you want multiple edit controls on the GUI, displaying all the field values for 1 record and clicking $btn2 you would just move to the next record and again, display all the fields for that record? Link to comment Share on other sites More sharing options...
glasglow Posted August 30, 2008 Author Share Posted August 30, 2008 So are you looking to move to and display the next field value of the same record? Or the same field, $RS.Fields(0).Value, of the next record? Consider a database that looks like this: Field_0 Field_1 Field_2 Record#1 Joe Smith 34 Record#2 Jane Johnson 25 Record#3 Sam Boswell 75 Each time you press $btn2, are you wanting to just move through the database looking at all the field_0 values: Joe, then Jane, then Sam or do you want to start with record#1 and view Joe, then Smith, then 34 ? And if the latter, after you've viewed all the fields in the current record (one at a time), do you want to press $btn2 again, and that will move to the next record and start all over again, moving through each field every time you press $btn2? And/or in the end, do you want multiple edit controls on the GUI, displaying all the field values for 1 record and clicking $btn2 you would just move to the next record and again, display all the fields for that record? yes is exactly what I was looking for: (Great example) : ) "Each time you press $btn2, are you wanting to just move through the database looking at all the field_0 values: Joe, then Jane, then Sam" That's the logic I have with my loop, moving through record 1 then record 2 then record 3, but I can't get that loop onto the $btn2 (repeat click) Link to comment Share on other sites More sharing options...
ResNullius Posted August 31, 2008 Share Posted August 31, 2008 (edited) yes is exactly what I was looking for: (Great example) : ) "Each time you press $btn2, are you wanting to just move through the database looking at all the field_0 values: Joe, then Jane, then Sam" That's the logic I have with my loop, moving through record 1 then record 2 then record 3, but I can't get that loop onto the $btn2 (repeat click)This code has been tested and performs as expected: expandcollapse popup#include <GuiConstantsEx.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> ;;;readdata;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $dbname = "Database.mdb";had to add mdb extension to $dbname $tblname = "network" $T = "distribution" $addfld = ObjCreate("ADODB.Connection") $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname) $RS = ObjCreate("ADODB.Recordset") $RS.ActiveConnection = $addfld $RS.Open("Select " & $T & " From " & $tblname) $browser = GUICreate("dbBrowser") $label = GUICtrlCreateLabel("Record Number: ", 10, 5) $edit = GUICtrlCreateEdit("", 10, 20, 300, 70, BitOR($WS_VSCROLL, $ES_MULTILINE)) $btn2 = GUICtrlCreateButton("Browse", 200, 95, 60, 20) GUISetState() $recNum = 0 While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $btn2 If $recNum <> 0 And Not $RS.EOF Then $RS.MoveNext ;if NOT on the first record, move to the next If $RS.EOF Then ;if reached the end of records, loop back to first record ;comment out the next 3 lines and uncomment the 3 line block following to have the browse stop at the last record instead $RS.MoveFirst $data = $RS.Fields(0).Value $recNum = 0 #cs $data = "Record # " & $recNum & " was the last record" & @CRLF & @CRLF & "No more records to dispaly" GUICtrlSetData($edit, $data) ContinueLoop #ce Else $data = $RS.Fields(0).Value EndIf $recNum += 1;increment our record count for display GUICtrlSetData($edit, $data) GUICtrlSetData($label, "Record Number: " & $recNum) EndSelect WEnd Edited August 31, 2008 by ResNullius Link to comment Share on other sites More sharing options...
glasglow Posted September 1, 2008 Author Share Posted September 1, 2008 This code has been tested and performs as expected: expandcollapse popup#include <GuiConstantsEx.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> ;;;readdata;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $dbname = "Database.mdb";had to add mdb extension to $dbname $tblname = "network" $T = "distribution" $addfld = ObjCreate("ADODB.Connection") $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname) $RS = ObjCreate("ADODB.Recordset") $RS.ActiveConnection = $addfld $RS.Open("Select " & $T & " From " & $tblname) $browser = GUICreate("dbBrowser") $label = GUICtrlCreateLabel("Record Number: ", 10, 5) $edit = GUICtrlCreateEdit("", 10, 20, 300, 70, BitOR($WS_VSCROLL, $ES_MULTILINE)) $btn2 = GUICtrlCreateButton("Browse", 200, 95, 60, 20) GUISetState() $recNum = 0 While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $btn2 If $recNum <> 0 And Not $RS.EOF Then $RS.MoveNext;if NOT on the first record, move to the next If $RS.EOF Then;if reached the end of records, loop back to first record ;comment out the next 3 lines and uncomment the 3 line block following to have the browse stop at the last record instead $RS.MoveFirst $data = $RS.Fields(0).Value $recNum = 0 #cs $data = "Record # " & $recNum & " was the last record" & @CRLF & @CRLF & "No more records to dispaly" GUICtrlSetData($edit, $data) ContinueLoop #ce Else $data = $RS.Fields(0).Value EndIf $recNum += 1;increment our record count for display GUICtrlSetData($edit, $data) GUICtrlSetData($label, "Record Number: " & $recNum) EndSelect WEnd That's beautiful. So it looks like two things are the key to this code. First the movenext within the case. And second the $recNum with a ContinueLoop so it holds the $recnum count/position. I appreciate the code very much, now it's to understand it so I can munipulate it. : ) Thank you so much you have given me a new logic I've never really been able to use before. With an additional bonus actually moving back to the first value when it reaches the end. Thank you thank you... You are a good teacher! : ) Link to comment Share on other sites More sharing options...
ResNullius Posted September 1, 2008 Share Posted September 1, 2008 That's beautiful. So it looks like two things are the key to this code. First the movenext within the case. And second the $recNum with a ContinueLoop so it holds the $recnum count/position. I appreciate the code very much, now it's to understand it so I can munipulate it. : ) Thank you so much you have given me a new logic I've never really been able to use before. With an additional bonus actually moving back to the first value when it reaches the end. Thank you thank you... You are a good teacher! : )The $recNum variable isn't absolutely required for this to work.I use it more for the updating of the "Record Number: " label.When you do an $RS.MoveNext the recordset itself "remembers" what record number it's on.And testing for $RS.EOF lets us know when we've reached the end of all the records.If you want to make working with Access databases easier, check out GEOSoft's excellent Access UDF at http://www.autoitscript.com/forum/index.php?showtopic=40397 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now