TnTinMN 418 Practically a Master Poster

There is nothing apparent in your code that should be causing this problem. I'm suspecting that you may have a corrupt .Net module. Can you make try running your executable on a different machine?

One last grasp at a straw, in the IDE, go to the menu Debug->Exceptions and enable breaking on thrown for all exceptions and then see what happens.

TnTinMN 418 Practically a Master Poster

that's what I get from free handing it; complaints about 2 transposed leters that you then turn into a whole different method. :-/

If dp.YValues(0) > DateTime.FromOADate(Chart1.ChartAreas("Fred").AxisY.Minimum).Add(New TimeSpan(0, 3, 0)).ToOADate Then

TnTinMN 418 Practically a Master Poster

Perhaps a quick refresher read will help you gel your thought process. It has pretty pictures (I like pictures). :)

http://www.c-sharpcorner.com/UploadFile/eecabral/OOPSand.NET211102005075520AM/OOPSand.NET2.aspx

TnTinMN 418 Practically a Master Poster

Perhaps I'm not understanding your design properly, but I thimk you are making way to difficult.

You have 7 types of pieces that are represented by an image.

You make a 6 x 12 grid out comprised of multiple copies of the original 7 pieces.

Why not make a Piece Class that includes: Image, Piece Type, and Coordinates?

This is simple enough to manage. No need for image comparisons as piece stores it's identity.

But then I'm probably simplifying this to much.

TnTinMN 418 Practically a Master Poster

The DataPoints primarily Type Double or something that can be converted to double. Think it logically, it needs plots floating pont values.

In this application, the Y-Axis values are AODate values that in turn are Type Double. The YAxis.Minimum value is your relative zero point. To get a TimeSpan value 3 minutes greater than that:

if dp.YValues(0) > DataTime.FromOADate(Chart1.ChartArea(0).AxisY.Minimum).Add(New TimeSpan(0,3,0)).ToAODate then
TnTinMN 418 Practically a Master Poster

For the memory issue try something like this before assigning the PB.Image

if (PB.Image != null) PB.Image.Dispose();

TnTinMN 418 Practically a Master Poster
TnTinMN 418 Practically a Master Poster

I am posting this in response to those who ask about replacing the webbrowser (WB) control’s default browser. You cannot ask the WB control to use a different browser, it is hardwired to use the current version of Microsoft’s Internet Explorer that is installed on the target computer.

It may appear that the WB control is using an older version than is installed; this is not the case. Microsoft in their infinite wisdom made the decision to make IE 7 the default-rendering mode for all applications that use the WB control. This can be observed by visiting this website:

http://detectmybrowser.com

This can be overridden by adding the application name to the registry key:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION

Doing this can be a royal pain in the butt. Especially when developing a program as you would need to make one entry for “ApplicationName.exe” and one for “ApplicationName.vshost.exe” (for debugging under VS).

This code adds and deletes the registry entry on the fly for you. Just add it to your project. That is all that needs to be done. It automatically makes the registry changes for you.

Disclaimer: This code makes changes to the registry on Windows based systems. This is an inherently dangerous operation. The author assumes no responsibity for issues related to your use of this code. Use at your own risk.

john.knapp commented: bookmarked! +3
TnTinMN 418 Practically a Master Poster

I'm getting old and sloppy in my coding; it is a datatype precision mistake.

change
Dim targetY As Single = CSng(area.AxisY.Minimum + ((targetTS.Ticks / deltaTSticks) * (area.AxisY.Maximum - area.AxisY.Minimum)))

to

Dim targetY As Double = (area.AxisY.Minimum + ((targetTS.Ticks / deltaTSticks) * (area.AxisY.Maximum - area.AxisY.Minimum)))

TnTinMN 418 Practically a Master Poster

What is the error message?
Linq is not the fastest in the world. How many data points do you have (approximately)?

For drawing the line, you need to scale the position to the axis as the labels are not the axis values. We had to fake it into using the timespan values with the custom labels.

     Private Sub Chart1_PostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs) Handles Chart1.PostPaint
          If TypeOf e.ChartElement Is ChartArea Then

              Dim area As ChartArea = CType(e.ChartElement, ChartArea)

              Dim x1 As Single = CSng(area.AxisX.ValueToPixelPosition(area.AxisX.Minimum))
              Dim x2 As Single = CSng(area.AxisX.ValueToPixelPosition(area.AxisX.Maximum))

              ' need to scale the targetY value to the y-Axis values

              Dim targetTS As New TimeSpan(0, 3, 0) 'your 00:03:00

              ' when we originally setup the Y-Axis we used OADates to create a numeric value
              ' now convert these back to .Net datetime and get the range in Ticks
              Dim deltaTSticks As Int64 = DateTime.FromOADate(area.AxisY.Maximum).Ticks - DateTime.FromOADate(area.AxisY.Minimum).Ticks

              ' It is a linear scale:  y = y(0) + slope * X
              ' where X is targetTS.tick
              '       slope = (area.AxisY.Maximum - area.AxisY.Minimum) / deltaTsticks
              '       y(0) = area.AxisY.Minimum 
              '       y = targetY
              Dim targetY As Single = CSng(area.AxisY.Minimum + ((targetTS.Ticks / deltaTSticks) * (area.AxisY.Maximum - area.AxisY.Minimum)))

              ' now convert to pixel position
              Dim y As Single = CSng(area.AxisY.ValueToPixelPosition(targetY))

              e.ChartGraphics.Graphics.DrawLine(New Pen(Color.Blue, Width:=5), x1, y, x2, y)

          End If
     End Sub
TnTinMN 418 Practically a Master Poster

So this crashing as soon as you start the application?

Can you post all MnForm.vb so that we can see the offending line 13?

The snippett you posted should be fine, so I can only make guesses at this point and ask that you try rebooting your machine and then run the app without VS started. There have been some report memory leak issues with WMI, but I don't see anything at this point that would trigger those.

Also what version of VS are you running and what version of the framework are you targeting? These are probably not an issue, but more info is always better.

Is this a release or debug build?

TnTinMN 418 Practically a Master Poster

Dragon,

The .Net MessageBox is just a wrapper for the Win API MessageBox. You could move it using the API SetWindowPosition function, but retrieving its handle gets a bit messy with enumerating the threadwindows and seeking the dialog class name "#32770".

That said, you went the correct route.

TnTinMN 418 Practically a Master Poster

Curious is not the word I use when that happens!

LOL. And just what may the word you use be?

TnTinMN 418 Practically a Master Poster

Aah, the old who has focus when I get clicked dilemma.

If there is no reason that the button needs to be focused, then you can create a nonselectable button or any other control for that matter. The only drawback of this technique is that the button can not be access via the keyboard (Tab, Enter).

  Public Class NoFocusButton
     Inherits System.Windows.Forms.Button
     Public Sub New()
        SetStyle(ControlStyles.Selectable, False)
     End Sub
  End Class

Just add this to your project and perform a build operation. It should show up at the top of your toolbox.

This is a useful alternative to a toolstrip button.

Reverend Jim commented: Cleaner and easier. Thanks. +12
TnTinMN 418 Practically a Master Poster

Return = WmiResults.GetPropertyValue("Name").ToString

??? That compiled?

Option Strict On
Option Explicit On
Option Infer Off

TnTinMN 418 Practically a Master Poster

The code I posted showed you a way to retrieve the available instances of SQL Server within the local network [System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources()].

Where you place the code is up to you to decide.

Personally, I would make the user select a server on the first time execution of the program and then store that server info as a user setting. For subsequent runs, do a check on load to verify that the server is still available. If not, prompt the user for a new selection. It would also be advisable to verify that the database file exists where you expect it to be before attempting to make a connection. Users do get curious at times and can delete your files.

TnTinMN 418 Practically a Master Poster

how will i change that connection/datasource as what the user wants?

I thought you did not want them to be able to change the DataSource.

If you need to allow them to select a server, maybe this will work for you?

    Dim csb As New SqlClient.SqlConnectionStringBuilder

    csb.IntegratedSecurity = True
    csb.UserInstance = True

    ' Full File Path Works with both these DataSource constructs
    'csb.AttachDBFilename = "F:\SQLServer2008\AttachedDBTest.mdf"
        ' DataSource = ".\" & InstanceName
        ' DataSource = ServerName & "\" & InstanceName


    ' |DataDirectory| only works with DataSource = ".\" & InstanceName
    csb.AttachDBFilename = "|DataDirectory|\AttachedDBTest.mdf"

    ' Try to retrieve the available servers
    Dim dtSQLServers As DataTable = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources()
    If dtSQLServers.Rows.Count > 0 Then
        Try
            Dim ServerName As String = dtSQLServers.Rows.Item(0).Field(Of String)("ServerName")
            Dim InstanceName As String = dtSQLServers.Rows.Item(0).Field(Of String)("InstanceName")

            csb.DataSource = ".\" & InstanceName
            'csb.DataSource = ServerName & "\" & InstanceName

        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try

    End If

    Dim conn As New SqlClient.SqlConnection(csb.ConnectionString)

    conn.Open()
    conn.Close()
john.knapp commented: <snippet>nice!</snippet> +3
TnTinMN 418 Practically a Master Poster

use the keydown event not keypress. You cannot trap backspace on keypress.

TnTinMN 418 Practically a Master Poster

Try setting the "TextMaskFormat" before retrieving the text.

MaskedTextBox1.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals

TnTinMN 418 Practically a Master Poster

Well here's one las t update. I added a few for comments to help you uderstand whats in there and cleaned up the code.

As far as things to help you learn.

  1. First and of high important. Set Option Strict On, Option Explicit Off, and Option Infer Off as defaults in your settings. You may hate that you have to do some extra typing, but it will save you much more time in debugging. It will also make you think about why VS is now saying that you should not do some code in a certain way.

  2. Your search engine is your friend. If you are looking for help on a certain keyword or method, try searching for "msdn what you are looking for". This used to mainly take you directly to the documentation page, but I noticed that lately, it pulls more from the microsoft forums. Both can be useful and bad at the same time. If you are looking at the documentation, scroll to the end of the page; that is where the community feedback is and there is often corrections and sometime sample code placed there.

  3. Let VS help you zero in on possible things to investigate further. Right click on methods and click "Go to definition" This helps see more information about the method and can help think about what to go looking for.

  4. Sample code is always good, but you will most likely for the source code as C#. This is OK, because in reality …

Reverend Jim commented: Good advice +12
TnTinMN 418 Practically a Master Poster

Can you take a look on the code again?

Good thing I did. Found some serious logic errors. Good example of that just because it worked, doesn't mean its right.

Now has color setting capabilty and rounded corners. Yes, I had to tweak it. ;)
I really want to use a pointed crystal shape, but writing a custom shape is will take some time. I also add some stuff to make it nicer to use a control. Feel free to ask if you have questions.

Please close this thread if your happy with it.

TnTinMN 418 Practically a Master Poster

Yes that is the intent. You run my script file that will in turn run your file.

The statement call shell("""YourScript.vbs""") will run the script file YourScript.vbs once the specified volume becomes available. I just noticed that I forgot to set fso to nothing, so here is the revised coding with both corrections.

' Ref: http://ss64.com/vb/filesystemobject.html
' Get File System Object
dim fso
set fso = CreateObject("Scripting.FileSystemObject")

dim DriveLetter
' Replace the inputbox with your Volume Letter
DriveLetter = inputbox("What drive to check?", "Drive Letter?", "E") 'Default Drive E

On Error Resume Next
dim USBDrive
USBDrive = fso.Drives(CStr(DriveLetter))

while Err.Number <> 0 
    WScript.Echo("Drive " & DriveLetter & ": DNE")
    if Err.Number <> 0 then wscript.sleep(5000) ' sleep 5 seconds, increase to meet your needs
    Err.Clear
    USBDrive = fso.Drives(CStr(DriveLetter))
wend

fso = Nothing
WScript.Echo("Drive " & DriveLetter & ": is available")

' uncomment and modify this line
'call shell("""YourScript.vbs""")

wscript.quit()

sub shell(cmd)        
   ' Run a command as if you were running from the command line
    dim objShell
    Set objShell = WScript.CreateObject( "WScript.Shell" )
    objShell.Run(cmd)
    Set objShell = Nothing
end sub
TnTinMN 418 Practically a Master Poster

No guarranties here, but I think you are in the realm where you would need to write this as windows service.

You could use WMI to detect the addition of a USB Drive.

You would then need to have the service take excluse control of the drive. On first glance, this looks like a way to do that.
FSCTL_LOCK_VOLUME

Then presumably you would prompt the user to speak your password. using .Net speach recognition.

Use may fid this video helpful on allowing the service to interact with the user.

http://channel9.msdn.com/Blogs/Charles/Session-0-Changes-and-Vista-Compatibility-for-Services-running-as-Interactive-with-Desktop

I hope this helps.

TnTinMN 418 Practically a Master Poster

There is an error in the code I posted last night.

call shell("YourScript.vbs")

should be

call shell("""YourScript.vbs""")

Note the 3 quotation marks on each side of the filename.

This code will then launch your script file.

TnTinMN 418 Practically a Master Poster

I have one question though. Is is possible to integrate the control in the Global Assembly Cache so I won't have to include the file in every project anew?

Sure, just start a new Control Library project and copy the usercontrol code to it. Here is a link to how to add an assembly to the GAC.

http://msdn.microsoft.com/en-us/library/dkkx7f79%28v=vs.90%29.aspx

TnTinMN 418 Practically a Master Poster

To be honest, I don't think I understand what you asking. Here is my interpretation.

  1. You have some program that creates a VBScript file.
  2. This script is to run only if a certain Drive Volume is available.
  3. If it is not available, you want to prompt the user to mount the drive.
  4. Then your script file is to run.

If this is the case then maybe a VBScript like this will work:

' Ref: http://ss64.com/vb/filesystemobject.html
' Get File System Object
dim fso
set fso = CreateObject("Scripting.FileSystemObject")

dim DriveLetter
' Replace the inputbox with your Volume Letter
DriveLetter = inputbox("What drive to check?", "Drive Letter?", "E") 'Default Drive E

On Error Resume Next
dim USBDrive
USBDrive = fso.Drives(CStr(DriveLetter))

while Err.Number <> 0 
    WScript.Echo("Drive " & DriveLetter & ": DNE")
    if Err.Number <> 0 then wscript.sleep(5000) ' sleep 5 seconds, increase to meet your needs
    Err.Clear
    USBDrive = fso.Drives(CStr(DriveLetter))
wend

WScript.Echo("Drive " & DriveLetter & ": is available")

' uncomment and modify this line
'call shell("YourScript.vbs")

wscript.quit()


sub shell(cmd)        
   ' Run a command as if you were running from the command line
    dim objShell
    Set objShell = WScript.CreateObject( "WScript.Shell" )
    objShell.Run(cmd)
    Set objShell = Nothing
end sub
TnTinMN 418 Practically a Master Poster

Ok, I'll take swag at a possible explaination. Are you trying to debug and modify while having VS configured for a release build?

TnTinMN 418 Practically a Master Poster

First off, COOL project.

I think what you want is to define this as a user control so that you can place multiple instances on a form. I apolgize for totally rewriting your code, but it looked like to much fun to play with for me not to turn it into a control I will use.

Here is the modified project. I did not impliment your track bar, but I think you can deal with that.

Edit: I forgot to mention, just rebuild the project. The Digit control should showup on your toolbar.

Reverend Jim commented: Excellent post. +12
TnTinMN 418 Practically a Master Poster

Possible problems:

If you are developing on an Windows XP machine you have to enable UPNP on the computer. see: http://support.microsoft.com/kb/941206

Your firewall may also be blocking access to the router for your program. I think you need ports TCP 2869 and UDP 1900 open.

A good test program to ensure your PC can do this is: http://www.codeproject.com/Articles/13285/Using-UPnP-for-Programmatic-Port-Forwardings-and-N

TnTinMN 418 Practically a Master Poster

Thanks for the replies.

If the elapsed time is greater than something reasonable (say 4 weeks) , prompt the current poster to consider making a new thread or even disallow said posts

We already put up a notification on the quick reply for older threads

I was not aware of this as I did not want to commit an act that I find irritating to dicovert this fact. (Live and learn)

I've not been on a forum that automatically closed threads, but have been on one where a Moderator could mark the thread as answered. Unfortunately, they had irritating habit of marking their own post as the answer often when it was totally irrelevant to the original question or worse totally incorrect.

I guess that I just seen to many several year old threads dug up recently in which the new poster displayed their ignorance and this prompts others to add to the issue.

Thanks for the info.

TnTinMN 418 Practically a Master Poster

Hi,

I’m sure I’m not the only one irked by those who resurrect long dormant threads.

Would it be possible to check new post’s creation-date against the creation-date of the last post by the thread’s creator? If the elapsed time is greater than something reasonable (say 4 weeks) , prompt the current poster to consider making a new thread or even disallow said posts. The thread creator should always be able to post a bump if they are still seeking feedback.

In addition, if a thread has not been closed after some duration (6 weeks?), would it be possible to close it out automatically with some status such that it would no longer show up in the unanswered listings? The original poster could be sent an email stating that such an action has occurred and could reopen the thread by posting a bump request.

Thanks for reading my rants.

TnTinMN 418 Practically a Master Poster

Hi Lulu,

You are sure beating that example code to death! :-)

You should really post more of the code when you are asking for help. People are not going to know what DTRow is for example.

Oh well, so much fo my pedantic streak. Here is one way you could do it.

      Dim group As IEnumerable(Of DataRow) = _
         From sortrow As DataRow In ( _
         From row In DS.Tables(0).AsEnumerable() _
         Group row By LINENAME = row.Field(Of String)("LINENAME") Into grp = Group _
         Order By LINENAME _
         Select DTRow(grpDT, _
                      New Object() {LINENAME, _
                                    myToday.Add( _
                                                New TimeSpan(CType( _
                                                                     grp.Average(Function(r2 As DataRow) TimeSpan.Parse(r2.Field(Of String)("EVENTTM")).Ticks),  _
                                                                     Int64 _
                                                                   ) _
                                                            ) _
                                               ) _
                                   } _
                     ) _
         ) Order By sortrow.Item("EVENTTM")

Or you could just do it on your datatable.

      'Add the query results to the new Table
      For Each row As DataRow In group
         grpDT.Rows.Add(row)
      Next

      grpDT.DefaultView.Sort = "[EVENTTM] Asc" ' for ascending


      'grpDT.DefaultView.Sort = "[EVENTTM] Desc" ' for descending 


      'Assign new Table as DataSource of DGV
      GridView1.DataSource = grpDT.DefaultView

Select one way or the other. Not Both.

TnTinMN 418 Practically a Master Poster

Did some playing around and found putting the search into a separate function increased the speed by a factor of approximately 4(i.e. on my machine original code was 1200-1300, the new code
300-400)
You also switched to using a char for the seek parameter versus char which is the the reason for the speed increase not the fact that it hidden under another function.

If the OP would change: str.IndexOf(",", 0) to str.IndexOf(',', 0) the factor of 4 performance boost would also be observed.

So there is a lesson in this; when seeking for one char use the char overload not the string overload.

TnTinMN 418 Practically a Master Poster

five this a try

Dim excelApp 
Set excelApp = CreateObject("Excel.Application")
excelApp.Visible = True
Dim FilePath 
FilePath = "F:\afi\vbscript\Test.xls"
Set ExcFile = excelApp.Workbooks.Open(FilePath)
Dim a
a = excelApp.Cells(1, 2)

If Not (IsNull(a) Or IsEmpty(a)) Then
    dim parts
    parts = Split (a, VBLF)

    Dim b
    b = ""

    for each p in parts
        If p <> vbNullString Then
            select case Len(b)
            case 0
                b = b &  p
            case else
                b = b & vbLF & p
            end select
        End If  

    next

    excelApp.Cells(1, 2).Value = b
Else
    MsgBox ("null cell")
End If
excelapp.Quit()
TnTinMN 418 Practically a Master Poster

I don't know what notepad.vbs is but I suspect it is some type of shell scripting host. You probably will get better support in this forum

Click Here

A guess whould be that the value of "a" is empty at that point. Check your Exel file. You could enclose everything after the "a=" statement in an if block.

If Not (IsNull(a) Or IsEmpty(a)) Then
' the statements

End If
TnTinMN 418 Practically a Master Poster

I guess they updated VBA a bit since I last did much work with it so I was able to test this out. My mistake on the filter Function, I forgot it ignores empty strings. This should work for you.

Set excelApp = CreateObject("Excel.Application")
excelApp.Visible = True
Dim FilePath As String
FilePath = "F:\afi\vbscript\Test.xls"
Set ExcFile = excelApp.Workbooks.Open(FilePath)
Dim a As String
a = excelApp.Cells(1, 2).Value
Dim parts() As String
parts = Split(a, vbNewLine)

Dim b As String
b = ""
Dim ubparts As Integer
ubparts = UBound(parts)
Dim i As Integer
For i = 0 To ubparts
    If parts(i) <> vbNullString Then

        b = b & IIf(i > 0 And Len(b) > 0, vbNewLine, vbNullString) & parts(i)
    End If
Next i
excelApp.Cells(1, 2).Value = b
TnTinMN 418 Practically a Master Poster

Looks like VB6 to me or possibly Shell Scripting. You are in the VB.Net forum.

Your blank lines are likely due to to VBNewline characters.

I can't test this, but give it a try.

Instead of using "Replace" use the "Split" function to create an array of strings; split on VBNewline. Then use the "Filter" function with the filter set to VBNewline and the "switch" parameter set to False to create an array with the blank lines removed. Then create a new string by concatonating each array element. Remember to add a VBNewline to the end of each element.

Good luck.

TnTinMN 418 Practically a Master Poster

I just realized that I gave some bad advise above as you can view each connected PC through Skydrive's web interface.

TnTinMN 418 Practically a Master Poster

As long as each of you is only editing your our own assigned files this may work; I just gave it a simple test. Create a MS SkyDrive account and install MS's SkyDrive app on each of your systems (requires Vista or higher). Each of you would login to the same SkyDrive account. Then store your VS project on SkyDrive.

You may will get messages about about source modified outside the VS environment if you have a file open that has been modified by someone else.

TnTinMN 418 Practically a Master Poster

i took a form and dragged and dropped that database as details view. first i arranged labels in row format and their respective text boxes under them. and i made copies of text boxes of first row text by holding Ctrl key

The details view is just that the details for a single record. The origianl textboxes created by the drang 'n drop are bound to the naviagtor that should also have been create by that operation. The textboxes will show the details for the currently selected record indicated in the naviagor position box. Even if you correct the binding definition that got lost when copying. Each row would show the same data.

To have multiple rows of details, you would need to have multiple binding navigator (or some other binding method) set up for the additional rows a where each sucessive row would be incremented one greater thean the row above. But what happens if your retrieved data has less than four rows like shown in the picture. If this case you would have to have code to remove the binding and blank out the empty rows. Yes it can be done, but it will involve a fair amount of coding to achieve.

If you want multiple rows, use a datagridview.

TnTinMN 418 Practically a Master Poster

This should really be moved to the C# forum.

TnTinMN 418 Practically a Master Poster

I don't use MySQL but based on this , the connection string looks wrong. It looks more like a SQL Server connection string.

TnTinMN 418 Practically a Master Poster

Do you need to print from the application?

If so, printing with a WPF RichTextBox, it is pretty easy to get WYSIWYG results. It even handles embedded images. :)

Even if it is a WinForm application, you can always host a WPF RichTextBox in the Winform app.

I would recommend that you save as RTF. Word can read an RTF document.

TnTinMN 418 Practically a Master Poster

Try this pattern, it's one of many that will work.

  With DataGridView1.Rows(DataGridView1.Rows.Add())
     .Cells(0).Value = "hi"
  End With

"DataGridView1.Rows.Add()" returns the index of the row that is just added. Doing it this way you add an empty row that is templated to accept the values that the cells expect.

Edit: This assumes that you have defined the columns of the DGV elsewhere.

TnTinMN 418 Practically a Master Poster

Well after realizing that I was using files with Timestamps a day ahead of me, I was able to look at your code and made the changes that we had recommended. It works fine now. I also made a few minor changes to assist you.

Modified project

TnTinMN 418 Practically a Master Poster

Jim's method is probably the simplest and qickest in performance terms, but I would recommend that the linked textbox be passed to the second form versus hard coding the reference. The TB could be passed in the form's contructor, be a property on the form or passed in the Show or ShowDialog method.

Since you asked about databinding, I'll show that method and pass the TB in Show method. Binding should be removed when not needed, so that is done in the FormClosed event handler.

Public Class Form2

  Public Shadows Sub Show(ByVal tb As TextBox)
     SetLinkedTB(tb)
     MyBase.Show()
  End Sub

  Public Shadows Sub ShowDialog(ByVal tb As TextBox)
     SetLinkedTB(tb)
     MyBase.ShowDialog()
  End Sub

  Private LinkedTB As TextBox
  Private LinkedTBBinding As Binding
  Private Sub SetLinkedTB(ByVal tb As TextBox)
     TextBox1.Text = tb.Text
     TextBox1.SelectionStart = tb.SelectionStart
     TextBox1.SelectionLength = tb.SelectionLength
     LinkedTBBinding = New Binding("Text", TextBox1, "Text", False, DataSourceUpdateMode.OnPropertyChanged)
     tb.DataBindings.Add(LinkedTBBinding)
     LinkedTB = tb
  End Sub

  Private Sub Form2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
     LinkedTB.DataBindings.Remove(LinkedTBBinding)
     LinkedTB.SelectionStart = TextBox1.SelectionStart
     LinkedTB.SelectionLength = TextBox1.SelectionLength
  End Sub
End Class

usage:

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     Form2.Show(TextBox1)
  End Sub
john.knapp commented: nice code! I've been beating myself up with databinding the last few days - fixing an MS walkthrough and all :) +0
TnTinMN 418 Practically a Master Poster

That's what I figured. If you open the file with Notepad, you will probably see that it contains Html code. Two possible causes of this are that the adress you have is not the true download link or that site requires cookies to authenticate the download.

I have not found a solution to the first one. All that can be done is capture the Navigating event and print out the "e.url" property in the event and look through the results. There will probably be several Urls printed out,

If you do have that right link but need to supply cookies, I created an extended WebClient class to retrieve the cookies.

Imports System.Runtime.InteropServices

Public Class WebClientwithCookies
   Inherits Net.WebClient

  Private mycookies As New Net.CookieContainer()
   Public Shadows Sub DownloadFile(ByVal url As String, ByVal filename As String)
      mycookies.SetCookies(New Uri(url), GetCookies(url))
      MyBase.DownloadFile(url, filename)
   End Sub

   Public Shadows Sub DownloadFile(ByVal url As Uri, ByVal filename As String)
      mycookies.SetCookies(url, GetCookies(url.ToString))
      MyBase.DownloadFile(url, filename)
   End Sub


  Protected Overrides Function GetWebRequest(ByVal address As Uri) As Net.WebRequest

   Dim request As Net.WebRequest = MyBase.GetWebRequest(address)

   If request.GetType() Is GetType(Net.HttpWebRequest) Then
   CType(request, Net.HttpWebRequest).CookieContainer = mycookies
   End If

   Return request

  End Function

   Public Enum CookieError
      ERROR_NO_MORE_ITEMS = 259
      ERROR_INSUFFICIENT_BUFFER = 122
      ERROR_INVALID_PARAMETER = 87
   End Enum

   <DllImport("wininet.dll", SetLastError:=True)> _
   Public Shared Function InternetGetCookie(ByVal url As String, _
                                            ByVal cookieName As String, _
                                            ByVal cookieData As System.Text.StringBuilder, _
                                            ByRef size As Int32) As Boolean
   End Function

   Public Shared Function GetCookies(ByVal uri As String) As String
      Dim datasize As Int32 = 1024
      Dim cookieData As New …
TnTinMN 418 Practically a Master Poster

Good job John!

I never thought to to search for an api function to create a user DSN (Doh!) and have done it by directly modifying the the registry.

For those interested in the registry route, I have an example for creating/deleting a Dbase DSN at this link:

Click Here

TnTinMN 418 Practically a Master Poster

The form of the Url does not matter.

When you say "it won't let me download" what do you mean. Does it: throw an error, or the downloaded file is not what you want (appears corrupted) or is it something else?

TnTinMN 418 Practically a Master Poster

I don't use MySql, but based this article: Handling BLOB Data With Connector/Net it seems that storing and retrieving binary data follows the same methods as used for for DBs that I'm familar with.

I don't know if the use of phpmyadmin would throw in any obstacles for you, but it should be worth a try.