TnTinMN 418 Practically a Master Poster

Perhaps something like this will work for you.

Public Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      With ListView1
         .Alignment = ListViewAlignment.SnapToGrid
         .AllowDrop = True
         .AutoArrange = False
         .Scrollable = False
         .View = View.LargeIcon
      End With
   End Sub

   Private Sub ListView1_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles ListView1.ItemDrag
      Dim lvi As ListViewItem = CType(e.Item, ListViewItem)
      ListView1.DoDragDrop(New DataObject("System.Windows.Forms.ListViewItem", lvi), DragDropEffects.Move)
   End Sub

   Private Sub ListView1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter
      If e.Data.GetDataPresent("System.Windows.Forms.ListViewItem") Then
         e.Effect = DragDropEffects.Move
      End If
   End Sub

   Private Sub ListView1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragOver
      Dim lvi As ListViewItem = CType(e.Data.GetData("System.Windows.Forms.ListViewItem"), ListViewItem)
      Dim Offset As Size = Size.Subtract(Cursor.Size, New Size(Cursor.HotSpot.X, Cursor.HotSpot.Y))
      lvi.Position = Point.Subtract(ListView1.PointToClient(New Point(e.X, e.Y)), Offset)
      e.Effect = DragDropEffects.Move
   End Sub

End Class
TnTinMN 418 Practically a Master Poster

Your main problem is that the checkbox is not very amenable to using an image to indicate the checked state. You are trying to paint over the box and that is always going to look strange.

Here is a custom control that I hammered out quickly based on a Button. It left aligns the button image and uses the ImageList property to contain a Checked and UnChecked Image. There are three added properties: CheckedImage, UnCheckedImage and ImageSize that control the images. If you don't like the looks, you can easy overide the style properties.

The code style my seem a bit strange as I originally did it in VB and converted to C#.

public class ImageCheckBox : Button
{
    private Image _CheckedImage = new Bitmap(24, 24);
    private Image _UnCheckedImage = new Bitmap(24, 24);
    public ImageCheckBox()
    {
        _Checked = false;
        this.ImageAlign = ContentAlignment.MiddleLeft;
        base.ImageList = new ImageList();
        this.FlatAppearance.BorderSize = 0;
        this.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
        Checked = false;
    }

    private void SetImages()
    {
        base.ImageList.Images.Clear();
        base.ImageList.Images.Add(_UnCheckedImage);
        base.ImageList.Images.Add(_CheckedImage);
        Invalidate();
    }

    private bool _Checked;
    public bool Checked
    {
        get { return _Checked; }
        set
        {
            _Checked = value;
            if (_Checked)
            {
                ImageIndex = 1;
            }
            else
            {
                ImageIndex = 0;
            }
        }
    }

    private Size _ImageSize = new Size(24,24);
    public Size ImageSize
    {
        get { return _ImageSize; }
        set
        {
            _ImageSize = value;
            this.ImageList.ImageSize = value;
            SetImages();
        }
    }

    public Image CheckedImage
    {
        get { return _CheckedImage; }
        set
        {
            _CheckedImage.Dispose();
            _CheckedImage = value;
            SetImages();
        }
    }


    public Image UnCheckedImage
    {
        get { return _UnCheckedImage; …
TnTinMN 418 Practically a Master Poster

vbBack is string value

try Asc(vbBack)

TnTinMN 418 Practically a Master Poster

but one more question how can i make it something like 30,000,000 not like 29,482,410?

Change the rounding factor: Const Factor As Double = 5
If you want to round to the nearest 10,000,000, use that as the factor.

Also if your range always starts at zero, just set the Y axis minimum to zero as there is no need to compute a minimum value.

Please take the time to try and understand how to code works instead of just inserting it.

TnTinMN 418 Practically a Master Poster

Probably due to me giving an example that I did not check properly. :(

ymax should be using FindMaxByMalue not FindMinByValue.

 Dim ymax As Double = Math.Max(.Series(0).Points.FindMaxByValue("Y1").YValues(0), _
                               .Series(1).Points.FindMaxByValue("Y1").YValues(0))
TnTinMN 418 Practically a Master Poster

the secondary axis i want it to be fixed in the line of the primary axis in the left side

Assuming that this means that you want both axes to have the same range, then something like this will work.

  With Chart1
     ' Y1 = first Y Point, Y2 = Second Y point, etc.
     Dim ymin As Double = Math.Min(.Series(0).Points.FindMinByValue("Y1").YValues(0), _
                                   .Series(1).Points.FindMinByValue("Y1").YValues(0))

     Dim ymax As Double = Math.Max(.Series(0).Points.FindMinByValue("Y1").YValues(0), _
                                   .Series(1).Points.FindMinByValue("Y1").YValues(0))

     'round values to the nearest "Factor"
     Const Factor As Double = 5

     ymin = Math.Floor(ymin / Factor) * Factor
     ymax = Math.Ceiling(ymax / Factor) * Factor

     .ChartAreas(0).AxisY.Minimum = ymin
     .ChartAreas(0).AxisY.Maximum = ymax
     .ChartAreas(0).AxisY2.Minimum = ymin
     .ChartAreas(0).AxisY2.Maximum = ymax

  End With
Begginnerdev commented: I'm confuse. (DERP) +8
TnTinMN 418 Practically a Master Poster

arr is a binary data file stored in a database

Assuming that this means that "arr" is a byte array that has been loaded from a database, then

change: Photograph1.Image = Photograph1.Image.FromStream(New IO.MemoryStream(arr))

to: Photograph1.Image = Image.FromStream(New IO.MemoryStream(arr))

FromStream is a shared method on the Image class. The IDE does not like you accessing a shared method/field/property on an instance eventhough as it works as you have found out. In this case, the instance is the Image property on Photograph (assuming Photograph is a PictureBox).

TnTinMN 418 Practically a Master Poster

Ok, you said that you installed the 64-bit Access Engine. Now you say that your application works using the Jet provider that is strictly a 32-bit driver. This implies that your application is 32-bit and is likely the reason that it could not find a suitable ISAM.

TnTinMN 418 Practically a Master Poster

You may find looking at the Data Connection Dialog code instructive.

Release of Data Connection Dialog Source Code

TnTinMN 418 Practically a Master Poster

April,

Look at your button handler. You are creating anAccount each time. Move the declaration of anAccount to the class level.

Also, rethink your logic. Would it not be better to call Deposit with an amount to deposit?

TnTinMN 418 Practically a Master Poster

Try something like this:

Public Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Dim sorter As New lvMonthSorter
      sorter.MonthColumn = 0 ' set the column that holds the month
      sorter.Order = SortOrder.Ascending
      ListView1.ListViewItemSorter = sorter
   End Sub

End Class


Public Class lvMonthSorter

   Implements System.Collections.IComparer
   ' array to get a month index from for sorting
   Private Shared Months() As String = {"january", "february", "march", "april", "may", "june", _
                           "july", "august", "september", "october", "november", "december"}

   Private _MonthColumn As Int32 = 0
      Public Property MonthColumn() As Int32
      Set(ByVal Value As Int32)
         _MonthColumn = Value
      End Set

      Get
         Return _MonthColumn
      End Get
   End Property

   Private _Order As SortOrder = SortOrder.Ascending
   Public Property Order() As SortOrder
      Set(ByVal Value As SortOrder)
         _Order = Value
      End Set
      Get
         Return _Order
      End Get
   End Property

   Public Function Compare(ByVal x As Object, ByVal y As Object) As Int32 Implements IComparer.Compare
      Dim result As Int32

      Dim xstr As String = CType(x, ListViewItem).SubItems(_MonthColumn).Text.ToLower
      Dim ystr As String = CType(y, ListViewItem).SubItems(_MonthColumn).Text.ToLower

      Dim xpos As Int32 = Array.FindIndex(Of String)(Months, Function(xs As String) xs = xstr)
      Dim ypos As Int32 = Array.FindIndex(Of String)(Months, Function(ys As String) ys = ystr)

      result = xpos.CompareTo(ypos)

      Select Case Order
         Case SortOrder.Ascending : Return result
         Case SortOrder.Descending : Return -result
         Case Else : Return 0
      End Select
   End Function

End Class
ImZick commented: This work for me. +2
TnTinMN 418 Practically a Master Poster

I do not know if this is required, but you are missing the termininating ";"

"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\20130305.xlsx; Extended Properties=Excel 14.0;HDR=YES;"

You mention x64, did you install the x64 version of Microsoft Access Database Engine 2010 Redistributable ?

TnTinMN 418 Practically a Master Poster

@Andre,

The NZ function allows for substituting a Value for a Null. Something like this:

IIf(Nz([AnotherFieldName],0)=0,3,[AnotherFieldName])

is analogous to:

If [AnotherFieldName] is Null Then
   [AnotherFiledName] =0
End If

If  [AnotherFieldName]  = 0 Then
    Return 3
Else
    Return [AnotherFieldName]
End If

OP:

The expression should be processed by the database engine as it is stored in Access, so I do not believe it should be any different than running any other selection query. Say the Access Query is named Q1, the the SQL query should be something like: "Select * From Q1"

TnTinMN 418 Practically a Master Poster

Great. Please close out this thread then by marking it answered.

TnTinMN 418 Practically a Master Poster

It's like 60 something over there meaning every where in Cali.

be careful with generalizations.

TnTinMN 418 Practically a Master Poster

The only automatic substitution that I am aware of being allowed in a connection string is the "|DataDirectory|".

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database1.accdb

The default definition for DataDirectory is the application directory, but this can be redefined like this:

AppDomain.CurrentDomain.SetData("DataDirectory", Environment.GetFolderPath(Environment.SpecialFolder.Personal));

The obvious caveat is to redefine it before trying to use the connection string to access the data.

TnTinMN 418 Practically a Master Poster

Is this what you mean?

MsgBox "Found here - Cabinet: " & Range("E" & Rng.Row).Value _
       & " Drawer: " & Range("F" & Rng.Row).Value
TnTinMN 418 Practically a Master Poster

Based on the fact that you currently have this working, It appears that the returned recordset for the first entered character is not to large to fit into the available memory.

The question is why are you querying the database for subsequently entered characters?

Load a datatable based on the first entered character and then use that table as the datasource for the listbox. On subsequent character entry, adjust the table's defaultview row filter.

Something like this:

   Private lbxSource As New DataTable
   Private LastLoadCharacter As Char = Nothing

   Private Sub tbSearchCriteria_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbSearchCriteria.TextChanged

      Dim txtlen As Int32 = tbSearchCriteria.Text.Length
      If txtlen = 0 Then
         ListBox1.DataSource = Nothing
      Else
         If txtlen = 1 Then

            If LastLoadCharacter <> tbSearchCriteria.Text(0) Then
               LastLoadCharacter = tbSearchCriteria.Text(0)
               ' query database and load the table lbxSource with the results
            End If
            lbxSource.DefaultView.RowFilter = ""
            ListBox1.DataSource = lbxSource

         Else
            lbxSource.DefaultView.RowFilter = "[SearchField] Like '" & tbSearchCriteria.Text & "*'"
         End If
      End If

   End Sub
TnTinMN 418 Practically a Master Poster

MsgBox "Found here " & Rng

Rng is an object. If you wnat the address use Rng.Address.
But move to be inside your if block just in case that Rng is Nothing.

TnTinMN 418 Practically a Master Poster

Chris,

I do not know if this is applicable to your situation, but this technique sort of works for RDLC reports.

  • Set the height of the table to zero. It will not let it be exactly zero, but will set it to some small value.
  • Add a rectangle (no border) to the report and place the table in it. Then set the height of the rectangle to zero; again will not be exactly zero, but close.
  • Toggle the table visibility as you have been doing in an expression.

You the following example, I have set it to page break before the rectangle.

layout
p11
p2
second page with table invisible
p2b

TnTinMN 418 Practically a Master Poster

For future reference: SQL Server Data Type Mappings

TnTinMN 418 Practically a Master Poster

Is this above routine something I can put in and test? f so, what controls do I need to add to "form1" to use it? I'm asking this as I'm a "learn by doing" person.

Of course play with it! I didn't code any teeth into it, it does not bite. (Note to self: learn how to code in teeth).

You can use that anywhere you want to to save control text. It does not have any requirements other than using as shown in the example. It would probably be a good idea to put it in it's own code file. Just go to the Project Menu - Add New Class and replace the default class code created.

It really should have more robust error checking and recovery code, but you can always add that later. The good thing about it is you will only have to modify this one class as opposed to modifying replicated logic in multiple forms.

Please close out this thread. It's long enough.

TnTinMN 418 Practically a Master Poster

Sometimes this happens when the solution files get corrupted. Delete the "projectname.snl" and "projectname.sou" files and then using VB open the project definition file "projectname.vbproj".

TnTinMN 418 Practically a Master Poster

Sorry forgot C#,

object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
object missing =  System.Reflection.Missing.Value;
doc.Close(ref doNotSaveChanges, ref missing, ref missing);
ddanbe commented: top +14
TnTinMN 418 Practically a Master Poster

Pass "false" in the Close method;

wordDoc.Close(false);

TnTinMN 418 Practically a Master Poster

It would help if your showed the code that you are using.

At this point I can only guess that the method you are using calls Image.FromFile followed by Image.GetThumbnailImage and is not properly releasing the GDI resources.

If this is the case, take a look at this: Load Image From File and Release File

TnTinMN 418 Practically a Master Poster

Don,

I had seen your prior post and decided to add some comments to the example that I had previouly provided. For once I refreshed my browser before posting it and seen that you have got it working. Good job!

Since you seen to be having problems with terminology (wat! you no speekee mi lingo!), I am going to post it anyways so that it may help you understand some of the jibberish. :)

Public Class Form1

   ' the following statement creates an instance of the class ControlTextSaver
   ' the constructor for the class (the "New" subroutine) expects a string that
   ' is the path to a file that will store the Text property for the specified controls
   Private controlTextManager As New ControlTextSaver("savedtb.txt")

   ' Form_Load is an event handler that runs after an instance of the form is created.
   ' the default configuration of VB.Net automatically creates the form instance for you.
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

      ' the following for-next loop is an attempt to show you that you could add the controls to the 
      ' text manager in a loop, eventhough I do not agree with this methodology

      For i = 1 To 3 ' I an only using 3 texboxes for this example
         ' assuming that all the textboxes are parented to a panel
         ' the control manager exposes a List(of Controls) property
         ' since the is just like any other List(of type) instance, 
         ' you can add, insert, …
TnTinMN 418 Practically a Master Poster

Don,

I realized that I did not address the questions you raised in the following text.

...it is within a Panel that I'm using because it needs a vertical scroll bar. This suggests that I may need some other code for it to recognize the TextBox within the panel that IS on the form!! What tangled webs I weave!

Controls can parent other controls. You can make a control a child be another by adding it to the target parent control's Controls collection or by setting the Parent property of the child control.

parent.Controls.Add(child)

or

child.Parent = parent

If all the textboxes are parented to the panel, then you could change Me.Controls to Panel1.Controls (replace Panel1 with the true name of the panel) and your logic would function. "Me" is an internal reference to the class in which you are writing code; in this case the form you are defining. The reason you are able to type the name of the textbox reference and it is recognized by the IDE is because you have defined in the class even if you are not aware that you have done so.

When you drag a control to the design, visual studio executes a design routine for that control that generates the statements necessary to instaniate it and set its properties. This code is then written to the form's designer file. You can view this file by going to the solution explorer window and clicking on the …

TnTinMN 418 Practically a Master Poster

Don,

You are beginning to see the issues that I tried to cautioned you about in this post.

http://www.daniweb.com/software-development/vbnet/threads/449051/saving-multiple-strings-to-a-single-.txt-file-in-top-to-bottom-order#post1941747

Consider the time that you have wasted already just to trying and save some time typing in names of the controls that you wish to save the text from by using a loop to generate the control's name. Is it really worth it?

The class shown in that post will manage the saving and restoring of the Text property. All you need to do is create an instance of it and tell it which controls to manage and then issue it the commands for saving and loading the text at the proper point in your code.

TnTinMN 418 Practically a Master Poster

"A first chance exception of type 'System.NullReferenceException'

Don,

Most likely you have misnamed one of the Textboxes or it is not parented to the form.

Try adding the if-block shown below.

Me.Controls("something") will return either a control named "something" or Nothing (null) if the requested control does not exist in the collection.

Dim txtTmp As TextBox
Using reader As StreamReader = New StreamReader("c:\BusinessBasics\miscspareflds.txt")
    For intIndex As Integer = 1 To 36

        txtTmp = Me.Controls("txbUserFld" & intIndex)
        ' put in this 
        if txtTmp Is Nothing Then 
          msgbox("txtUserFld" & intIndex.ToString() & " not found on " & me.name)
          stop
        end if
        strLine = reader.ReadLine
        txtTmp.Text = strLine

    Next
End Using

If you are running in debug mode, this will stop execution. Do not leave the code in for the final version.

TnTinMN 418 Practically a Master Poster

Granted, but I doubt that you will enjoy the purgative effect necessary to achieve that.

Do you really believe that to have managed govermental service that you need a bunch self serving politicians?

TnTinMN 418 Practically a Master Poster

Granted, but the in the horror caused by realizing your previous wish to be an old fart, you have just wished to be an older one who while playing an online game had his computer hacked, his identity stolen, all his financial assets stolen so the power company has turned off the electricty due to lack of payment thereby preventing you from playing the game. (that's one of the worst sentences I have ever typed. I'm proud of it!! :)))

I wish all politicians ceased to exist.

TnTinMN 418 Practically a Master Poster

... "old" BASIC language with Visual Basic. It's clear there is little similarity.

You have made a very important realization with that one. VB.Net is one of several laguages in the .Net family. Each has it's own pro's and con's. VB tends to be a bit verbose for some, but it is for this reason that I like it. I find it much easier to read than say C#.

The important thing to remember is that while a language may offer certain constructs unique to the that language, you will always have access to the base fucntionality defined in .Net.

Converting an object to a string representation is a good example of this. In .Net every object will have a ToString function defined for it even if it has to work its way up the inheritance tree to find the default ToString defined on the Object Class. Pretty much every Type in .Net derives ultimately from the Object Class.

In VB.Net all of these will produce the string "3"

   Dim s As String
   s = "3"
   s = "3".ToString() ' let's be redundant
   s = 3.ToString()
   Dim i As Int32 = 3
   s = CStr(i) ' a VB function
   s = CType(i, String) ' a VB function
   s = New System.ComponentModel.StringConverter().ConvertToString(i) ' a .Net class
   s = Microsoft.VisualBasic.ChrW(51) ' convert the ASCII value to a character

Here are some links regarding data types and type conversion.

Data Type Summary
http://msdn.microsoft.com/en-us/library/vstudio/47zceaw7%28v=vs.90%29.aspx

Type Conversion …

TnTinMN 418 Practically a Master Poster

Don,

What parts do you not understand?

From my perspective the only thing that I see that may be confusing is the save method. In retrospect, I should not have written it that way for someone who at your level of understanding.

The fancy word for the original method that I employed is LINQ (Language Integrated Query). I tend to through these into examples just to see if people are paying attention and ask questions or if they are cut & paste programmers. I tend not to offer future help to that type of person.

Dim output() As String = (From cntrl In savedControl Select CType(cntrl, Control).Text).Cast(Of String)().ToArray()

does the same thing as:

Dim output(0 To savedControl.Count -1) As String 
For i as Int32 = 0 to savedControl.Count -1
    output(i) = savedControl.Item(i).Text
Next i

It is a somewhat of a programming short cut, but can be a pain to debug if done wrong.

If you are having problems with or just need a refresher on the fundumental stuff, this is a good online tutorial.

http://www.homeandlearn.co.uk/net/vbnet.html

The entire jist of the class "ControlTextSaver" is that it is a generic and re-usable block of code for saving and retrieving the text for a list of controls.

All the controls (button, textbox, label) that you use in a WinForm project are derived from a common ancestor class named "Control", hence the word controls. This follows an inheritance pattern. If you look at the documentation for say the …

TnTinMN 418 Practically a Master Poster

I'll answer and ask all at the same time: Are you sure that it is worth the effort?

Sorry, no offense intended, I just could not resist being a Smart aleck. Besides, I had to beat Michael to the punch line.

TnTinMN 418 Practically a Master Poster

Don,

This type of coding is seductive at first glance, but can be a major PITA to maintain.

Say if at some point you decide that you need to use a RichTextBox (or some other control for that matter) for one of the fields so that you can take advantage of it formating capabilities. You are then forced to rewrite all of the save and load logic to accomodate that one simple change.

Additionally, this technique limits you to having all of the textboxes parented to the same control.

You can achieve the much of the perceived reduced coding effort by simply storing a reference to the control in an array or list of controls and then process that list. Granted you will have to load the list, but you can still use the method that Jim has shown you. However, if you ever need to make any changes, you will only need to modify that loading routine and not all of the others.

You may have noted that I purposely used the word "control" above instead of textbox. There is a good reason for this; it is flexibilty. There is no reason to limit yourself to just textboxes. The TextBox.Text property is inherited from the Control class.

Here is a simple example of the technique. I have only put in very limited error checking.

Public Class Form1

   Private controlTextManager As New ControlTextSaver("savedtb.txt")

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      For i = 1 …
TnTinMN 418 Practically a Master Poster

Just to let you know, I am also pretty much self taught in programming and hold two engineering degrees. In fact, it was my distain for doing mundane computations that provided the impetus to become more proficient at programming.

It takes time to to develop skills whether they be in programming or anything else. Since you are still a student in engineering, you should be presented with plenty of well defined and tedious computational tasks that could be made easier with some type of computer program. Even if you don't end up being a full-time coder, having the skill will be only to your benefit. Keep your options open.

I would recommend that you use your elective classes wisely to strengthen skills that will be valuable to you as both an engineer or programmer. i.e. advanced mathemetics.

I am somewhat concerned that you have expressed doubt about your ability to tackle developing a large complex program. As an engineering student, you should realize that a well designed large complex system is built of many smaller components.

However, if you are in the midst of the weed-out class, I can understand that confidence may be shaken a bit at this point. Stick it out it will get better.

You may want to talk to your adviser and some other of your professors about your love for programming. You may even be able to pick-up some work develop applications for them.

It's hard to give more relevant advice, without knowing more about …

TnTinMN 418 Practically a Master Poster

I don't know.

But if you did, would they eat the nasty bugs like they do in my garden?

TnTinMN 418 Practically a Master Poster

It doesn't, it's the burps afterwards that do.

I'll ask again: Are we there yet?!!!!

TnTinMN 418 Practically a Master Poster

Chris,

When you write "the pages alignment of the tables is off" do you mean the physical positioning on a given page or do you mean that they are not appearing on the Excel tab that you expect?

If it is a physical positioning problem (the table is not at the top of the page) then it may be due to the hidden table having it's PageBreakAtEnd property being set. It may work to change all tables to PageBreakAtStart.

I am assuming that the report you are running is similar to those used in the ReportViewer as the Reportviewrr is based on SSRS. This may not be the case though.

TnTinMN 418 Practically a Master Poster

what this code really do?!
there isn't any performclick() method in c#

It does what I I interpreted your question to be. It locates a button control at a give location and if it is a button, it executes the Button.PerformClick method of the button. I assumed that you are working on a WinForm project.

TnTinMN 418 Practically a Master Poster

when i enter a position in my form in a text field then the button that is in the same position get activated

        private PointConverter pc = new PointConverter();
        private void button2_Click(object sender, EventArgs e)
        {
            Point pt ;
            Button b = null;
            try
            {
                if(!String.IsNullOrEmpty(textBox1.Text))
                {
                    pt = (Point) pc.ConvertFromString(textBox1.Text);
                    Control c = this.GetChildAtPoint(pt);

                    if (c != null && c is Button)
                    {
                        b = (Button)c;
                    }
                }


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            if (b != null)
            {
                // not sure if you mean focus the button
                b.Focus();
                // or click it
                b.PerformClick();
            }
        }
TnTinMN 418 Practically a Master Poster

Well I, thought that what I left you to figure out was not a trival as I thought. The darn thing looses the row reference when adding a formated paragraph for you Title. It took a bit of experimenting, but I think if you follow the pattern shown below it should work for you. At least the test case worked.

Imports Microsoft.Office.Interop

Public Class Form1
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      PlayWithWord()
   End Sub

   Private Sub PlayWithWord()
      Dim app As New Word.Application
      app.Visible = True

      Dim doc As Word.Document = app.Documents.Add 'app.Documents.Open("D:\My Documents\Splittable.docx")
      Dim view As Word.View = app.ActiveWindow.View
      With view.Zoom
        .PageColumns = 2
        .PageRows = 1
      End With
      view = Nothing
      Dim table As Word.Table

      doc.Bookmarks.Item("\endofdoc").Select()
      app.Selection.Text = "Flintstones. Meet the Flintstones. They're the modern stone age family.  From the town of Bedrock, They're a page right out of history."

      doc.Bookmarks.Item("\endofdoc").Select()
      table = doc.Tables.Add(app.Selection.Range, 70, 1)
      Stop
      Dim Title As String = "Top of Page Title"

      SplitTable(table, Title)

      Stop

      doc.Bookmarks.Item("\endofdoc").Select()
      app.Selection.Text = "fred was here" & vbNewLine
      Stop

      doc.Bookmarks.Item("\endofdoc").Select()
      app.Selection.Range.Select()
      Stop

      table = doc.Tables.Add(app.Selection.Range, 50, 1)
      Stop
      SplitTable(table, Title)
      Stop

      doc.Bookmarks.Item("\endofdoc").Select()
      app.Selection.Text = "end of doc"

      Stop

      doc.Close(False)
      doc = Nothing
      app.Quit()
      app = Nothing
      GC.Collect()
   End Sub

   Sub SplitTable(ByVal t As Word.Table, ByVal Title As String)
       Dim r As Word.Row
       Dim CurPage As Integer
       Dim LastPage As Integer
       Const wdCharacter As Int32 = 1

       t.Rows(1).Select() ' remember that office indices start at 1 not 0

       Dim myapp As Word.Application = t.Tables.Application …
TnTinMN 418 Practically a Master Poster

Running a for loop on the tables will not work as by splitting then, you are adding to the collection.

In your report generation code, as soon as you are finished populating a table, pass its reference to the split routine. This assumes you are following a start to end generation pattern.

TnTinMN 418 Practically a Master Poster

It sounds like you want a way to enumerate through the files in a directory.

Directory.EnumerateFiles

TnTinMN 418 Practically a Master Poster

Rats! I forgot to tell you how to get the active Selection. Oh well, see if this makes any sense to you.

Imports Microsoft.Office.Interop

Public Class Form1
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      PlayWithWord()
   End Sub

   Private Sub PlayWithWord()
      Dim app As New Word.Application
      app.Visible = True
      Dim doc As Word.Document = app.Documents.Open("D:\My Documents\Splittable.docx")
      ' remember that office indices start at 1 not 0
      SplitTable(doc.Tables(1)) 'Split the first table up if it needs splitting
      doc.Close(False)
      doc = Nothing
      app.Quit()
      app = Nothing
      GC.Collect()
   End Sub

   Sub SplitTable(ByVal t As Word.Table)
       Dim r As Word.Row
       Dim CurPage As Integer
       Dim LastPage As Integer
       t.Rows(1).Select() ' remember that office indices start at 1 not 0

       Dim myapp As Word.Application = t.Tables.Application
       LastPage = CInt(myapp.Selection.Information(Word.WdInformation.wdActiveEndPageNumber))

       For Each r In t.Rows
          r.Select() ' Selected it so its the activerange
          CurPage = CInt(myapp.Selection.Information(Word.WdInformation.wdActiveEndPageNumber))
          If CurPage <> LastPage Then
             t.Split(r.Index)
             r.Select() ' Selected it so its the activerange
             Dim NewTable As Word.Table
             NewTable = myapp.Selection.Tables(1)
             Call SplitTable(NewTable)
             Exit For
          End If
       Next r
    End Sub

End Class
TnTinMN 418 Practically a Master Poster

It should be easy to convert. Just delete the "Set" keywords and adust some namespace references.

I just did not feel like setting up a VB project to test it. I develop this stuff in VBA first because it gives instant results and is easy to prototype and I have yet to find anything that does not easily convert to .Net interop. Although, it can sometimes be a challenge to find what namespace VBA constants are hidden under on the .Net side.

If you have any problems, just ask.

TnTinMN 418 Practically a Master Poster

I'm running out of ideas here. The only thing that I can think of that may still be an issue is that you are accessing My.Settings.plasmaExport in DoWork. This is something that frankly I have never found a good answer to, so I tend to error on the safe side and pass anything that is created on the UI thread using the parameter object. If you need to pass more one item you can create a class or pass an Object array depending on your needs. It appears that you only need the one item so it is simple.

bgWorkerWMVExport.RunWorkerAsync(My.Settings.plasmaExport)

then in DoWork

Dim plasmaExport as String = Ctype(e.Argument, String) ' I assumed string here
.
.
.
e.Result = plasmaExport

I doubt that this is the issue, but its worth a try.

The only other thing that comes to mind, is that sometimes VS gets messed up and a restart is needed. And when all else fails try a reboot.

Good luck with this. I'm calling it night. Maybe someone else has an idea.

TnTinMN 418 Practically a Master Poster

I don't scare easy. Get peeved at lazy fools yes.

But you do not fit that category and are making an effort yourself by eliminating the obvious.

I have not yet asked, but how have you determined that the completed event is not being called.

Did you determine it by debug messages or missing results.

By messages I mean adding:

Debug.WriteLine("leaving Dowork")
Debug.WriteLine("Entering Completed")

These show up in the Immediate Window (cntrl-Alt-I).

TnTinMN 418 Practically a Master Poster

Foul. Two stupid questions.
Answer to the First: I'm bored and don't feel like working on my project.
For the answer to the second I will borrow from an old comercial for a candy: The world may never know.

Now for the stupid question, what is the candy from the commercial am I referring too?