Solved

VB.NET Notepad

Posted on 2016-07-21
3
40 Views
Last Modified: 2016-07-21
HI Experts

I have an SQL that writes to a ComboBox can you explain how to write it to the combobox and open notepad and write to it so customer doesn't need to cut and paste from combo to notepad

Dim Sql As String = String.Format("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.tables ORDER BY TABLE_NAME")
            Dim reader As Data.IDataReader = DataConnector.GetReader(Sql, Nothing)
            Do While reader.Read = True
                mTablesComboBox.Items.Add(reader.GetString(0))
            Loop

Open in new window

0
Comment
Question by:Kevinfeening
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 500 total points
ID: 41723979
It is unclear what you mean by notepad. Is it Windows Notepad.exe you want to write to? Is it a notepad control within your application?
If it is the former you can create a temp text file, fill it with the table names from your SQL query and then open it with Notepad.exe using Process.Start
0
 

Author Comment

by:Kevinfeening
ID: 41724007
Sorry its Windows notepad

the SendMessage(notepad.MainWindowHandle, WM_SETTEXT, IntPtr.Zero, texttoadd) sends nothing
I tried SendKeys.SendWait(texrttosend) sends some info not all and sometimes exits the program
there may be up to 50 fields in the table I want them on separate lines how do you  populate the notepad or is the only way is to create a text file and open it. I would rather send direct but if a temp file is the only way how do you open It in the notpad with out using file open

Const WM_SETTEXT As Integer = &HC
        <DllImport("user32.dll")> _
        Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, <MarshalAs(UnmanagedType.LPStr)> ByVal lParam As String) As IntPtr
        End Function

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim npad As ProcessStartInfo = New ProcessStartInfo("NotePad.exe")
            npad.UseShellExecute = True

            Dim notepad As Process = Process.Start(npad)
            Dim texttoadd As String = ""

            Dim sql As String = "Select column_name from information_schema.columns where table_name = @TableName order by column_name"
            Dim params As New DataParameterCollection("@TableName", "Employee")
            Using dataConnector As IDataConnector = DataUtils.GetDataConnector()
                Dim reader As Data.IDataReader = dataConnector.GetReader(sql, params)
                Do While reader.Read = True
                    texttoadd = vbLf & reader.GetString(0)
                    SendMessage(notepad.MainWindowHandle, WM_SETTEXT, IntPtr.Zero, texttoadd)
                Loop
                reader.Close()
            End Using
        End Sub
    End Class

Open in new window

0
 

Author Closing Comment

by:Kevinfeening
ID: 41724031
Worked it out from the Process.start
used sendkeys.send with vbLF to fix
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Import Data from Multiple Text Files in Excel 12 85
Generate Numbers in JQuery file 11 72
vb.net deleting excel sheet in workbook 11 30
Set arraylist as datatable 2 6
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

761 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question