Jump to content
Xtreme .Net Talk

Shamil

Avatar/Signature
  • Posts

    28
  • Joined

  • Last visited

Everything posted by Shamil

  1. Have a look at ASP.NET Calendar Control from Infragistics http://www.infragistics.com/products/schedule.asp Shamil
  2. Hi All, Has anybody seen the info how to implement the subj? TIA, Shamil
  3. Here is even more tricky solution with two implemeneted Interfaces and full control on Interface methods DispIds: Imports System.Runtime.InteropServices <Guid("D9870F22-4CA5-4567-96DA-6A6CAA541F6D")> _ Public Interface ICAllMeFromCOM1 <DispId(1)> Sub MessageBox(ByVal vstrMsg As String) <DispId(2)> Function GiveMeYourName() As String <DispId(3)> Function GetMyRef() As Object End Interface <Guid("780B6E92-AF98-48b6-8C0B-2832C86F2DB7")> _ Public Interface ICallMeFromCOM2 <DispId(503)> Sub testMessage(ByVal vstrMsg As String) End Interface <Guid("AE2F4135-D660-453a-B638-373691194EB6")> _ Public Class TestClass Implements ICAllMeFromCOM1 Implements ICallMeFromCOM2 Public Sub New() MyBase.New() End Sub <DispId(1)> Public Sub MessageBox(ByVal vstrMsg As String) _ Implements ICAllMeFromCOM1.MessageBox MsgBox("Test Message = " + vstrMsg) End Sub <DispId(2)> Public Function GiveMeYourName() As String _ Implements ICAllMeFromCOM1.GiveMeYourName GiveMeYourName = MyName() End Function <DispId(3)> Public Function GetMyref() As Object _ Implements ICAllMeFromCOM1.GetMyRef GetMyref = Me End Function <DispId(503)> Public Sub myMessage(ByVal vstrMsg As String) _ Implements ICallMeFromCOM2.testMessage MsgBox("ICallMeFromCOM2.testMessage: " + vstrMsg) End Sub <ComVisible(False)> Public Function MyName() As String MyName = Me.GetType().FullName End Function <ComRegisterFunction()> Public Shared Sub OnRegistration(ByVal T As Type) MsgBox(T.FullName & " is being registered in COM!") End Sub End Class In Vb6 (or any other COM application) this class above can be used e.g. like this: Dim obj As New TestClass Dim I2 As ICallMeFromCOM2 obj.MessageBox "Test" Set I2 = obj I2.testMessage "Test" Shamil
  4. Here is a solution based on info from MSDN and other sources: Test class: ======== Imports System.Runtime.InteropServices <ComClass(TestClass1.ClassId, TestClass1.InterfaceId, TestClass1.EventsId)> _ Public Class TestClass1 #Region "COM GUIDs" Public Const ClassId As String = "FA16F4E8-69AC-4fd1-84BA-770674DFFFAE" Public Const InterfaceId As String = "A041238E-7C8A-437d-A18B-3A18D09E7B60" Public Const EventsId As String = "691E110D-C2FD-4eda-8801-A5246169A4F3" #End Region Public Sub New() MyBase.New() End Sub <DispId(1)> Public Sub MessageBox(ByVal vstrMsg As String) MsgBox("Message from VB.Net component - " & vstrMsg) End Sub <DispId(2)> Public Function GiveMeYourName() As String GiveMeYourName = MyName() End Function <ComVisible(False), DispId(3)> Public Function MyName() As String MyName = Me.GetType().FullName End Function <ComRegisterFunction()> Public Shared Sub OnRegistration(ByVal T As Type) MsgBox(T.FullName & " is being registered in COM!") End Sub End Class AssemblyInfo.VB ============ Imports System.Reflection Imports System.Runtime.InteropServices <Assembly: AssemblyTitle("CCW Test")> <Assembly: AssemblyDescription("Call VB.NET Component from COM")> <Assembly: AssemblyCompany("Test")> <Assembly: AssemblyProduct("CCW Test DLL")> <Assembly: AssemblyCopyright("Public Domain")> <Assembly: AssemblyTrademark("")> <Assembly: CLSCompliant(True)> <Assembly: Guid("DB955828-2239-4747-A08C-5C1F9F574AFA")> <Assembly: AssemblyVersion("1.0.*")> <Assembly: ComVisible(True)> '<Assembly: ClassInterface(ClassInterfaceType.AutoDual)> <Assembly: AssemblyKeyFileAttribute("<type you full path to snk file here>.snk")> Create Assembly Strong Name .snk file =========================== sn -k myKey.snk Create class library and build solution from VS.NET IDE ====================================== (use of VS.NET IDE is obvious) Register assembly and export type library ============================== regasm MyCCWDll.dll /tlb:MyCCWDll.tlb Install Assembly in the global Assembly cashe ================================ gacutil /if MyCCWDll.dll Now you can set reference from COM applications to MyCCWDll.tlb and use its exposed objects via early binding or you can use CreateObject(...) to create instances of the objects exposed from MyCCWDll.dll and use them with late binding... Maybe this above isn't an optimal way to make CCW Dll but it worked for me... HTH, Shamil P.S. The procedure to make CCW components visible to COM should work automagically in theory fro VS.NET IDE if you set "Register for COM interop" checkbox in project's configuration settings but it failed for me...
  5. VB.NET: Yes, VB.NET managed classes can be called from COM (like MS Word 2000) applications - COM Callable Wrappers (CCW) are used for that - here is an article describing this technology: http://www.codeproject.com/dotnet/COM_DOTNET_INTEROP.asp Here is a sample code: http://www.dotnetextreme.com/articles/ccwrcw.asp Here is a discussion of the CCW subject with some more information how to build visible to COM apps .NET components... HTH, Shamil
  6. VB6: You have to put your class into ActiveX Dll and set its Instancing property to MultiUse or GlobalMultiuse. Then you compile your ActiveX Dll and set a reference to it or just use CreateObject(...) to create instances of your class... HTH, Shamil
  7. Here it's: http://www.informit.com/isapi/product_id~%7BA1CE8908-9877-4B24-9B2C-BD7B836490D6%7D/element_id~%7B8B2060F0-4E20-489D-8B39-2890BAC99CA0%7D/st~%7BEA7C8D03-4995-402D-B085-06E000F897B8%7D/content/articlex.asp HTH, Shamil
  8. Shamil

    Method name

    Phylum, You can use this code to solve first part of your task: Dim strProcName As String Dim strClassName As String Dim strAssName As String strAssName = System.IO.Path.GetFileName( _ System.Reflection.Assembly.GetExecutingAssembly().Location()) strProcName = System.Reflection.MethodBase.GetCurrentMethod().Name strClassName = Me.GetType().ToString HTH, Shamil
  9. Robby, This is free WebHosting where anybody can install and test ready to use (Shopping Cart, Portal, Community etc.) and their own ASP.NET applications. I've used it today and I've found it very good. Shamil
  10. Mark, Here is code sample, which may help to solve your task: Public Sub CopyFormat( _ ByRef rwbkDst As Excel.Workbook, _ ByVal vlngDstColNum As Int32, _ ByRef rwbkSrc As Excel.Workbook, _ ByVal vlngSrcRowNum As Int32, _ ByVal vlngSrcColNum As Int32) ' Copy format of rwbkSrc.Worksheets(1).Cell(vlngSrcRowNum,vlngSrcColNum) to ' entire column rwbkDst.Column(vlngDstColNum) rwbkSrc.Worksheets(1).Cells(vlngSrcRowNum, vlngSrcColNum).Copy() rwbkDst.Worksheets(1).Columns.Item(vlngDstColNum).PasteSpecial( _ Paste:=Excel.Constants.xlFormats, _ Operation:=Excel.Constants.xlNone, _ SkipBlanks:=False, _ Transpose:=False) End Sub HTH, Shamil
  11. Have a look at: http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20655227.html and http://msdn.microsoft.com/msdnmag/issues/01/07/vbnet/default.aspx HTH, Shamil
  12. <<< I was talking about making applications, write code ...what is your suggestions on this ? >>> You may try this: http://europe.webmatrixhosting.net/ HTH, Shamil
  13. This doesn't work for you? Dim strFullPath As String = "c:\temp\testDir" ' hide dir System.IO.File.SetAttributes(strFullPath, FileAttributes.Hidden) ' unhide dir System.IO.File.SetAttributes(strFullPath, FileAttributes.Normal) It works well here. Shamil
  14. Ben, Here is the function, which should help you (tested with MS Office 2000 only): Public Function MsWordFullPath(ByVal vlngVersion As Long) As String ' Given MS Word version number returns its FullPath if it's installed, empty string ("") otherwise ' Note: MS Office versions supported: 8 and above Dim objRegKey As Microsoft.Win32.RegistryKey Dim strKeyName As String Dim strValueName As String Dim strValue As String strKeyName = "SOFTWARE\\Microsoft\\Office\\" & vlngVersion.ToString & ".0\\Common\\InstallRoot" Select Case vlngVersion Case Is < 8 strValueName = "" strValue = "" Case 8 strValueName = "OfficeBin" Case Is > 8 strValueName = "Path" End Select If Microsoft.VisualBasic.Len(strValueName) > 0 Then objRegKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(strKeyName, False) If (objRegKey Is Nothing) Then strValue = "" Else strValue = objRegKey.GetValue(strValueName) If Microsoft.VisualBasic.Len(strValue) > 0 Then If Microsoft.VisualBasic.Right(strValue, 1) <> "\" Then strValue = strValue & "\" strValue = strValue & "winword.exe" If Not System.IO.File.Exists(strValue) Then strValue = "" End If objRegKey.Close() End If End If Return (strValue) End Function HTH, Shamil
  15. Ben, Sorry, I did post wrong registry keys (form MS Access instead of MW Word) - here how they should have been posted: For MS Word versions starting 9.0 (2000) you can check the existence of the registry key: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\<MS Office version>\Word\InstallRoot] e.g. for MS Word 2000 this will be the key: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\9.0\Word\InstallRoot] For MS Office 97 I think you've to check the existence of the system registry value BinDirPath under [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\8.0] read this value - e.g. I've it here as "BinDirPath"="D:\\Program Files\\MSOffice\\97\\Office" and then concatenate it with winword.exe - it will be: D:\Program Files\MSOffice\97\Office\winword.exe for the sample value above and see if this file exists of not. HTH, Shamil
  16. Ben, For MS Word versions starting 9.0 (2000) you can check the existence of the registry key: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\<MS Office version>\Access\InstallRoot] e.g. for MS Word 2000 this will be the key: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\9.0\Access\InstallRoot] For MS Office 97 I think you've to check the existence of the system registry value BinDirPath under [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\8.0] read this value - e.g. I've it here as "BinDirPath"="D:\\Program Files\\MSOffice\\97\\Office" and then concatenate it with winword.exe - it will be: D:\Program Files\MSOffice\97\Office\winword.exe for the sample value above and see if this file exists of not. HTH, Shamil
  17. Alfredo, Here is the info from MS KB: Tips and Tricks: Building Microsoft Office Add-ins with Visual C# .NET and Visual Basic .NET http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchtipstricksbuildingmicrosoftofficeadd-inswithvisualcnetvisualbasicnet.asp HTH, Shamil
  18. Hi All, I just wanted to inform you about error I found and which I don't have clear explanation to: 1. This code doesn't work Dim doc as Word.Document dim rng as Word.Range Dim lngStart As Long Dim lngEnd As Long lngStart = 3 lngEnd = 10 rng = doc.Range(lngStart, lngEnd) and results in error: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in MSWordAutomationVBNet.exe Additional information: Type mismatch 2. This code works well: Dim doc as Word.Document dim rng as Word.Range Dim lngStart As Long Dim lngEnd As Long lngStart = 3 lngEnd = 10 rng = doc.Range(CType(lngStart, Integer), CType(lngEnd, Integer)) Explicit cast to Integer makes the difference but it's unclear why it's needed for a function with a signature: Public Overridable OverLoads Function Range([byref Start as Object],[byRef End as Object]) as Word.Range Anybody and clues? Shamil
  19. Conrad, This code works, tested: Public Function CopyPage(ByRef rdocTo As Word.Document, _ ByRef rdocFrom As Word.Document, _ ByVal vlngPageFrom As Long, _ Optional ByVal vfInsertPageBreakBeforeCopy As Boolean = True) As Long ' Add page to the end of the target document ' ' Arguments: ' rdocTo - target document ' rdocFrom - source document ' vlngPageFrom - source page number ' vfInsertPageBreakBeforeCopy - if =True - insert PageBreak mark before copied page ' Dim rngPageToCopy As Word.Range ' range of the page to copy Dim rng As Word.Range ' temporary range Dim intPageStart As Integer ' first char position of the page to copy Dim intPageEnd As Integer ' last char position o fthe page to copy ' check that source page number >=1 If vlngPageFrom < 1 Then CopyPage = 1 ' source page number should be >=1 Exit Function End If ' check that page number corresponds to a page in the source document rngPageToCopy = rdocFrom.GoTo(what:=Word.WdGoToItem.wdGoToPage, which:=Word.WdGoToDirection.wdGoToAbsolute, Name:=CStr(vlngPageFrom)) rng = rdocFrom.GoTo(what:=Word.WdGoToItem.wdGoToPage, which:=Word.WdGoToDirection.wdGoToAbsolute, Name:=CStr(vlngPageFrom - 1)) If (rngPageToCopy.Start = rng.Start) And (vlngPageFrom > 1) Then CopyPage = 2 ' source page doesn't exist Exit Function End If ' set and copy the contents of the source page into clipboard intPageStart = rngPageToCopy.Start intPageEnd = rngPageToCopy.Start + PageLength(rdocFrom, rngPageToCopy, vlngPageFrom) rngPageToCopy = rdocFrom.Range(intPageStart, intPageEnd) rngPageToCopy.Copy() ' set the position in the target document to copy the source rng = rdocTo.Content If (rng.StoryLength > 1) And (vfInsertPageBreakBeforeCopy = True) Then ' insert PageBreak mark at the of the target document if it has any text rng.MoveStart(Word.WdUnits.wdStory, 1) rng.InsertBreak(Word.WdBreakType.wdPageBreak) rng = rdocTo.Content End If rng.MoveStart(Word.WdUnits.wdStory, 1) ' paste from clipboard the content of the source page rng.Paste() CopyPage = 0 ' SUCCESS End Function Private Function PageLength(ByRef rdoc As Word.Document, ByRef rrngPage As Word.Range, ByVal vlngPageNo As Long) As Long ' return pagelength of a page. ' note: pageLength includes PageBreak mark if the page vlngPageNo is not the last page Dim rng As Word.Range rng = rdoc.GoTo(what:=Word.WdGoToItem.wdGoToPage, which:=Word.WdGoToDirection.wdGoToAbsolute, Name:=CStr(vlngPageNo + 1)) If rng.Start > rrngPage.Start Then ' this isn't the last page PageLength = rng.Start - rrngPage.Start - 1 ' no PageBreakMark Else ' this is the last page PageLength = rng.StoryLength - rrngPage.Start End If End Function HTH, Shamil P.S. If you find a solution without Clipboard usage please send it to me.
  20. Richard, What you see in internal representation of MS Excel workbook (or its link - did you insert a link to MS Excel workbook into OLE field?). Please clarify more what is your task? - it may happen that you will not need to store MS Excel workbooks in MS Access tables - this way you "bloat" MS Access database and there should eb a clear reason to do that or not. Shamil
  21. Lucian, Here is an example in VB.NET: Dim oldCI As System.Globalization.CultureInfo = _ System.Threading.Thread.CurrentThread.CurrentCulture System.Threading.Thread.CurrentThread.CurrentCulture = _ New System.Globalization.CultureInfo("en-US") Dim wapp As Word.Application Dim wdoc As Word.Document Dim dbe As DAO.DBEngine Dim dbs As DAO.Database Dim rst As DAO.Recordset Dim strDbFullPath As String Dim strText As String wapp = New Word.Application() wapp.Visible = True wdoc = wapp.Documents.Add strDbFullPath = "c:\temp\testDb.mdb" dbe = New DAO.DBEngine() dbs = dbe.OpenDatabase(strDbFullPath) rst = dbs.OpenRecordset("tblTest", DAO.RecordsetTypeEnum.dbOpenSnapshot) While Not rst.EOF strText = "My name is " & rst.Fields("Name").Value & _ " and I am " & rst.Fields("Function").Value & " in this company." With (wapp.Selection) .TypeText(strText) .TypeParagraph() rst.MoveNext() If Not rst.EOF Then .InsertBreak(Type:=Word.WdBreakType.wdPageBreak) End With End While dbs.Close() wdoc.SaveAs("c:\temp\doc1.doc") Dim idoc As Word._Document idoc = wdoc idoc.Close() Dim iapp As Word._Application iapp = wapp iapp.Quit() wapp = Nothing GC.Collect() System.Threading.Thread.CurrentThread.CurrentCulture = oldCI Do you want it translated to C#? HTH, Shamil
  22. Problem solved using the information from http://support.microsoft.com/?kbid=320369 Shamil
  23. I tested the code it works. The problem with Interop.Excel.Dll solved using info from http://support.microsoft.com/?kbid=320369 - I just added before the code: ' save default culture information Dim oldCI As System.Globalization.CultureInfo = _ System.Threading.Thread.CurrentThread.CurrentCulture System.Threading.Thread.CurrentThread.CurrentCulture = _ New System.Globalization.CultureInfo("en-US") and after the code: ' restore default culture information System.Threading.Thread.CurrentThread.CurrentCulture = oldCI HTH, Shamil
  24. GC.Collect() solves the trouble. Sorry for bothering you with my silly question. Shamil
  25. Hi All, I'm getting the following runtime error while trying to set .Visible property to True of successfully created instance of MS Excel: <<< An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in WindowsApplication3.exe Additional information: Old format or invalid type library. >>> I'm automating MS Excel 2000 and as far as I see the reference is set correctly to "Microsoft Excel 9.0 Object Library" and to "Microsoft Office 9.0 Object Library".. the Interop assemblies I have locally in my projects' obj subforlder are the following: Interop.Excel.dll 19.03.1999 20:00 942080 Interop.Office.dll 23.02.2000 02:33 155648 As far as I understand they are generated automatically by VS.Net based on MS Excel and MS Office .OLBs, which I set references to. Why they don't work is a real puzzle for me... Any solution anybody? TIA, Shamil
×
×
  • Create New...