Jump to content
Xtreme .Net Talk

DPrometheus

Avatar/Signature
  • Posts

    50
  • Joined

  • Last visited

Everything posted by DPrometheus

  1. You can connect to several databases with dataproviders in .NET. See http://msdn.microsoft.com/en-us/library/s7ee2dwt%28VS.71%29.aspx for more information about data providers. ConnectionStrings for the several databases can be resolved at www.connectionstrings.com/
  2. What about: CBoolProperty m_bHeight = false; [/Code] ??
  3. What if you take the code from Chetan Chudasama's weblog and recompile it against the vs.net 2008 (v9) libraries. Then you should be able to use that in the codeplex project for example Chetan opens Visual Studio v8 (2005) from his code using EnvDTE80; ... Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.8.0"); [/Code] If you replace these with the vs.net 2008 equivalents (version 9) It might do the trick? ~DP
  4. in the ElseIf vals(0) = "Drops" Then Me.txtDrops.Text = vals(1) End If you have to have an additional loop which checks on a vbNewLine (or just empty line). Before you encounter that (or a EndOfFile) you can add each sentence as an item. i.e. Dim FileName As String FileName = "Data.dat" Dim srBestiary As System.IO.StreamReader = New System.IO.StreamReader(FileName) Dim line, vals() As String Do line = srBestiary.ReadLine If line Is Nothing Then Exit Do vals = line.Split(vbTab) If vals(0) = "Name" Then Me.txtName.Text = vals(1) ElseIf vals(0) = "Level" Then Me.txtLevel.Text = vals(1) ElseIf vals(0) = "Drops" Then ' Add this piece here while(line = srBestiary.ReadLine) if string.IsNullOrEmpty(line) exit while Me.txtDrops.Text = line end while End If Loop srBestiary.Close() srBestiary = Nothing however you should also append the text or something, since now you are replacing it and thus the textbox (assuming txtDrops is a textbox) will only read the last line of the document, thus 'Raw Meat'. You can change this for example by replacing Me.txtDrops.Text = line with Me.txtDrops.Text &= vbNewLine & line ~DP
  5. Hi there, Do you want the textbox to consist of scrollbars? Since then you don't have to add them, you can then dis-/enable them in the property page of the rtb. (named Scrollbars and you can set it to both, horizontal, vertical, force horizontal etc.) Otherwise you can add multiple controls to a usercontrol or add them to a panel. Here you can add the VScrollBar. Now you can dock it to the right (as default in most programs) and handle the scroll event (with e.newvalue and e.oldvalue in the event arguments you can determine how far you want your controls moved) You can then adjust the location property of the controls contained within the panel or usercontrol. ~ DP
  6. VB.NET Private Declare Function SendMessageByString Lib "user32.dll" Alias "SendMessageA" _ (ByVal hwnd As IntPtr, _ ByVal uMsg As Int32, _ ByVal wParam As IntPtr, _ ByVal lParam As String) As Integer Private Const WM_SETTEXT As Int32 = &HC Private Declare Function SendMessageByInt Lib "user32.dll" Alias "SendMessageA" _ (ByVal hwnd As IntPtr, _ ByVal uMsg As Int32, _ ByVal wParam As Int32, _ ByVal lParam As Int32) As Integer Private Const WM_GETTEXTLENGTH As Int32 = &HE Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As IntPtr Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" _ (ByVal hWnd1 As IntPtr, _ ByVal hWnd2 As IntPtr, _ ByVal lpsz1 As String, _ ByVal lpsz2 As String) As IntPtr Public Function GetHandle(ByVal ClassName As String) As IntPtr Dim hwnd As IntPtr = FindWindow(ClassName, Nothing) hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Edit", Nothing) If (Not hwnd.Equals(IntPtr.Zero)) Then Return hwnd Else Return IntPtr.Zero End If End Function Public Sub SetNewText(ByVal hwnd As IntPtr, ByVal txt As String) If (Not hwnd.Equals(IntPtr.Zero)) Then Call SendMessageByString(hwnd, WM_SETTEXT, IntPtr.Zero, txt) End If End Sub ~DP
  7. Open notepad with System.Diagnostics.Process.Start("notepad.exe") [/Code] Then you can get the window handle and send a WM_SETTEXT message to set the text. also you could write to a (temporary) text file and start notepad and the textfile as second parameter: [Code] System.Diagnostics.Process.Start("notepad.exe", "mydocument.txt") [/Code] ~ DP
  8. Update =-=-=- The problem grew today in size as I also need a reference to some document objects. Those can be set with a document manager (custom class like above patient manager with additional functions). But the references are lost in the VBA code (if I set it within the .NET assembly), same goes for the other way 'round. Anyone has tips for a workaround or something? thanks in advance, ~DP
  9. As iMP said, you should get something like this: vb.NET Private Function CheckControls(ByVal control As Control) As Control For Each c As Control In control.Controls If c.Controls.Count > 0 Then CheckControls(c) If TypeOf c Is Label Then ' Do something with c Return c End If Next Return Nothing End Function [/Code] or C# [Code] private Control CheckControls(Control control) { foreach (Control c in control.Controls) { if (c.Controls.Count > 0) CheckControls(c); if (c is Label) { // Do something with c return c; } } return null; } [/Code] ~DP
  10. Thanks for your opinion thus far. In the load event of the Main Form I call this line in the .NET App: _wDoc = EcAppPanel1.LoadDocument(My.Computer.FileSystem.CurrentDirectory & "\Spec.dotm") which opens the file in the hosted Word Instance. In this macro enabled template I got only one function like this: Sub AutoNew() AddIns.Add ("K:\mso\AppInApp\Word07Def.dotm") End Sub [/Code] Which adds another macro enabled template to the word instance. This is done like this so the template stays active even after switching documents. This Word07.dotm template modifies the ribbon together with some additional functionality. For example [Code] Sub AdresseringButton_Click(control As IRibbonControl) Dim Address As New Specialist07.EcfAdresseringForm Address.Show End Sub [/Code] Where Specialist07 is a .NET DLL registered with regasm & gacutil and marked as COM exposed. EcfAdresseringForm is a .NET form. The resulting tlb file is linked to the dotm file by extra->References in the VBA Editor. It should check other properties for a patient in a db (like name and disease and stuff) do some transformations with it (insert predefined text from other table (based on patient ID, actually disease and some other variables but that is linked to the ID) & replace special characters in the text with those variables of this selected patient) and finally it should add this piece of text (with the inserted variables) into the word document. Later the document is saved in another table in the DB. btw the patient ID can change anytime by another application (This is handled in the .NET assembly, but the VBA can't update (since it doesn't share the same patient Manager object)) ~ DP
  11. From this website Access Specifiers Public: Gives variable public access which means that there is no restriction on their accessibility Private: Gives variable private access which means that they are accessible only within their declaration content Protected: Protected access gives a variable accessibility within their own class or a class derived from that class Friend: Gives variable friend access which means that they are accessible within the program that contains their declaration Protected Friend: Gives a variable both protected and friend access Static: Makes a variable static which means that the variable will hold the value even the procedure in which they are declared ends Shared: Declares a variable that can be shared across many instances and which is not associated with a specific instance of a class or structure ReadOnly: Makes a variable only to be read and cannot be written
  12. Hey there, Some serious problem occurred the other day. I'm building a reporting module. At the moment I have a .NET Application which consists of several buttons to the right side of the form. on the mid - left side there is Word 2007 hosted in a panel. The .NET Application loads a .NET DLL for some functionality for those buttons. Word loads a specific template which strips most of the ribbon and adds our own buttons and controls. (With VBA Scripts). These buttons calls the same .NET DLL as the application. Now I need to have access to a patient Identifier (for now perhaps more fields later on) which resides in the .NET DLL. I made a simple class EccPatientManager which holds the patient ID. Public Class EccPatientManager ' Shared ID private shared _id As Long = -1 ''' <summary> ''' Switch to patient ''' </summary> ''' <param name="value"></param> ''' <remarks></remarks> Public Shared Sub setPatient(ByVal value As Long) _id = value End Sub ''' <summary> ''' Retrieve patient ID ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property ID() As Long Get Return _id End Get End Property If I fill this in the .NET Application with valid data and call this from word (with vba ) I always get back -1. Probably because the .NET DLL is loaded twice, once for each process. Now I looked a little into IPC but with DDE I think this is a no-go with my current knowledge about it and the time constraint on the project. Also .NET solutions as .NET Remoting don't apply in my opinion as WinWord is not a .NET application, and I can't modify it's source Does someone can put me in the right direction to send data (as simple as integer value-types) from my application to the VBA script? I need to execute some code in VBA [create a form (from the .NET DLL) and show it, as well as supply the patient Identifier]. (No option to move the calling code to the .NET DLL as the VBA handles the GUI of the template for WinWord). Thanks for reading, let me know if you've got any suggestions.. ~ DP
  13. Hey there for single arrays you can use this: Default Public ReadOnly Property Item(ByVal index As Integer) As Object Get Return List(index) End Get End Property If you want to use an array of more items you can go for an implementation with 'rows' in your array. Create a class or structure which contains a single row of 8 items. then you can modify it to something like this: Default Public Property Item(ByVal index As Integer) As ArrayRow8 Get dim r as new ArrayRow8(.. input data from array8x8(index) .. ) Return r End Get Set(byval value as ArrayRow8) array8x8(index) = value ' You have to specify an operator overload or copy this per value. Return r End Get End Property however I must confess I don't know if it's a Microsoft Best Practice, but that's how I solved it in the past. Hope it helps. ~DP
  14. Also see this post ' Import ' Post message to handle <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Private Shared Function PostMessage( _ ByVal hWnd As IntPtr, _ ByVal Msg As UInteger, _ ByVal wParam As IntPtr, _ ByVal lParam As IntPtr) As Boolean End Function <DllImport("user32.dll")> _ Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, _ ByVal wParam As IntPtr, ByVal lParam As StringBuilder) As IntPtr End Function ' Message registration .. both app's CONSTANTS.MSG_STRINGWISSEL = RegisterWindowMessage("StringWissel") sending app SendMessage(hWnd, CInt(CONSTANTS.MSG_STRINGWISSEL), Nothing, New StringBuilder("TEST PATIENT")) Receiving app Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) ' Select appropriate message Select Case m.Msg ' Case we want to switch patients Case CInt(CONSTANTS.MSG_PATIENTWISSEL) Try 'Activate this screen Me.Activate() Dim ptr As IntPtr = m.WParam Dim patNr As Integer = ptr.ToInt32 ' Change patient ChangePatient(patNr) Catch ex As Exception ' In case of errors list them to the user MsgBox(ex.Message) End Try ' Case we want to send text Case CInt(CONSTANTS.MSG_STRINGWISSEL) ' Add received data to string object ' _BS.BuildString(m.LParam) Dim b As StringBuilder b = CType(m.GetLParam(GetType(StringBuilder)), StringBuilder) Me.Text += " : " + b.ToString() 'Me.Text += " : " + m.LParam.ToString() Case Else MyBase.WndProc(m) End Select End Sub Although I feel the Alloc could work as well, Allocation forces us to an exception for receiving string data. As well as strings could be send to (third party) applications which (might) not do anything with the string, thus leaving it into memory.
  15. Hey there For the several applications rolled out right now we want a single module to handle inter-application communication. i.e. we have one application (called App1 for simplicity) and with a button in this application we switch to another application (called App2). we want to exchange information such as patient number etc. My guess was to use Postmessage / sendmessage for this. All works fine, until we got to the point in which we have to communicate strings instead of numbers. An integer was easy to convert to a Intptr with new IntPtr(intValue) however creating an intptr from a string and send this pointer won't work. We also saw there was an overloaded sendmessage with a stringbuilder, but the receiving application receives other characters then those which were sent. As a third we tried to dissassemble the string and send it as bytes. as in this solution. While this solution works my co-workers ain't happy with such a kind of a work-a-round. if we can't send the string this project will come to an end, and we are bound to use an even more cumbersome solution, namely something with an invisible button, which we can change its caption with a call to SetWindowText. Thereafter on a text change we can read the string and dependent on some codes we can trace back what kind of 'message' is posted. I'm definitely convinced we shouldn't go for this, but if we can't find a way to send strings with a postmessage or sendmessage, I have no other option then to give in. :p Does someone know if it can be achieved in .NET? WM_SETTEXT is capable of sending strings, so somehow it should be possible in my opinion. Also in native code (where I program in @home) this ain't a problem, and is definitely possible. Someone any suggestions or tips? Maybe it's just me who's stubborn, I just want to know what's best to do, and if possible know how to send strings using messages. thanks in advance ~DP
  16. For generating Word documents you can use Office Interop. Include the following references in your .NET project: - Microsoft.Office.Interop.Word - Office These enable Office objects like Word.Application and Word.Document. From there you can choose to insert shapes, text etc. or load a template and replace certain fields. such as shown here ~ DP
  17. * The focus could also be a result of the call to process.Start(info) I found a little bit more information.. Apparently you have to register your custom messages and can't just use identical numbers to identify messages. However problem ain't solved yet. Since all messages receive the value 0. I changed the SendMessage declaration to Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, _ ByVal wParam As IntPtr, ByRef lParam As IntPtr) As IntPtr instead of a StringBuilder as lParam.. However if some one has an idea of how I can use the stringbuilder I'm all ears. Then I sent the message like: SendMessage(hWnd, CInt(MSG_PATIENTWISSEL), Nothing, CType(ComboBox1.SelectedValue.ToString.Trim, IntPtr)) and receive it like this: Case CONSTANTS.MSG_PATIENTWISSEL Try Me.Activate() _patNr.Append(m.GetLParam(GetType(IntPtr)).ToString) ... At the load event I register MSG_PATIENTWISSEL as CONSTANTS.MSG_PATIENTWISSEL = RegisterWindowMessage("PatientWissel") Still I receive '0' as nr. instead of a 9 digit number what I sent.. ??? SOLVED: The problem was in converting IntPtr to Integers and lParam used byref instead of wParam, so used that one instead. ' Receive: Dim ptr As IntPtr = m.WParam Dim patNr As Integer = ptr.ToInt32 ' Send: SendMessage(hWnd, CInt(MSG_PATIENTWISSEL), New IntPtr(CInt(ComboBox1.SelectedValue.ToString.Trim)), Nothing)
  18. Hey there I'm trying to send some messages to another program. Somehow they never arrive. The sending application on button click: Dim info As New ProcessStartInfo("C:\Users\mso\Documents\Visual Studio 2005\Projects\SwitchApplication\MedicalRecords\bin\Debug\MedicalRecords.exe") Dim process As Process process = process.Start(info) ' Wait for process to be started Threading.Thread.Sleep(1500) hWnd = process.MainWindowHandle Dim Buffer As New StringBuilder(128) Buffer.Append(ComboBox1.SelectedValue.ToString) MsgBox(Buffer.ToString & "Sent to " & hWnd.ToString) SendMessage(hWnd, MSG_PATIENTWISSEL, Nothing, Buffer) The ' receiving' application Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Select Case m.Msg Case CONSTANTS.MSG_PATIENTWISSEL Me.Activate() _patNr.Append(m.GetLParam( GetType(System.Text.StringBuilder))) System.Threading.Thread.Sleep(1500) Me.Text += ":" & _patNr.ToString MsgBox(_patNr.ToString & " received!") Case Else MyBase.WndProc(m) End Select End Sub Private Sub MedicalRecord_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Shows right handle Me.Text = Me.Handle End Sub however the handles correspond to eachother, so I'm pretty sure it's the right handle. Also the CONSTANTS.MSG_PATIENTWISSEL constant matches on both applications. The Send messagebox shows up, but the receive messagebox doesn't. Anybody has an idea of what I'm doing wrong? thanks, ~ DP EDIT: If I put a System.Diagnostics.Debugger.Break() call between Case CONSTANTS.MSG_PATIENTWISSEL and Me.Activate() the program crashes. (As there is no debugger attached to the second application) Weird thing is, that it does reach this code. Although the text variable of the form doesn't change, as well as the messagebox seem to be refusing to pop up. The receiving application also takes focus when the message is actually sent.
  19. Hi there http://www.codeproject.com/KB/miscctrl/imapi2.aspx also Nero has a sdk which you can use to burn files http://www.softpedia.com/downloadTag/Nero+SDK ~ DP
  20. thanks for your quick response. I changed the if not word.ActiveDocument to if word.ActiveDocument is nothing. Just before you posted I already changed it to if word.ActiveDocument = "" which also got me rid of the error. Close happens to trigger with the right ActiveDocument, (document1, even Word07 and WordApp points to the same document before they shut it down) but still it fails to close that one, exiting with error 4198 - command fails, while running this from the application. I'm about to implement the document collection as I'm back from my break, see if that does any good. thanks for your suggestions. ~DP EDIT: I found the bug. Within the .net environment I changed some handlers for the document events. (DocumentOpen, NewDocument & DocumentBeforeClose) Within the DocumentBeforeClose event I was canceling out that same event, since it could close the panel as well. After changing this the document succesfully switches from template to template. I just have to trust the end user not pressing the closing-X while in the editor. I made a small warning messagebox just in case. Thanks for your time and suggestions ~DP
  21. Hi Cindy, thnx for replying. I'm working here at the local hospital. I'm currently working on a control library for this particular hospital. For our former applications (VB6) they have built text editors for each module, we now want a more robust way to implement text editors. Since every employee is familiar with Word, and its highly customizable, we choose to create a 'word panel'. This sits in our control library, and will open Word07 within it's client rectangle. If we load a template with customized ribbons and functionality we can make one single control which can be used for each specialisation within the hospital. Which buttons and addins are available are controlled by templates. These can be switched by the user (for users with different occupations, or specialisations which closely overlap) and by the application itself. Those documents listed above in my first post were just for testing purposes. Available documents are shown based on logged in user or state of the application. Furthermore I think Word.ActiveDocument equals to nothing when I load from my .net application and the real problem exists in the following snippet: If FileExists(openFile) Then ' Activate new template Word.ActiveDocument.Close (False) Word.Documents.Open(openFile).Activate End If if I insert something like: If Word.ActiveDocument = "" Then MsgBox "Word ActiveDocument doesn't exists in code!" End If I get no messages in my application (which uses the Word-panel) and in Word 2007 itself. However, Word 2007 keeps the newly loaded document, while the applications switches back to the old one. And when I have the On Error Resume Next statement it also displays the error number and description posted above. Last I removed the On Error Resume Next and check for error values after ActiveDocument.Close and Documents.Open it displays two messages (One error for each function :( ) loosely translated into something similar like this: Error 4198: Command failed. (this goes for the close function) I found a similar tread for this one microsoft newsgroups but without a real solution. followed with error 91 as shown above (first thread, on open function) Any idea's why the applications both run different code paths with the same source code? Word 2007 has no issues with my templates while the panel keeps spawning errors. Why does the document fails to close? It really gives a descriptive error for that line. I hope I made myself clear. thanks in advance ~ DP
  22. Hi StreamReader sra = new StreamReader ("c:\\File.txt"); string aLine = sra.ReadLine(); Console.WriteLine(aLine); string[] TokenBuffer = aLine.Split('\t'); where \t comes from http://msdn.microsoft.com/en-us/library/h21280bw.aspx TokenBuffer[0] & TokenBuffer[1] indicates the string before the second tab while the other entries in this array are extra text Loop through it for each line and your done ;) ~ DP srry couldn't help myself write a little bit of code :p
  23. Hi there, I've encountered the following problem and I'm really clueless. For work I've made a word host application, and now we need to switch templates in it. I've made a custom ribbon where a combobox lists all templates. These templates are loaded in the combobox_change event. See code listing 1 below. I've a Word template (.dotm) called Spec.dotm. This template does nothing more then redirect to another template (Word07Def.dotm), which will be activated as some sort of global template (This enables me to switch documents). This global template contains the ribbon adjustments, and VBA code to handle the ribbon controls If I do this in Word 2007 everything works fine, however if I do this in my host application (Which does nothing else then just open Spec.dotm, which succesfully redirects to Word07Def) it fails with error 91: object variable or with block not set. when I try to switch templates. If I check the Globally loaded templates I see Word07Def activated. Whenever it fails I see word flickering once or twice (which indicates it loads the other document, I guess) and then opening my previous document with the error code. Weird thing is, if I do this in Word 2007 it works like a charm?! :confused: I have word running in a panel control like code listing 2. code 1: Sub TypeBriefCombo_Change(control As IRibbonControl, text As String) On Error Resume Next Dim openFile As String openFile = "" Select Case text Case "Poliklinische brief" ' set filename string openFile = "K:\mso\AppInApp\Klinisch.docx" 'Templates("K:\mso\AppInApp\Klinisch.dotm").OpenAsDocument Case "Klinische brief" openFile = "K:\mso\AppInApp\Klinisch.docx" Case "Ontslagbrief" openFile = "K:\mso\AppInApp\Ontslag.docx" Case "Patiëntenbrief" openFile = "K:\mso\AppInApp\Ontslag.docx" End Select If FileExists(openFile) Then ' Activate new template Word.ActiveDocument.Close (False) Word.Documents.Open(openFile).Activate End If If Err.Number <> 0 Then MsgBox "Err: " & Err.Number & " " & Err.Description End If End Sub code 2 ... ' Use Opusapp for word applications If _wordWnd = 0 Then _wordWnd = FindWindow("Opusapp", Nothing) If _wordWnd <> 0 Then SetParent(_wordWnd, Me.Handle.ToInt32) ... _wordApp.Visible = True SetWindowPos(_wordWnd, Me.Handle.ToInt32(), 0, 0, Me.Bounds.Width, Me.Bounds.Height, SWP_NOZORDER Or SWP_NOMOVE Or SWP_DRAWFRAME Or SWP_NOSIZE) OnResize() ... As a final note, since the Word07Def.dotm is loaded via Spec.dotm Word07 is not able to open the project Word07Def in VBE, so I can't set any real breakpoints. Someone got any idea's or tips? ~ DP
  24. As posted above, yes I also set the icon at the properties page for the application. I also tried wsrm.ico which I found at the wow64 Windows folder. This icon scales and shows the image in al views in explorer. However, after inserting it in VS2005 and set that one as active icon, I still get the same results. The application icon shows up in only 3 views, and while in one of the other views, the image gets converted back to the default icon.
  25. Heyey I have a WinForm application built in VB.NET, all works fine. Now I want to have a nice icon to finish it all up. I already have a form Icon (So it shows up while doing Alt+Tab, and the taskbar is also fine). I also set the icon at the properties page for the application. And even in TaskManager and Explorer (rightclick application exe file -> properties), the icon shows as expected. Although the .exe file still shows the default icon which VS2005 set at projection creation. How can I change this icon as well? The icon file consists of a 16x16 and 32x32 picture, both 256 colors as 16 colors. ~DP After switching the View in Explorer I determined that the icon is succesfully registered, as the icon shows up in the following views: - Small icons - List view - Detailes view However the icon doesn't appear in the other ones (tiles, medium, large and extra large icons) I've added 48x48p Icons as well as 24x24p Icons, with no different results.
×
×
  • Create New...