Pete's Windows, Office, VB & SQL Blog

Problems I have solved (or not) and good ideas I've found

Error -2147417848 (&H80010108): The object invoked has disconnected from its clients.

leave a comment »

I have a spreadsheet that is used for data entry.  In the Workbook_Open Sub on the ThisWorkbook sheet I set up some validation.

Dim Con_ws As Worksheet
Set Con_ws = Worksheets(“Contract”)
Dim frDt As Date, toDt As Date

frDt = DateAdd(“m”, -6, Now())
Con_ws.Cells(1, 1).Value = frDt
toDt = DateAdd(“m”, 6, Now())

With Worksheets(“Contract”).Cells(1, 1).Validation
.Delete
.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Format(frDt, “mm/dd/yyyy”), Formula2:=Format(toDt, “mm/dd/yyyy”)
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = “”
.ErrorTitle = “”
.InputMessage = “”
.ErrorMessage = “”
.ShowInput = True
.ShowError = True
End With

and lots more besides.  On SOME workstations the macro fails with the Error -2147417848, entering Debug the .Add Type= line is high lighted.

I have read http://support.microsoft.com/default.aspx?scid=kb;en-us;Q319832 and it doesn’t seem to apply to the code above.

Trying to work out the cause, I re-recorded the macro that adds the validation:

Range(“A1″).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=”12/31/2009″, Formula2:=”12/31/2010″
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = “”
.ErrorTitle = “”
.InputMessage = “”
.ErrorMessage = “”
.ShowInput = True
.ShowError = True
End With

That runs fine on the affected workstation.  If I put that code in before my own, all of it works everywhere.

Why?

I suppose it must be something to do with cell selection but I don’t understand what.

Written by fisherpeter

2010 December 14 at 15:13

A short Evaluation of Scribus 1.3.3.14

leave a comment »

My software of choice for DTP is PagePlus. I’m a little behind, I have version X2. More importantly I’ve been using it for years, mainly for simple fliers.

We have a requirement for DTP at church and someone suggested Scribus. The free version of PagePlus is rather too limited, so I decided to take a look.

This evaluation has not stretched the product. It has though stretched me. The use interface is far from obvious. After inserting a frame, which is easy enough you then have to insert content. So after inserting an image frame, I have to right click and choose ‘Get Image …’ or press Ctrl-D.

After inserting a text frame I have to click the Icon before I can type in the frame. This is fundamentally time wasting, what else am I going to put in a text frame, apart from text.

To resize an image you must use properties on the frame, click the image section and select ‘scale to frame size’. Then when you adjust the frame the image size changes. If you don’t do this the exposed portion of the image changes.

 

I tried to paste an image, but that seems to be impossible. I tried to ‘drag-and-drop’ an image, both onto the page and into a frame. Although windows indicates that it is OK, nothing appears on the page or in the frame.

Some of the text properties seem to work in unison and some don’t, I’m still confused about that.

If we are looking to use this to produce the monthly magazine then there are some more serious limitations. I cannot find a ‘booklet’ option. This is certainly available in PagePlus and has been for years, and I’m pretty sure its in Publisher too. You have to pay for those of course.

In general it is responsive once started and the .PDFs that it produced are well compressed (74K for the first page as opposed to 208k with PagePlus for both pages). Stratup however is slow, a long time is spent creating the font cache.

 

Written by fisherpeter

2010 October 19 at 21:22

Posted in Software Evaluation

Tagged with ,

Scheduled tasks created by schtasks do not run – “could not start”

leave a comment »

The reason for this is quite simple, but once again the information on the web is misleading.  The schtasks parameter concerned is /tr, this tells the scheduler what to run.  The value must be enclosed in quotes inside the schedule job file if the path name contains spaces.  Therefore the string that must be delivered is

“C:\Program Files\Scheduled\Program.exe”  -Param=P

To include the double quote character in the string use \” (not ^”) so the /tr parameter looks like:

/tr “\”C:\Program Files\Scheduled\Program.exe\” -Param=P”

full details from Microsoft here, see the Workaround tab

Written by fisherpeter

2010 September 2 at 20:09

how to get rid of those annoying 3 encoding characters written at the start of a text file

leave a comment »

If your text file looks like

TEXT

or similar the you have generated encoding characters, to generate the file without them use

Dim TextString As String = “TEXT”
My .Computer.FileSystem.WriteAllText(“C:\TEXT.TXT” , TextString, False, System.Text.Encoding.ASCII)

the Default option will encode in ANSI, but still provide the encoding string.

Written by fisherpeter

2010 August 11 at 10:56

The remote device or resource won’t accept the connection

leave a comment »

First IE (8) says it Cannot display the page, then I click Diagnose Network problems and receive the message “The remote device or resource won’t accept the connection”.

I know this to be a lie.  I have the site open in Firefox.  I only got here because my Free Download Manager stopped working.  It gets it’s Internet setting etc. off the back of IE.  IE version 8.0.7600.16385.

This problem ONLY happens on my account, not to any of the other accounts on my system.

First of all I found references to “Fix IT”.  What an odd idea.  Click here to download this executable to copy onto the computer with no network!  (back to CD’s?)

Then I found http://support.microsoft.com/kb/956196. Many of the suggestions can be easily discarded – I know I have network and browser access to the web, I know that it is not system wide, but account specific.

Suggestion 8 work a treat.

This problem is most likely a hangover from a recent attack which I thought I’d defended and tidied up.

Written by fisherpeter

2010 August 6 at 21:40

Posted in Windows 7 (64bit)

Tagged with ,

code execution has been interrupted

leave a comment »

After running my macro like this:

set apExcel = CreateObject(“Excel.Application”)
set wkBook = apExcel.Workbooks.Add (“C:\SpreadSheet.xls”)
apExcel.run “A_Macro”
wkBook.Close
apExcel.Quit

It stopped with the message “code execution has been interrupted” next time I ran it in Excel on my desktop.  I’d not seen this message before.  Clicking ‘Continue’ worked the macro executed that line of code and many more until it got back to that line later, then the message appeared again.  About four lines exhibited the problem, I recognised them as lines I had se breaks on during development.  I have occasionally experienced a problem where breaks don’t actually leave the code, even though the markers do.  So I hit F9 twice – to set and unset the breakpoint – to no effect.  I tried ‘clear all breakpoints’ – to no effect.

I found a solution here, which seems to have worked.   The entry is Oct 13th, 2009, 02:35 PM, by akforsyt.  IT is simple to go into debug and press Ctrl+break.

Written by fisherpeter

2010 July 21 at 09:33

Posted in Office 2003

Tagged with , ,

Breakpoints cannot be set in method or class with the ‘DebuggerStepThrough’ attribute when the debugger option ‘Just My Code’ is Enabled

leave a comment »

If you are trying to get to some system generated code in VB 2008 Express then ignore all comments you find about Tools … Options … Debugger.  It doesn’t exist.  Right clicking and un-ticking ‘Step over properties and operators’ will similarly have no effect.

In the file ‘class-name.Designer.vb’ there is a compiler directive:

<System.Diagnostics.DebuggerStepThrough()>

If this is commented out, then breakpoints can be set.

Why do I need to do this?

Simple.  The form setup includes access to my code.  In my case setting the initial value in a combo-box generates:

Me.cmbDisp.Text = “Activity”
  
Which in turn triggers a cmbDisp.SelectedIndexChanged event, and off to my code it goes (just as it should) BUT this is no longer system generated code, so the compiler should allow debug to occur, it is not clever enough to realise that it has switched from a class in a system generated file, to a class in a user generated file.  The debugger simply fails the program, and provides an inner exception with no code references.

Written by fisherpeter

2010 June 2 at 09:19

Posted in VB Express 2008

Tagged with

Small Icons in the Quick Launch toolbar in Windows/XP

leave a comment »

I like my taskbar on the left rather than at the bottom.  This, it seems, causes the quick launch bar to loose its settings and sometimes disappear.  Theses are the steps I follow to reset the icon size.

  1. Grab the Taskbar and move it to the bottom, the default position.
  2. Right Click on some unused space in the quick launch toolbar
  3. If there is no unused space resize the toolbar.
  4. If the menu displayed does not show ‘view’ at the top, click on ‘Show Title’.  The right click above the title.
  5. Point to the ‘View’ menu,  when it expands, click ‘Small Icons’
  6. Righ Click on the title and click on ‘Show Title’ (to untick it).
  7. Grab the taskbar and move it back to the left.

Written by fisherpeter

2010 May 13 at 08:10

Posted in Windows/XP(sp3)

Tagged with ,

Internal connection fatal error.

leave a comment »

A small upgrade to fix a relatively minor problem and suddenly my SQL call result in “Internal connection fatal error.”.  Google, for once doesn’t give an immediate solution.  Too many people get too technical too quickly.  I examined the program carefully to ensure that the queries and updates are all using the correct connections.  This is a multi-threaded, multi-connection application.  There were minor errors.  I fixed them.  I couldn’t understand why I couldn’t reproduce the errors on my own workstation.  It has to be environmental.

Then I came across this. Thanks to Bob whose comment at the end sent me on the MDAC track.

Microsoft provide a nice utility to check the versions of MDAC. It reveals that I have generated and tested the program in a MDAC 2.81.1132 (from XP Sp3) environment, and am running it in a MDAC 2.81.1117 (from XP SP2) environment.  Never clever!

I set up a test environment with the correct version of MDAC – no change, the problem still occurs.  I examined my trace.  The problem always occurs after two threads have processed and their trace entries are intermingled.  If the dispose of one connection occurs while the connection to the other thread is active – Bang!

Much more careful program searching found that the connection that is failing is established on the secondary thread and passed to the primary via an ‘invoke’.  I’ve not found anything that says I shouldn’t do this, but it was the only one and always the one that failed.

Having now changed the code to ensure that connections are not used across a thread the program is functioning correctly and has been stable for over a week.

Written by fisherpeter

2010 May 1 at 09:28

Multi-threading, delegates & invoke in windows forms

leave a comment »

Multi-threading was not the intended approach to my program, by suddenly after making some changes I received messages that I was on the wrong thread.  I had ‘Imports System.Threading’ in only one module, and all it did was thread.wait(200). That was just to give excel time to recalculate after setting a value before reading it back to check the format.

Perhaps it was the addition of the second timer control.  It was certainly occurring on that thread.

So after much experimentation I ended up with a simplified example from http://msdn.microsoft.com/en-us/library/a1hetckb.aspx

Two things to note:

After the execution of :

 ”myDelegate = New AddListItem(AddressOf AddListItemMethod)”

myDelegate must have both a method and a target.  It does not seem to be able to do this unless it is executed from within the form class.

The command “Me.Invoke(Me.myDelegate, New Object() {myString})” in GenerateStrng must also be within the form Class, even if the addressing is changed to MyFormControl

Here is the code, with some helpful Debug.Prints to help you see whats really happening. (apologies about the colour!)

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Threading

Public Class MyFormControl
    Inherits Form

    Delegate Sub AddListItem(ByVal myString As String)
    Public myDelegate As AddListItem
    Private myButton As Button
    Public myThread As Thread
    Private myListBox As ListBox

    Public Sub New()
        myButton = New Button()
        myListBox = New ListBox()
        myButton.Location = New Point(72, 160)
        myButton.Size = New Size(152, 32)
        myButton.TabIndex = 1
        myButton.Text = “Add items in list box”
        AddHandler myButton.Click, AddressOf Button_Click
        myListBox.Location = New Point(48, 32)
        myListBox.Name = “myListBox”
        myListBox.Size = New Size(200, 95)
        myListBox.TabIndex = 2
        ClientSize = New Size(292, 273)
        Controls.AddRange(New Control() {myListBox, myButton})
        Text = ” ‘Control_Invoke’ example “
        myDelegate = New AddListItem(AddressOf AddListItemMethod)
        Dim tid As Integer = Thread.CurrentThread.ManagedThreadId
        Debug.Print(“New tid:” & tid.ToString)
        AddListItemMethod(“New ” & tid.tostring)
    End Sub ‘New

    Shared Sub Main()
        Dim myForm As New MyFormControl()
        myForm.ShowDialog()
    End Sub ‘Main

    Public Sub AddListItemMethod(ByVal myString As String)
        Dim tid As Integer = Thread.CurrentThread.ManagedThreadId
        Debug.Print(“AddListItemMethod tid:” & tid.ToString)
        myListBox.Items.Add(myString)
    End Sub ‘AddListItemMethod

    Private Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
        myThread = New Thread(New ThreadStart(AddressOf GenerateStrng))
        myThread.Start()
    End Sub ‘Button_Click

    Public Sub GenerateStrng()

        Dim i As Integer
        Dim tid As Integer = Thread.CurrentThread.ManagedThreadId
        Debug.Print(“ThreadClass.Run tid:” & tid.ToString)
        For i = 1 To 5
            Dim myString As String = “Step ” + i.ToString() + ” executed from ” & tid.ToString
            ‘ Execute the specified delegate on the thread that owns
            ‘ ‘myFormControl1′ control’s underlying window handle with
            ‘ the specified list of arguments.

            Me.Invoke(Me.myDelegate, New Object() {myString})
            Thread.Sleep(800)

        Next i

    End Sub ‘Run

    Private Sub MyFormControl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub InitializeComponent()
        Me.SuspendLayout()
        ‘
        ‘MyFormControl
        ‘
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Name = “MyFormControl”
        Me.ResumeLayout(False)

    End Sub
End Class ‘MyThreadClass

Written by fisherpeter

2010 March 27 at 12:28

Posted in VB Express 2008

Tagged with

Follow

Get every new post delivered to your Inbox.