7/8/2025 5:29:02 PM
|
|
slxdeveloper.com Community Forums |
|
|
|
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
|
|
|
|
Opening and Closing a Form
Posted: 06 Feb 08 9:41 AM
|
I dont know if it is even possible. i have an active script being invoked on the click of a button. the script does a huge calculation. so i want to display a small form showing the status like "calculating..." or something. how do i go about doing it. how can i invoke and close a form from an active script. |
|
|
|
Re: Opening and Closing a Form
Posted: 06 Feb 08 11:44 AM
|
move your calculation code to a manage form, put the progress bar on the manage form, then return the resultant value through a global variable. |
|
|
|
Re: Opening and Closing a Form
Posted: 06 Feb 08 11:53 AM
|
Great idea. i will do that....Thanks man. But still..just curious to know how to open and close a basic form from a script.. |
|
|
|
Re: Opening and Closing a Form
Posted: 06 Feb 08 12:15 PM
|
Originally posted by Sankar
I dont know if it is even possible. i have an active script being invoked on the click of a button. the script does a huge calculation. so i want to display a small form showing the status like "calculating..." or something. how do i go about doing it. how can i invoke and close a form from an active script. |
|
Yeah, I do this all the time. You need to just launch the form as a non-modal MainView. The form loads and shows but doesn't stop the execution of the script that launches it. As long as you hang on to the reference of the MainView object you can just close it from the other script when the stuff is all done. You can even update status messages in a label on the loaded form in the MainView as the process is running via your saved reference to the MainView object.
Make sense? |
|
|
|
Re: Opening and Closing a Form
Posted: 06 Feb 08 12:25 PM
|
Excatly..this is wat i was looking for..but i dont know how to load a form without stoping the execution of the script and how will u close the form... by setting the modalresult to mrcancel ? |
|
|
|
Re: Opening and Closing a Form
Posted: 06 Feb 08 12:45 PM
|
1) Create a dialog called "System:Progress Dialog". Add a label on it named "MessageLabel".
2) Add the following code to your script:
Dim m_Dlg Private Sub ShowProgressDialog Set m_Dlg = Application.MainViews.Add("System:Progress Dialog", 0, False) With m_Dlg .BorderStyle = 3 .Caption = "Processing" .Show End With Application.BasicFunctions.ProcessWindowMessages End Sub Private Sub UpdateProgress(ByVal Message) m_Dlg.DetailsView.MessageLabel.Caption = Message Application.BasicFunctions.ProcessWindowMessages End Sub Private Sub CloseProgressDialog On Error Resume Next m_Dlg.Close Set m_Dlg = Nothing Application.BasicFunctions.ProcessWindowMessages On Error Goto 0 End Sub
3) In your long running script,when you want the progress dialog to show just call the following:
ShowProgressDialog
4) When you want to update the table on the progress dialog just call this:
UpdateProgress "Starting up the flux capacitor..."
5) When you are done and want to close the dialog just execute the following:
CloseProgressDialog
Does all that make sense? I suppose I should make this one an article, but at least for now this should work for you.
-Ryan |
|
|
|
Re: Opening and Closing a Form
Posted: 06 Feb 08 1:07 PM
|
WOOOW..brilliant...it sure is an article item.. i will let you know once i implment this in my code.. thanks a lot Ryan. |
|
|
|
Re: Opening and Closing a Form
Posted: 06 Feb 08 2:57 PM
|
Ryan, it worked perfectly.... i just changed the border to 0 so it looks like a splash screen... thanks a lot for the help... |
|
|
|
Re: Opening and Closing a Form
Posted: 06 Feb 08 2:59 PM
|
Ryan, it worked perfectly.... i just changed the borderstyle to 0 so it looks like a splash screen... thanks a lot for the help... |
|
|
|
Re: Opening and Closing a Form
Posted: 31 Dec 09 6:22 AM
|
This is fantastic, as is saving me so much time (I used to pop up hidden panels all the time).
However, if I lauch this from an already open dialog / manage form (to show a window with a progress bar in it), when my progress bar windw closes, the "manage form" it was launch from also disappears behind the main Saleslogix screen.
Also, whilst the "progress window" is nicely counting up, if the user clicks outside of the form, the form disapears behind Saleslogix.
Is there any way of preventing this?
Cheers guys. |
|
|
|
Re: Opening and Closing a Form
Posted: 31 Dec 09 7:27 AM
|
Hi Folks,
I've figured out the answer to my own question through trial and error. I thought I'd pop it up on here in case it helps anyone else.
There are two things I have done which ensure that focus stays in the right place.
1) Use SetFocus after the dialog has closed to ensure the correct things spring back to the front after the "Progress Window" has closed. eg. grdExport.SetFocus - this pulls the form that it was on back to the front of the screen. You can always wrap this all up in a function where grdExport is passed as one of the parameters.
2) When opening the "Progress Window" dialog, change the window style from 0 to 2. This ensures the window remains in the foreground, but still does not interrupt the script that is running. eg. Application.MainViews.Add("System:Dialog - Progress", 2, False)
If it's of any use to anyone. I've wrapped this all up in a series of functions that export datagrids to excel. It's a lot better than the "xlWs.Cells.CopyFromRecordset rs" shortcut as well, as your memo fields do not get cut off at the legs, and it tries its best to format things in a friendlier way. However, it is slightly slower than xlWs.Cells.CopyFromRecordset rs.
The code is below if it helps anyone.
PREREQUISITES You need to create a "Manage" form with at least the following on it... 1) A progress bar called prgProgress (used to track progress) 2) A label called lblProgress (used to send text to during progress)
Save it down somewhere. In my case I saved it as "System:Dialog - Progress". That way, if I create any more I know they all begin with "Dialog"
USAGE Syntax: Grid_ExportToExcel (grdGRID, blCreateHeaderRow, blRemoveFirstColumn, blShowProgress, objReturnFocusTo) EG: Grid_ExportToExcel (grdExport, True, True, True, txtCurrentName)
grdGRID = The DataGrid object you are exporting to Excel blCreateHeaderRow = Tells the function whether or not you want the field names in the first row blRemoveFirstColumn = In many of the grids I use, I put the record ID in the first column. Use True or False to remove or keep the first column blShowProgress = Whether or not to launch the "Progress Window" dialog whilst running objReturnFocusTo = The object to return focus to when the function has finished, the majority of the time you can use the same object as grdGRID, unless it is hidden. Any control that allows the "SetFocus" method will do fine.
CODE
MAIN ROUTINE Sub Grid_ExportToExcel (grdGRID, blCreateHeaderRow, blRemoveFirstColumn, blShowProgress, objReturnFocusTo) Dim xlApp Dim xlWb Dim xlWs Dim rs Dim i Dim strHEADER
Dim iRowCount Dim iRow Dim iCol
Set rs = grdGRID.Recordset rs.MoveLast rs.MoveFirst iRowCount = rs.RecordCount
Set xlApp = CreateObject("Excel.Application") Set xlWb = xlApp.Workbooks.Add Set xlWs = xlWb.Worksheets("Sheet1")
xlApp.Visible = False xlApp.UserControl = False
'populate the data iRow = 1
if blShowProgress = True then Dialog_Progress_Show "Export to Excel...", iRowCount end if
Do While rs.EOF = False
'*** Update the progress dialog if blShowProgress = True then Dialog_Progress_Update CStr(iRow) & " / " & iRowCount, iRow end if
For iCol = 1 To rs.Fields.Count xlWs.Cells(iRow, iCol).Value = rs.Fields(iCol-1).Value Next xlWs.Cells(iRow, iCol).RowHeight = 13 iRow = iRow + 1 rs.MoveNext
Loop
'now let's add the columns headers if we need to if blShowProgress = True then Dialog_Progress_Update "Finalising...", iRow end if
if blCreateHeaderRow = True then 'and insert a new row for the title xlWs.Rows("1").Insert For i = 1 to rs.Fields.Count strHEADER = rs.Fields(i-1).Name & "" xlWs.Cells(1, i).Value = strHEADER Next end if
'now delete the first column if we need to if blRemoveFirstColumn = True then xlWs.Columns("A").Delete end if
'now auto-fit the width of the columns 'you dont have to do this if you dont want, but it can make the final spreadsheet easier to read xlApp.Selection.CurrentRegion.Columns.AutoFit xlApp.Selection.CurrentRegion.Rows.AutoFit xlApp.Selection.CurrentRegion.Rows.RowHeight = 13
xlApp.Visible = True xlApp.UserControl = True
Set xlWs = Nothing Set xlWb = Nothing Set xlApp = Nothing Set rs = Nothing
if blShowProgress = True then Dialog_Progress_Close objReturnFocusTo.SetFocus end if
MsgBox "Export Complete", vbInformation + vbOKOnly, "Finished"
end sub
DIALOG HANDLING ROUTINES Sub Dialog_Progress_Show (strCaption, intProgress_Max)
Set dlg_Progress = Application.MainViews.Add("System:Dialog - Progress", 2, False)
With dlg_Progress .DetailsView.lblProgress.Caption = "Processing..." .DetailsView.prgProgress.Max = intProgress_Max .BorderStyle = 3 .Caption = strCaption .Show End With Application.BasicFunctions.ProcessWindowMessages
End Sub
Sub Dialog_Progress_Update (strLabel, intProgress)
dlg_Progress.DetailsView.lblProgress.Caption = strLabel dlg_Progress.DetailsView.prgProgress.Position = intProgress Application.BasicFunctions.ProcessWindowMessages
End Sub
Sub Dialog_Progress_Close
On Error Resume Next dlg_Progress.Close '*** dlg_Progress.Parent.Visible = True Set dlg_Progress = Nothing Application.BasicFunctions.ProcessWindowMessages On Error Goto 0
End Sub |
|
|
|
Re: Opening and Closing a Form
Posted: 31 Dec 09 7:28 AM
|
Looks like you'll have to add your own tabs I have no idea how to format the code I paste up in here.
Sorry if it's too long winded Ryan. Wipe it out if you need to, I won't cry. |
|
|
|
Re: Opening and Closing a Form
Posted: 31 Dec 09 8:05 AM
|
Originally posted by Guy Barrett
Looks like you'll have to add your own tabs I have no idea how to format the code I paste up in here.
Sorry if it's too long winded Ryan. Wipe it out if you need to, I won't cry. |
|
Use PRE and /PRE tags (in angled brackets) to maintain code formatting.
here's some code
|
|
|
|
Re: Opening and Closing a Form
Posted: 31 Dec 09 8:19 AM
|
I'll have to remember that for the future. Is it just one set of tags surrounding the whole code, or a set of tags per line? |
|
|
| |
|
You can
subscribe to receive a daily forum digest in your
user profile. View the site code
of conduct for posting guidelines.
Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
|
|
|
|
|
|
|
|