|
Please do not post in two forums, with the same question. Very rude.
Select which forum you feel is most appropriate and post there, just there.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
I want to create log for both success and failure of transaction in database and not only for exceptions(errors)
In Enterprise Library, Can i do logging in case of exceptions only?
Thanks
modified on Thursday, July 30, 2009 3:20 AM
|
|
|
|
|
Stick your logging into the finally block
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You mean using enterprise library I can do the logging out of catch block also?
Can u please provide me link for the same? Actually i am searchin for the articles and everywhere logging is done in catch block only and i think it is for exceptions only
|
|
|
|
|
It really isn't all that mysterious:
'Dim variables that you want to pass to the Catch or Finally clauses here,
'outside the Try Catch Finally block.
Try
'Your transaction takes place here
'Monitor any return value from your transaction (rows affected for example)
'and log success or failure based on the outcome here.
'Or if no errors occur you can simply log success here
Catch ex As Exception
'if an error occurs log the error here
Finally
'if you want to log something, no matter what happens, do it here.
End Try
My advice is free, and you may get what you paid for.
|
|
|
|
|
Please confirm that the code is also for logging using Enterprise library.
Also can u provide a sample code link that tells that the logging in Enetrprise library can be done in any part of the function?
|
|
|
|
|
Having no experience with Enterprise Library myself, I would guess something like:
Dim logEntry As LogEntry
Try
'Your transaction takes place here
LogEntry = New LogEntry()
logEntry.EventId = 100
logEntry.Priority = 2
logEntry.Message = "Success or failure"
logEntry.Categories.Add("Trace")
logEntry.Categories.Add("UI Events")
Logger.Write(logEntry)
'Or
LogEntry = New LogEntry()
logEntry.EventId = 100
logEntry.Priority = 2
logEntry.Message = "Success"
logEntry.Categories.Add("Trace")
logEntry.Categories.Add("UI Events")
Logger.Write(logEntry)
Catch ex As Exception
LogEntry = New LogEntry()
LogEntry = New LogEntry()
logEntry.EventId = 100
logEntry.Priority = 2
logEntry.Message = "Error"
logEntry.Categories.Add("Trace")
logEntry.Categories.Add("UI Events")
Logger.Write(logEntry)
Finally
LogEntry = New LogEntry()
logEntry.EventId = 100
logEntry.Priority = 2
logEntry.Message = "Anyway"
logEntry.Categories.Add("Trace")
logEntry.Categories.Add("UI Events")
Logger.Write(logEntry)
End Try
My advice is free, and you may get what you paid for.
|
|
|
|
|
I am doing in window aplication.
Got teh folowing crash by execution the code provided by you.
The type initializer for 'Microsoft.Practices.EnterpriseLibrary.Logging.Logger'
threw an exception.
I am uisng the following Dll reference.
Microsodt.Practices.EnterpriseLibrary.Common
Microsoft.Practise.EnterpriseLibrary.Logging
Is there anything that i need to do in addition to the above said
|
|
|
|
|
Adapt your code a little to include MsgBox(ex.ToString) in the Catch clause.
It will tell you in much more detail what the error is, and on which line it happened.
My advice is free, and you may get what you paid for.
|
|
|
|
|
hi,
i have an application which will copy an image file from clipboard to Image.Text in vb6. now, i want it to try in vba and has error which is run-time error '424'. so what i did is i add reference library in tools. and still the same.
in vb6 this will work.
Me.Image1.Picture = Clipboard.GetData(vbCFMetafile)
but, in vba
Me.Image1.Picture = Clipboard.GetData(vbCFMetafile) => error here
my question is what vba equivalent of
Clipboard.GetData(vbCFMetafile)
thanks in advance.
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
Here[^] is the answer you need.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
thank you so much for the link and it helps me a lot.
i found out in the link that it cannot get data from clipboard only text, right? what i mean is that
(vbCFMetafile) is an image file.
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
My pleasure! I think what you need is this[^].
Good luck!
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Sir i need help regarding restricting of loading of new form unless my form which is open is closed. For example i have 2 forms form1 and form2 in MIDI.
If form 1 is open i want to restrict user to open form 2 unless form 1 is close
Parag
|
|
|
|
|
You can use a Global boolean which you will set upon form opening and reset upon form closing.
In each form's Load event you can check the boolean: if it's not set, you can proceed opening the form and set it, if it's already set you can close the form.
I don't think VB6 has a more elegant way of doing this. :P
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Hi to all
i would like to know about some VBA and excel. I would like to create a form and i would like to use excel as my database. How am i suppose to code it and update the "database". Before updating the database i have a Txt file from my TCS system as it only generate txt file. In this file there are lots of space, comma and semicolon. therefore the code need to delimite the space, comma as well as semicolon. how am i suppose to do it?? besides updating, in the form i need to read the data as well. so how to read the data from the database, maybe is it like C# SQl where they is a need of some store procedure. and for some part i would like to read selected column. once again how am i suppose to code thanks
once again thanks my dear friends
Warm Regards
Veon
|
|
|
|
|
It sounds like you are maybe confusing terms. Your TCS system (whatever that is) is apparently your database. In other words, the TCS system holds the data that you are working with.
What is it that you actually need to do with the data from the text file that the TCS system puts out? Do you just need to create readable reports, or do you need to manipulate the data, and feed it back into the TCS system, or what?
Generally speaking Excel should be used to display data, and perhaps make some calculations based on that data. As a "database", it is not the ideal solution.
You would be much better off downloading Visual Studio Express 2008 from Microsoft (it's free), which includes a simple database, and offers much better tools to do what it sounds like that you need to do. It allows you to program in C++, C#, JAVA, and VB, so you will also be able to find plenty of tutorials and other helpful articles on the internet.
My advice is free, and you may get what you paid for.
|
|
|
|
|
hi my dear friend
thanks for ya advice, maybe we could discuss this issuse and come out with a solution .ok actually i'm doing a system for company and it has a system (TCS system) that links to other station where this system will catch the sales data from all the station. This TCS system is at HQ where we will generate the data into text file as this is an old school system which is still using MDOS. so currently they will just manually input the txt file to excel and process it. therefore its very time consuming. so i'm trying to create a software to help them generate their reports as well as other things related to the Txt file faster, easier and user friendly hope to hear from you
Warm Regards
veon
|
|
|
|
|
Okay, so first of all you need to automatically convert a text file to Excel.
But I am still not entirely clear on what it is that you need to do with the data once you put it in Excel. Or is converting the text file to Excel really the only problem?
My advice is free, and you may get what you paid for.
|
|
|
|
|
hi
Besides converting there is still other problems. i'm still wondering what to use to programe this system. Anyway Once i get the data into excel it will become my "database", the current situation is that everymonth this data from all the outlet would be like 10000 Rows in excel and my staff need to manually input using privot table to generate the total sales for stations. besides that the manager would also like to view the turnover as compare to last year by Q1, Q2,Q3, Q4 ,H1,H2 or a year. from the report maybe it could generate graphs or chart for a better view.
thanks
veon
|
|
|
|
|
Again, Excel would not become your "database", it would become your reporting tool. In other words, the program to show manager the sales results. The TCS system is your database; it actually collects and stores the sales data (i.e. it is a database).
However, do I understand correctly, that the data in the text file is not in a list form?
For Example:
Customer | Sales | Profit | A | 100.00 | 10.00 | B | 150.00 | 20.50 |
etc.
First, again I recommend downloading Visual Studio, and challenging your VB and SQL skills.
If the data in the text file needs to be ordered into a database first, so you can query the data, before showing it in Excel, I recommend using Visual Studio's built-in Database program to first store your data.
So:
The TCS System creates a text file (with "chaotic" data) --> your application reads the text file, extracts the necessary data, and puts it in order. Then it stores the ordered data in MS SQL Express Server (database program) --> next your application queries the database, and writes the necessary data (for example Q1 sales) to an Excel file. And you create a macro that builds the pivot tables from the data.
As an alternative, you could use a regular version of MS SQL Server, installed on a server, and create queries directly in Excel from any workstation.
My advice is free, and you may get what you paid for.
|
|
|
|
|
I am working on quite a large form that has become very slow to load, so i'm looking to take off some of the controls and have them loading on a background worker. The most used controls will remain, and a stack will be set up of controls to load in the background, loading the most recently requested control next.
As controls can only be added on the main thread there is also a queue of controls that have been loaded on the background worker and now need adding to the form. All of this works, the issue i have is it would be useful to keep a reference to each control, so you only load it once etc.
To stop code replication it would be great if i can create an object by sending in the System.Type of the object i want to make, the controlCollection it should be added to, some data it can use and the class/form level referance you want set to the control when it has loaded.
Most of this works, however, i cannot get the class level reference to point to object created on the background worker. I get the feeling it should be doable using byRef, but am not quite sure how. I'm thinking my C++ way of thinking is causing problems here, any advice would be appreciated.
Sorry for the large amount of code being posted, think it is all needed to solve the problem.
Public Class MyClass
'class level declaration of control to load on the background worker
Private _addresses As uscAddresses = Nothing
Public Function Addresses() As uscAddresses
If _addresses Is Nothing Then 'if its not been loaded we should put it on the top of the stack
'don't worry if it is already on the stack as it will not get loaded twice
_loadQueue.Push(New ComponentToLoad(GetType(uscAddresses), _addresses, Nothing, tpAddresses))
'if we are already running the background worker no need to start it a second time
If Not bgwLoader.IsBusy Then bgwLoader.RunWorkerAsync()
'ideally won't need this next bit in the final solution
While _addresses Is Nothing
'Application.DoEvents()
'Threading.Thread.Sleep(100)
End While
End If
Return _addresses
End Function
Structure ComponentToLoad
Public Type As System.Type 'type of object that we want to load
'**************************************************************
Public Target As UserControl 'the class level reference to use for the created object
'**************************************************************
Public Data As Object 'any data to pass to the object
Public Parent As Control 'the control to add the new object to after its created
Public Sub New(ByVal inType As System.Type, ByVal inTarget As UserControl, ByVal inData As Object, ByVal inParent As Control)
Type = inType
Target = inTarget
Data = inData
Parent = inParent
End Sub
End Structure
'runs as a stack so most recent request is delt with first
Private Shared _loadQueue As New Stack(Of ComponentToLoad)
'could use another stack but a queue will do, user should see little difference
Private Shared _controlsToAdd As New Queue(Of ComponentToLoad)
Private Sub MatterManager_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'queue objects to load here if any are needed but not immediatly at form load
End Sub
'handles all loading, including checks that the object is not already loaded
Public Sub LoadControl(ByVal onUIThread As Boolean, ByRef inComponent As ComponentToLoad)
If onUIThread Then
'only add the control if its not there already
If Not DirectCast(inComponent.Parent, TabPage).Controls.Contains(inComponent.Target) Then
DirectCast(inComponent.Parent, TabPage).Controls.Add(inComponent.Target)
End If
Else
'only make the object if its not already made
If inComponent.Target Is Nothing Then
inComponent.Target = Activator.CreateInstance(inComponent.Type)
inComponent.Target.Dock = DockStyle.Fill
End If
'could pass the data in to the object here
End If
End Sub
Private Sub bgwLoader_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwLoader.DoWork
'check there is something in the queue
If _loadQueue.Count > 0 Then
'make reference to what we are loading so we can add it to the ui queue
Dim toLoad As ComponentToLoad = _loadQueue.Pop
'load it
LoadControl(False, toLoad)
'stick it on the ui addition queue
_controlsToAdd.Enqueue(toLoad)
End If
End Sub
Private Sub bgwLoader_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgwLoader.RunWorkerCompleted
While _controlsToAdd.Count > 0
'add all loaded controls
LoadControl(True, _controlsToAdd.Dequeue())
End While
If _loadQueue.Count > 0 AndAlso Not bgwLoader.IsBusy Then
'load the next object
bgwLoader.RunWorkerAsync()
End If
End Sub
End Class
modified on Wednesday, July 29, 2009 12:24 PM
|
|
|
|
|
This sounds a bit like you are trying to solve a basic simple problem with a really really really complicated solution.
From the way you are trying to solve this problem now, I understand that even when the form is loaded completely, the user won't need all the controls all the time anyway.
Wouldn't it be easier to just rethink your GUI design? No program should need so many buttons, text boxes, or whatever, that an average PC starts having trouble loading the interface.
Even if you were to get your solution to work, your app would likely bring the PC to its knees anyway, by the time the background thread has finished loading all controls.
Try to combine controls, and reuse them, or to move certain secondary functionality (and the accompanying controls) to its own form, which you then open with a single button or automatically, as a result of another action taken or choice made.
My advice is free, and you may get what you paid for.
|
|
|
|
|
While i understand your points, the application i am working on is a product that has been in development and use for many years, and i'm quite restricted in what i can do to change where information is displayed.
I think the C++ example of what i want is something like this:
#include <iostream>
#include <stdlib.h>
#include "objTest.h"
void main()
{
int toSet = 0;
objTest middleMan = objTest();
middleMan.setRef(&toSet);
middleMan.set(10);
std::cout<<toSet;
char c;
std::cin>>c;
}
#pragma once
class objTest
{
public:
objTest(void);
~objTest(void);
void setRef(int* newRef)
{
myVal = newRef;
}
void set(int newVal)
{
*myVal = newVal;
}
private:
int* myVal;
};
This is really quite simple and can be very powerful when used correctly, but i'm guessing not something that can be done in VB.
|
|
|
|
|
I understand your problem. In this light, I think you are right, your C++ way of thinking is causing you problems. I honestly don't know whether this can be done in VB or not, but I am certain VB was never meant for application control on that level.
Considering that the GUI must be created on the main thread, and that all interaction between user and app also happens on the main thread, what exactly are you trying to achieve by loading the controls in groups? If you consider that a PC with a multi core CPU (which will actually handle two threads at the same time), should be strong enough to load your form the old way, and a single core processor will handle each thread alternatingly, so it won't really load any faster anyway, and loading controls in groups will limit the use of the loaded controls until all controls have been loaded?
How about creating and placing groups of controls at runtime, upon some mouse-over event or something? A bit like MS Office or the windows start menu.
My advice is free, and you may get what you paid for.
|
|
|
|
|