
jjjamie
Avatar/Signature-
Posts
34 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by jjjamie
-
Hi I am writing a program in which I have used reflection to obtain a MemberInfo object based on the specified method name as follows: Dim MemberInfo As MemberInfo Dim MethodName as String = "MyMethod" MemberInfo = FormClass.GetMethod(MethodName) From this MemberInfo object, I need to create a delegate to the same method. Any ideas how I would do it? Please don't say 'create the delegate using AddressOf' - I need create the method name dynamically. Many thanks :) I have just read somewhere that you can't use delegates to call arbitrary methods at run time. If that is so, is there any other way that you can dynamically add event handlers at runtime? I need something like this: Dim EventName as String = "button.click" Dim MethodName as String = "ClickMethod" AddHandler EventName, MethodName This obviously will not work!
-
I wonder if anyone can help me with a small problem... I am currently trying to output RTF files from VB.NET and I have become stuck on one thing. I am trying to work out how many lines of text I can fit onto a page based on the page size, the size of the top and bottom margins and the font size. To make sure that I could work it out right, I opened an empty Word document. The top and bottom margins were set to 2.54 cm and the paper height was 29.7cm (A4). That means that I have a working area of 24.62cm. The font size that I am working with is 24points. I converted this to centimeters using an online convcerter and it gave me 0.846666666666667cm. Here is the strange part: when I manually tested it in Word, I could fit 25 lines of text down the page, but if you divide the working area of the page (24.62cm) by the font size, it gives you 29.078!! I made sure that there was no extra line spacing in Word, just in case that was the problem. Can anyone help me with this? If I don't know how to calculate how many lines I can fit on a page, I will not be able to finish developing the report generator that I am working on. Many thanks in advance Jamie http://www.angelfire.com/az/deaflab/measure.html
-
Thanks! It works a treat! :D
-
I am trying to convert some code from VB6 to VB.NET and I have it all working apart from one line... lDate = CLng(ChkDate) ' Convert date to Number For July 20th, 2003 the above line gives 37823. Does anyone know what is the equivalent .NET code?
-
Public scope is the most visible. It makes the variables usable from both the current application and any other applications that import it. If you just want your variables visible in the current application, use the Friend modifier.
-
Does anyone know how to add a comment to a custom property in the designer so that when you select it, a description tells you how to use it?
-
Yes I do want to do something like this and I've managed to work out how to do it. All I needed to do in the end was use the StackTrace class to retrieve the previous frame and then examine it to get the MethodBase object and in turn the name of the method. Here is the code I used: Public Sub Enter(Optional ByVal Message As String = "") Dim Caller As StackFrame Dim StackTrace As New StackTrace() Dim CallerName As String Dim Indent As String 'Dim FileName As String Caller = StackTrace.GetFrame(1) CallerName = Caller.GetMethod.Name ' Get name of calling method 'FileName = Caller.GetFileName ' ** Method not yet implemented ** Indent = IndentEnter(Caller.GetMethod) If Message <> "" Then WriteLine(Indent + "Entering " + CallerName + "() <" + Message + ">") Else WriteLine(Indent + "Entering " + CallerName + "()") End If End Sub The reason I wanted to do it is because I am implementing a trace listener to log to a file when certain methods are entered and exited (in order to aid the debugging of my program). I feal this is a good method to use because I only have to disable the TRACE compilation constant to prevent the logging. Here is the code that I used for those that are interested: Imports System.IO Imports System.Reflection Imports System.Diagnostics Public Class MainTraceListener Inherits TraceListener Private m_IndentStorer As New ArrayList() Private Structure MethodIndent Dim IndentLevel As Integer Dim Method As MethodBase End Structure ' Create a log file named PROFILE.LOG Dim m_StreamWriter As New StreamWriter("PROFILE.LOG") Public Overloads Overrides Sub Write(ByVal Message As String) ' Display indentation and time only at beginning of line If NeedIndent Then m_StreamWriter.Write("[" + Now.ToString + " " + _ CStr(Now.Millisecond) + "] ") WriteIndent() End If m_StreamWriter.Write(Message) m_StreamWriter.Flush() End Sub Public Overloads Overrides Sub WriteLine(ByVal Message As String) ' Use the Write method to display an extire line Write(Message + ControlChars.CrLf) ' Next line must be indented and current time must be displayed NeedIndent = True End Sub Public Sub Note(ByVal Note As String) WriteLine("***** " + Note + " *****") End Sub Private Function IndentEnter(ByVal Method As MethodBase) As String Dim MethodIndent As New MethodIndent() Dim Indent As String If m_IndentStorer.Count = 0 Then MethodIndent.IndentLevel = 0 MethodIndent.Method = Method m_IndentStorer.Add(MethodIndent) Exit Function Else MethodIndent.IndentLevel = _ CType(m_IndentStorer(m_IndentStorer.Count - 1), _ MethodIndent).IndentLevel + 1 MethodIndent.Method = Method m_IndentStorer.Add(MethodIndent) End If Indent = Space(IndentSize * MethodIndent.IndentLevel) Return Indent End Function Private Function IndentLeave(ByVal Method As MethodBase) As String ' Search for method Dim SearchMethodIndent As MethodIndent Dim Indent As String For Each SearchMethodIndent In m_IndentStorer If SearchMethodIndent.Method Is Method Then ' Found method. Do indent Indent = Space(IndentSize * SearchMethodIndent.IndentLevel) ' Remove method indent data from arraylist m_IndentStorer.Remove(SearchMethodIndent) Return Indent End If Next End Function Public Sub Enter(Optional ByVal Message As String = "") Dim Caller As StackFrame Dim StackTrace As New StackTrace() Dim CallerName As String Dim Indent As String 'Dim FileName As String Caller = StackTrace.GetFrame(1) CallerName = Caller.GetMethod.Name 'FileName = Caller.GetFileName ' ** Method not yet implemented ** Indent = IndentEnter(Caller.GetMethod) If Message <> "" Then WriteLine(Indent + "Entering " + CallerName + "() <" + Message + ">") Else WriteLine(Indent + "Entering " + CallerName + "()") End If End Sub Public Sub Leave(Optional ByVal Message As String = "") Dim Caller As StackFrame Dim StackTrace As New StackTrace() Dim CallerName As String Dim Indent As String Caller = StackTrace.GetFrame(1) CallerName = Caller.GetMethod.Name Indent = IndentLeave(Caller.GetMethod) If Message <> "" Then WriteLine(Indent + "Exiting " + CallerName + "() <" + Message + ">") Else WriteLine(Indent + "Exiting " + CallerName + "()") End If End Sub End Class I then instantiated the class in a shared module: Module TracerObject ' Trace listener Public Tracer As New MainTraceListener() Sub New() Trace.Listeners.Add(Tracer) End Sub End Module Then, I used the tracer (in a different class) as follows: Public Sub Start() Tracer.Enter() ' Log method start ' Only start server if it is stopped If ServerState.CurrentState <> ObjectState.Stopped Then Exit Sub ' Server is now starting ServerState.ClearError() ServerState.ChangeState(ObjectState.Starting, True) Tracer.Note("Starting listener") StartListener() Tracer.Leave() ' Log method end End Sub Here is the resulting output that has been sent to the file PROFILE.LOG (along with the output of a few other methods): [07/05/2003 19:55:25 779] Entering .ctor() [07/05/2003 19:55:25 809] Exiting .ctor() [07/05/2003 19:55:28 142] Entering Start() [07/05/2003 19:55:28 152] Entering doStateChanged() [07/05/2003 19:55:28 182] Exiting doStateChanged() [07/05/2003 19:55:28 192] ***** Starting listener ***** [07/05/2003 19:55:28 192] Exiting Start() [07/05/2003 19:55:28 373] Entering doStateChanged() [07/05/2003 19:55:28 393] Exiting doStateChanged() [07/05/2003 19:55:28 423] Server queue processor started. [07/05/2003 19:55:46 649] Entering Shutdown() [07/05/2003 19:55:46 649] Entering doStateChanged() [07/05/2003 19:55:46 649] Exiting doStateChanged() [07/05/2003 19:55:46 689] Server queue processor exiting. [07/05/2003 19:55:46 699] Entering doStateChanged() [07/05/2003 19:55:46 839] Exiting doStateChanged() [07/05/2003 19:55:46 839] Exiting Shutdown() Methods markey '.ctor' are constructor methods. I would have like to have included the name of the file that the method was running from but after checking the documentation, Microsoft hasn't implemented the StackFrame.GetFileName method. I hope that this has explained what I am up to and maybe a few people might find it interesting. The code isn't up to my ideal standard because I needed a quick and dirty solution but if anyone wants me to explain anything just ask. Jamie
-
Does anyone know how to fetch the name of the previously called subroutine from code? e.g. Sub One Two() End Sub Sub Two ' Code here should print 'One' when called via 'Sub One' End Sub
-
I'm trying to get to do the same but I can't hide the window from alt-tab. Any idea how to do it?
-
Hi, Does anyone know how I can list all the threads that are running in my application from within my application? Thanks in advance
-
The easiest way is to create a subroutine that takes the ComboBox as a parameter and then modify it from there. For example in the class write... Public Sub AddComboItem(ByVal ComboBox as ComboBox, ByVal Item as String) ComboBox.Items.Add(Item) End Sub Then all you have to do is call the subroutine from Form1 (or from elsewhere within the class). Jamie
-
Sub New is protected in VB6 OXC
jjjamie replied to jjjamie's topic in Interoperation / Office Integration
How do I add a Sub New to a OCX component so that I can initialise it in .NET?! :-\ -
Sub New is protected in VB6 OXC
jjjamie replied to jjjamie's topic in Interoperation / Office Integration
I've tried that. VB6 doesn't understand it. I have also tried: Public Sub Class_Initialize() End Sub I've no idea at all what to do!!! :confused: -
Hi, I am trying to use a VB6 OCX file in .NET but when I try to create the object in .NET it says: 'Private Sub New()' is not accessible in this context because it is 'Private' The first thing I checked in the VB6 file was whether there was a Private Sub New, but there was no Sub New at all. I then tried adding a Sub New, but VB wouldn't accept the line. Can anyone help me as to what to do? Thanks, Jamie
-
Hi, There is probably a really obvious answer to this question but I can't see it. I am encrypting a file using a private key at the server and then sending the file to a client where it is decrypted using the same key. The problem is that there are security risks if I use the same key for every file I encrypt. I can easly generate a random key for each file, but how does the client know what the key is? The obvious answer would be to send the key to the client but it could be intercepted and used to decipher the file. Any ideas? Thanks in advance :) Jamie
-
Somewhere in the framework there is a function to repeat a given character a specified amount of times and return a string but I can't seem to find it. Does anyone know what this function is called? It's really frustraiting because I know it exists!
-
Does anyone know a way that I can make Outlook's main screen visible through automation? I can do it for Word by setting the application's visible property to True. Here's the code that I use to make Word visible... Dim oWord As Word.ApplicationClass oWord = CreateObject("Word.Application") oWord.Visible = True oWord.Activate() I have tried doing the same thing for Outlook but there is not a Visible property! Does anyone know what I should do?
-
divil, you are a funky monkey :D
-
Hi Meanie, Did you ever figure out how to create a shortcut using VB.NET? I would sure like to know.
-
This thread has brought a smile to my face. I remember the times when I had similar problems (oooooooh the days! :D)
-
I have just read this very helpful post and I have a quick question - how would you go about using a Data Source, rather than a connection string to connect to the database?
-
.... or why not write your own installer? It can't be that hard!
-
Just use notepad to edit .ini files.
-
I posted a lengthy reply to this but it hasn't been copied across from the old forum (http://www.visualbasicforum.com). Thanks for your help guys. [edit]Here you go - divil[/edit] Thanks guys :) I was looking at the source code and this is what I found: Imports System.Windows.Forms ' This class is needed because the ' System.Windows.Forms.Design.FolderNameEditor.FolderBrowser is Protected and thus ' is not accessible in this context. Deriving a Public class from it enables you to ' use the dialog in your code. Public Class FolderBrowser Inherits System.Windows.Forms.Design.FolderNameEditor Public Shared Function ShowDialog() As String Dim fb As New FolderBrowser() fb.Description = "Select a Directory to Scan" fb.Style = Design.FolderNameEditor.FolderBrowserStyles.RestrictToFilesystem fb.ShowDialog() Return fb.DirectoryPath End Function End Class Why have Microsoft made the class protected? They have given no documentation on the FolderBrowser class. In the help files it says 'The FolderNameEditor.FolderBrowser type supports the .NET Framework infrastructure and is not intended to be used directly from your code.'. I find this strange us I have seen a lot of people on forums asking how to create one. (Now I know the answer!) Cheers.
-
I have been searching the net high and low but I can only find examples for C#. Does anyone know of a way I can display a select folder dialog without having to make my own?