|
We live and learn, I seem to have done more of the former than the latter.
I chose to pass as an Object because the IsNumeric function that THE ANZAC originally mentioned does so and because it enabled one function to be broadly applied in a similar way - I lack the underpinning knowledge that would have told me that 'Passing the parameter as an Object isn't recommended'.
However, now I do know this and, should the need ever arise in my code, I will follow the overloaded versions route.
Thank you
PS I suppose that including IsNumeric in my function or just using it in general is undesirable for the same reasons?
-- modified at 11:54 Sunday 17th September, 2006 - I spotted a typo
|
|
|
|
|
Passing as Object causes a value type to be "boxed" inside a reference type and stored in the garbage collected heap. That reference type is an instance of an Object class. So, instead of just pushing the value onto the call stack, you're allocating and constructing a new object, copying the value into it, then the address of the Object is pushed onto the call stack. This takes about 20 times longer than just pushing the actual value type onto the stack or making a simple assignment, like a=10 .
Once the Object is passed, there is an unboxing penalty. This time, the value has to be copied out of the Object to be used in the IsNumeric, CInt and CDbl functions. This is because you can't pass an address to a reference type to a function that is expecting a value type. This unboxing allocates a new local value type and copies the value in the Object to it. This also takes time - I think it's about half as much as boxing, but to compared to pushing and popping a value on/off the stack, it's still an eternity.
Now, the saving grace in your code is that IsNumeric, CInt and CDbl are all compiled in-line. This means that in the compiled code, there is a performance benefit from not having to push values onto the stack, making a JMP to the function code, popping those values off the stack, running the function code, pushing the return value back on the stack, returning to the caller and, finally, popping the return values off the stack.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I make a control in VB.Net and i want to use it in Internet Explorer.
This control connect a socket in special port on a server.
My control in local exe is ok but when i use it in IE i have an error about system.net.socketpermission
I add this lines in my code
Dim IPermSocket As New System.Net.SocketPermission(Security.Permissions.PermissionState.Unrestricted)
IPermSocket.AddPermission(Net.NetworkAccess.Connect, Net.TransportType.All, strIP, System.Net.SocketPermission.AllPorts)
IPermSocket.Demand()
and where cursor is on IPermSocket.Demand() i have the same error: autorisation failed
Is it possible to help me
|
|
|
|
|
Hello,
I am doing a application that will monitor up to 10 different tasks. Each task will start, run, and stop at different times.
I have to display each task in a label. I have 2 buttons start and stop.
l enter the task number in the text box and press start, I can do this will all the tasks. When l want to stop, I will enter the task number in the text box and press stop.
So I can start and stop any task and see the time of all the tasks that are currently running.
I have done this for 1 stopwatch object, but not sure how to create an array and monitor all the task the are currently running at the same time.
Here is my code so far so you can see what I am doing.
Start button
<br />
Dim taskID As String<br />
taskStopWatch.Start()<br />
Stop button
<br />
Dim taskID As Integer<br />
taskStopWatch.Stop()<br />
<br />
Private Sub tmrTaskLog_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrTaskLog.Tick<br />
Dim ts As TimeSpan<br />
<br />
If (taskStopWatch.IsRunning) Then<br />
ts = taskStopWatch.Elapsed<br />
taskDuration = String.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds)<br />
TimeTaskID.Text = taskDuration<br />
End Sub<br />
Thanks very much in advance
Steve
|
|
|
|
|
Create a HashTable and you can add all of your StopWatch objects to it. Ideally, you'd want to create a class that can track one process, complete with it's own StopWatch, and have each instance of that class watch one process. You can then add those to a HashTable to keep track of them all.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi
How can i maximize the printpreviewdialog during runtime.
Thanxs
quinton.nel
|
|
|
|
|
The PrintPreviewDialog doesn't expose any methods to do this. You can either use it's .SetDesktopBounds() method to set the size as large as you want, or you'll have to go through Win32 API calls to find the window handle and send an appropriatly formatted window message to the form to get it to maximize itself.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi all,
I am doing an desktop application in vb.net. For forms i have used the
property formborderstyle=none. So what happens when i minimize the form into
the task bar,and again right click on the form i could not the maximize or
minimize or restore. So please let me know how to do this.
regards
ravindra
|
|
|
|
|
Since you're form no longer has a control box in the now non-existant title bar, you don't have Minimizie, Maximize and Restore in the context menu either. But, just clicking on the icon in the TaskBar should restore the form. If not, the solution to restoring the context menu on the TaskBar is surprisingly easy.
Handle the form's Resize event. In that handler, check to see what the WindowState of the form is. If it's Minimized, set the FormBorderStyle to anything but None, otherwise reset it to None.
Private Sub Form1_Resize(blah, blah) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
Else
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
End If
End Sub
Now, there's a small problem that develops. Changing the FormBorderStyle like this also changes the size of the form. When it's restored, the form shows up smaller than before it was minimized. To get around this, set the form's MinimumSize property to the current size of the form BEFORE the form is minimized by your code:
Private Sub Button1_Click(blah, blah) Handles Button1.Click
Me.MinimumSize = Me.Size
Me.WindowState = FormWindowState.Minimized
End Sub
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi all,
Using StreamReader I opened a text file and reading line by line. In that I want replace the text say (File "604116mg_c.abc") to (File "604116g.abc") and update back in the text file. Please suggest me how to solve
sonj
|
|
|
|
|
You can not update part of a text file. You have to rewrite the entire file.
---
b { font-weight: normal; }
|
|
|
|
|
Hi
I've created a app for monitoring Internet access on workstations. I've created the project so that the main form's visible = false, when it detects the iexplore process it sets the visible = true and prompts the user for a session password. The problem is that my apps process is running in the Task Manager and the user can stop it from there. Thus dissabling my app.
I want to create a service that runs in the background and then starts my app to prompt user for session password. Is this possible and how can I implement it. Should I create a seperate windows service that starts my app or should I incorporate the service into my app.
quinton.nel
|
|
|
|
|
Hi all,
I have a problem with file List box,
I have a code like this
Private Sub Command1_Click()
Form1.FileListBox.Path = "d:\temp"
Form1.FileListBox.Pattern = "*.lnk"
MsgBox Form1.FileListBox.List(0)
End Sub
Suppose I have a shortcut d:\temp\hai.lnk
When I click on Command1 Button
Then "MsgBox Form1.FileListBox.List(0)" will get the value "d:\temp\hai.lnk"
Then I have deleted "hai.lnk" Manually and Again Click on Command1 Button,but "MsgBox Form1.FileListBox.List(0)" again showing "d:\temp\hai.lnk"
How can I Rectify it.
Please Help Me
Thanks IN Advance
George K Jolly
|
|
|
|
|
After you delete the file, call the Refresh method on the FileListBox:
FileListBox.Refresh()
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
Hi Members,
I'm stuck in a project where I need to connect a scanner to a program(VB.net),i.e., on click of a button the scanner should start functioning.
How can I achieve that?
Regards,
Member.
|
|
|
|
|
TWAIN. I think there's a .NET TWAIN driver here on CP, just search for it. Either way, you need a TWAIN implimentation to talk to scanners.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks i'll try to search and implement it.
|
|
|
|
|
i want to open doc file using vb.net. word doc should open. then i want to convert it into pdf.
sai
|
|
|
|
|
Sounds like you need to look into either .NET or COM interop with Office. IT depends on what versions you want to support, the COM ones are always there, the .NET ones I'm not sure when they came out. Creating PDF, there's a couple of projects on source forge that do it, and plenty of commercial options.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
How is it possible to retrieve the WMI property description field with VB 2005 / .net?
Example: for the value
<br />
root\CIMV2:Win32_PerfRawData_SMTPSVC_SMTPServer\MessageBytesTotal<br />
the Property Description is
"The total number of bytes sent and received in messages."
With this code I can get the value of "MessageBytesTotal", however how to get the description into a string variable?
<br />
Dim mc As ManagementClass<br />
Dim menge As ManagementObjectCollection<br />
Dim mo As ManagementObject<br />
Dim strTmp As String<br />
<br />
Try<br />
mc = New ManagementClass("\\MeinServer\root\cimv2:Win32_PerfRawData_SMTPSVC_SMTPServer")<br />
<br />
menge = mc.GetInstances()<br />
<br />
For Each mo In menge<br />
strTmp = mo("MessageBytesTotal")<br />
Next<br />
mc.Dispose()<br />
Return strTmp<br />
Catch ex1 As Exception<br />
console.writeline (ex1.Message)<br />
End Try<br />
Which code do I need to add to get success?
I have tried this here, but it does not work:
<br />
strTmp2 = mo("Description")<br />
Thanks for any hint and feedback!
|
|
|
|
|
AFAIK, there is no way to retrieve the property/method/event descriptions in WMI. You can retrieve the list of properties/methods, and their data types, but not the descriptions.
The only place I know to get that information is in the MOF files that were used to compile the WBEM classes. It would involving parsing those file to get the info. I don't know of an API to do it for you.
I could be wrong though...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
If you are realy into a bit of work, you could generate your own managed class using mgmtclassgen.exe and just add your own custom property for it.
Read on... for instructions:
The following command generates a managed class from Win32_PerfRawData_SMTPSVC_SMTPServer
mgmtclassgen.exe Win32_PerfRawData_SMTPSVC_SMTPServer /n root\cimv2 /l VB /p c:\SMTPServer.vb
The tool writes the managed class to the source file at c:\SMTPServer.vb, using the ROOT.CIMV2.Win32 namespace.
Add the file to your project.
Add the following to SMTPServer.vb somewhere near "Public ReadOnly Property MessageBytesTotal()" (about line # 2509 in my file.):
<Browsable(True), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), _
Description("Description of MessageBytesTotal.")> _
Public ReadOnly Property MessageBytesTotalDescription() As String
Get
Return "The total number of bytes sent and received in messages."
End Get
End Property
And/Or whatever you want the property(s) to be..
And/Or Your own overloads ect..
Have fun..
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfmanagementstronglytypedclassgeneratormgmtclassgenexe.asp
-- modified at 1:47 Friday 15th September, 2006
|
|
|
|
|
Hi,
Does anyone know how to send a pdf file to a printer without using Acrobat.
|
|
|
|
|
Without some component to load, parse and render the document, you can't send a PDF to the printer. It'll just print tons a garbage.
TallComponents[^] has a couple of things that might work for you.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|