I am using msflexgrid in my vb6 application, It do work fine,but if any cell has large content then the problem comes. the problem is that when we navigate in grid by using arrow buttons, navigation becomes very slow when the cell with large content comes to visible area.Otherwise it works fine. In this case i am not trying to open the cell content of grid,just navigating from one cell to another. So how this slow performance or slow navigation can be solved or improved?
Set your Redraw property to false
And set it to true again after update completed.
I know that once I had set autosize column rows on and it caused massive speed issues. Now I leave auto-size off normally, turn it on breifly when the data first loads, and make it an option for the user via context menu.
I setup a test harness using the Service Pack 6 (latest) version of the MSFlex grid control as follows:
Private Sub Form_Load()
Dim i, j As Integer
Dim s As String
For j = 1 To 500
For i = 65 To 122
s = s & Chr(i)
Next i
Next j
For i = 1 To 4
For j = 1 To 10
MSFlexGrid.Col = i
MSFlexGrid.Row = j
MSFlexGrid.Text = s
Next j
Next i
End Sub
The MSFlex Grid control had 5 columns and 50 rows in my case.
This generates about 29K (58 chars * 500 repeats) of data per cell. I can navigate fairly quickly from cell to cell with this test harness. I would suggest that you ensure you are using the latest (SP6) version of the control.
If you are using the SP6 version and the amount of data that you are displaying in each cell is so large that it is still causing a performance issue I would suggest switching to another control.
Possibly integrate a 3rd party VB6 control or leverage something you've written in .NET and integrate into your VB6 form.
Related
Suppose you have a microsoft word file (.DOCX), you open it and start to view it, using the mouse scrolling, from page 1 towards the last page.
Then, suppose you see a table, for instance, on page 4.
Now I ask: is it possible for Word-VBA to say to you what is the index or name of that table that is on the screen at the moment, no matter where is cursor located?
I want word-VBA fullfil a table that I am seeing at that moment, no matter where the cursor is located.
I hope I was clear enough...
Word doesn't have a direct way to get what's visible on-screen. It can be calculated, sort of, but not with 100% accuracy.
The following code sample does the trick for me, on my machine. It may need some tweaking to work on a different set up.
The object model does return the co-ordinates of the application window (ActiveWindow, here), the height of that Window and the UsableHeight - the height of the actual document working space. That can be used to get an estimated position.
There's also a Windows API function equivalent - RangeFromPoint - for a Window object that returns the a Range in the document for the given screen co-ordinates.
This code calculates a left and top position for the start of the visible part of the document, as well as for the end of the visible document. (In my test, it was a bit more, but not much). It then checks whether there is one or more tables within that scope. If it is, it takes the first one ( Set tbl = rngTargetStart.Tables(1)) - this returns the object your code needs to work with. As a "bonus", the code prints the index number of the table in the document and the page it's on to the Immediate Window.
Sub CheckForTableOnPage()
Dim WordWindowTop As Long 'in points
Dim WordWindowLeft As Long 'in points
Dim windowUsableHeight As Long 'in points
Dim rngTargetStart As Range
Dim rngTargetEnd As Range
Dim pageNumberTarget As Long
Dim tbl As Table
WordWindowTop = ActiveWindow.height
WordWindowLeft = ActiveWindow.left
windowUsableHeight = ActiveWindow.UsableHeight
RibbonFactor = 200
Set rngTargetStart = ActiveWindow.RangeFromPoint(WordWindowLeft, WordWindowTop - windowUsableHeight)
Set rngTargetEnd = ActiveWindow.RangeFromPoint(WordWindowLeft, WordWindowTop + windowUsableHeight)
rngTargetStart.End = rngTargetEnd.End
If rngTargetStart.Tables.Count >= 1 Then
pageNumberTarget = rngTargetStart.Information(wdActiveEndPageNumber)
Set tbl = rngTargetStart.Tables(1)
rngTargetStart.Start = ActiveDocument.Content.Start
Debug.Print "The table on page " & pageNumberTarget & " is number: " & rngTargetStart.Tables.Count
End If
End Sub
I am fairly familiar with userforms, so I decided to try and get a little fancy and attempted to make a userform grow/shrink and reposition to align center based on a checkbox change event.
The code is working as intended, but there is one issue. When shrinking the userform, the userform leaves a trail of all size increments set during the loop. This makes the program look less "smooth". I've included a screenshot of the issue as well as the relevant code.
I've tried including variations of DoEvents and Application.ScreenUpdating. ScreenUpdating seemed to do nothing, while DoEvents halved the number of trails, but also made the text inside the userform go a bit crazy during execution.
Note: The checkbox is named "MyCheckBox" and the userform is named "ColumnSelect"
Perhaps I'm trying to do too much with excels memory or w/e.. Any help is appreciated though. Thank you!
Private Sub MyCheckBox_Change()
Dim w As Integer
Application.ScreenUpdating = False
If MyCheckBox.Value = True Then
For w = 425 To 838 Step 7
ColumnSelect.Width = ColumnSelect.Width + 7
ColumnSelect.Left = ColumnSelect.Left - 3.5
Next w
Else
'DoEvents
For w = 838 To 425 Step -7
ColumnSelect.Width = ColumnSelect.Width - 7
ColumnSelect.Left = ColumnSelect.Left + 3.5
Next w
End If
Application.ScreenUpdating = True
End Sub
I have tested the file on my home (gaming) of, which is much more powerful than the laptop/monitor setup I used when posing the question. There was no visible trail when resizing the user form, so it seems user A.S.H was correct in his assumption that the issue involved the PC/monitor rather than the code.
If you want credit for the answer I will be happy to give it to you, just submit your own. Otherwise I'll mark this as answerws. Thanks for your help
I'm using netzero hardware to manage the contents of a number of monitors. My present solution creates a form in VB.Net that has a pixel offset corresponding to where I've placed the Monitors in display management in the control panel. Each monitor has a dedicated form, and in each form are various objects.
The annoyance is that each form must be individually created (so far as I know) at design time. I can't make an array of forms, coupled with an array of offsets and assign all the properties through code.
There ought to be a way to do this...it would simplify my coding and project management.
What I see on MSDN is either over my head or not helpful.
I haven't tested this in hardware yet, but it does compile w/o error:
Public Sub makeform()
Dim MonitorForm(21) As Form
Dim MPictureBoxes(21) As PictureBox
Dim a As Integer
For i As Integer = 0 To n 'up to 21
MonitorForm(i) = New Form
MonitorForm(i).Name = "Form" & (i + 1)
MonitorForm(i).Text = "Form" & (i + 1)
MonitorForm(i).Controls.Add(MPictureBoxes(i))
MonitorForm(i).Location= new Point (x(i), y(i))
With MPictureBoxes(i)
.Name = "Picture Box " & Convert.ToString(i)
.Image = Image.FromFile(CurrentPic(i))
.Location = New System.Drawing.Point(0, 0)
.Size = New Size(1920, 1080)
' Note you can set more of the PicBox's Properties here
End With
Next
End Sub
Where I had gone wrong in my attempts at this was trying to do it this way
Dim Monitor(21) as New Form
That doesn't work, and the difference between Dim Monitor(21) as Form followed by monitor(i)= new Form
was simply too subtle for my present understand of classes, namespaces etc.
.
Well, I've had to give up on this approach and go back to creating n forms at design time (which means that they have names of form2...form22, putting each of them at manual start positions in design mode. There just doesn't seem to be a way to do this with an array of forms. So the code I have built around the messiness of forms2...forms22 works just fine, it's just going to be messy to maintain and elaborate on.
The solution to this may lie in system.screen classes, but the documentation on this is too advanced for me and I'm not finding good code examples for anything other than extracting data about how many screens there are - nothing about writing to them.
This is very easy in code. You want to make many instances of the same form. In this case, I have created a form in the designer called frmTest and I create many instances in code called frmNew:
Public Sub Main()
For x = 100 To 400 Step 100
For y = 100 To 700 Step 200
Dim frmNew As New frmTest
frmNew.Show()
frmNew.Top = x
frmNew.Left = y
frmNew.Height = 100
frmNew.Width = 200
Next
Next
End Sub
I have just used two loops to increment x and y values, but you could do this from a database or config file easily enough.
I'm trying to add a little interaction to a PowerPoint presentation I'm working on. I'm written a little VB that will increase the size and position a particular chart object when the script runs. I'm tested the script in design mode and everything seems to work fine. When, however, I link my code to an action button and try to run it from within the slide show the code does not run. I do most of my VB in Excel so I have not run across this before. Can anyone suggest a fix for this. My code is set forth below:
Sub MoveChart23()
Dim s
For Each s In ActiveWindow.Selection.SlideRange.Shapes
If s.Name = "Chart 23" Then
s.Top = 50
s.Width = 620
s.Left = 50
s.Height = 400
End If
Next
End Sub
Thanks for your help.
Anyway, I think your problem is in the following line:
For Each s In ActiveWindow.Selection.SlideRange.Shapes
while you have no Selection in presentation mode. Depending on the way you run and control the whole presentation you should use something like this instead:
For Each s In ActiveWindow.Slides(1).Shapes
But if you need to refer to currently viewed slide you should go this way:
For Each s In SlideShowWindows(1).View.Slide.Shapes
at the moment I have a small application and need to take information from an object and display it into an excel file, using the Microsoft.office.interop class I've been able to write to the file, and it shows one by one the records being added, however about once every 3 times I try it, the spreadsheet stops filling somewhere between the 300th and 600th record, I have 6,000 in total and it's not breaking every time, I put a check after it finishes to see whether the last record is filled in but the code never reaches that point and I'm unsure of what's happening
I also don't know how to debug the problem as it'd mean going through 6,000 loops to check for it stopping... which might not even happen?
a little section of the code is here
loadExcel(incidents, WorkSheetName)
If WorkSheetName.Cells(DBObject.HighestInci + 1, 6) Is Nothing Then
MessageBox.Show("Failed to fill spreadsheet, Retrying now.")
loadExcel(incidents, WorkSheetName)
End If
above is the code calling and checking the method below
Private Sub loadExcel(ByVal incidents As List(Of Incident), ByRef WorkSheetName As Excel.Worksheet)
Dim i = 2
For Each inc As Incident In incidents
WorkSheetName.Cells(i, 1) = inc.DateLogged
WorkSheetName.Cells(i, 2) = inc.DateClosed
WorkSheetName.Cells(i, 3) = Convert.ToString(inc.DateLogged).Substring(3, 2)
i += 1
Next
End Sub
Thanks in advance
EDIT
I'm thinking loading it to a buffer of some sort then writing once they have all been updated would be the way to go instead of it currently loading and writing each separately? however I have no idea where to start for that?
I've fixed my problem, with what I had above Excel was opened and it started printing into the spreadsheet line by line, the problem is that any interactions with excel would cause the process to freeze
By adding an
ExcelApp.visible = false
before carrying out the process and an
ExcelApp.visible = true
afterwards, it all works and then opens the file afterwards