|
Valkiri wrote: Look what I've Found:
http://www.codeproject.com/KB/cs/agusercontrol.aspx[^]
Just because there's an article on the subject, doesn't make it a good idea.
Valkiri wrote: Are you stating that controls should never (hardly ever anyway) call the form.
It goes against OOP practices, specifically, "encapsulation", yes.
Valkiri wrote: Am I correct in understanding that you advise that the form should listen for and catch the, say, click event and act upon it.
That's one possible solution, yes.
Valkiri wrote: If the form is waiting to catch the event does this mean that the controls say click event has no code in it.
It should have the code necessary to clean up the data the control, and that button, is responsible for and raise it's event or some other notification mechanism.
Valkiri wrote: Do you know of URLs / articles that address this question of using control libraries.
I haven't found much in the way of control development on the web. Mostly in books and from what I gleaned out of the .NET Framework itself, using Reflector.
|
|
|
|
|
Hi Dave,
Many thanks for your input. I'm now off to reassess my approach spurred on by your comments.
Naturally I've got more questions but I do realise this is not a one to one tutorial.
So consider this thread as complete.
If I come up against another brick wall this is where I'll post my query.
Once again I stress that I appreciate you taking the time (again and again) to attempt to pull me back on track.
Have a nice one and the Seasons Greetings.
|
|
|
|
|
Hi,
I am facing this error for the following code. please reply and do the needful
Private Sub Command0_Click()
Dim DbAdo As ADODB.Connection
Dim RsAdo As ADODB.Recordset
Set DbAdo = CurrentProject.Connection
Set RsAdo = New ADODB.Recordset
Dim stDocName As String
Dim stDocName1 As String
Dim stDocName2 As String
Dim stDocName3 As String
Dim i, j As Integer
Dim str1 As String
Dim K As Integer
stDocName = "Personal"
RsAdo.Open stDocName, DbAdo, adOpenStatic, adLockPessimistic
Dim createExcel As New excel.Application
Dim Wbook As excel.Workbook
Dim Wsheet As excel.Worksheet
Set Wbook = createExcel.Workbooks.Add
Set Wsheet = Wbook.Worksheets("Sheet1")
Wsheet.Name = "Test"
i = 0
j = 0
'Wsheet.Cells(1, 1) = "Hosp ID : " & Me.HCO
'Wsheet.Cells(2, 1) = "Process : " & Me.ThisPdProcNum
'Wsheet.Cells(3, 1) = "Processing Period : " & Me.ThisPdStartDate & " - " & Me.ThisPdStopDate
'Wsheet.Cells(1, 1).Font.Bold = True
'Wsheet.Cells(2, 1).Font.Bold = True
'Wsheet.Cells(3, 1).Font.Bold = True
'Wsheet.Cells(5, 1) = "GL Research"
'Wsheet.Cells(8, 1) = "Unmapped Cost Centres"
'Wsheet.Cells(5, 1).Font.Bold = True
'Wsheet.Cells(5, 1).Font.Size = "20"
'Wsheet.Cells(8, 1).Font.Bold = True
'Wsheet.Cells(1, 1).EntireColumn.ColumnWidth = "10"
'Wsheet.Range("A:IV").Interior.ColorIndex = 2
'Wsheet.Range("A:IV").Interior.Pattern = xlSolid
'Wsheet.Range("A:IV").Interior.PatternColorIndex = xlAutomatic
For i = 0 To RsAdo.Fields.Count - 1
With Wsheet.Cells(9, i + 1)
.Font.Size = "9"
.Font.Bold = True
.Interior.ColorIndex = 15
.EntireColumn.ColumnWidth = 15
.EntireColumn.AutoFit
.HorizontalAlignment = xlHAlignCenter
.Value = RsAdo.Fields(i).Name
End With
Next i
If (RsAdo.RecordCount > 0) Then
RsAdo.MoveFirst
cnt = 10
Do Until RsAdo.EOF
Wsheet.Range("A" & Trim(Str(cnt))).Value = RsAdo("sno")
Wsheet.Range("B" & Trim(Str(cnt))).Value = RsAdo("name")
Wsheet.Range("C" & Trim(Str(cnt))).Value = RsAdo("age")
'Wsheet.Range("D" & Trim(Str(cnt))).Value = RsAdo("CCDESCR")
'Wsheet.Range("H" & Trim(Str(cnt))).Value = RsAdo("On CC RD XREF")
'Wsheet.Range("I" & Trim(Str(cnt))).Value = RsAdo("On New Base")
'Wsheet.Range("J" & Trim(Str(cnt))).Value = RsAdo("On New Fin")
RsAdo.MoveNext
Wsheet.Range("A" & Trim(Str(cnt))).Borders.LineStyle = xlContinuous
Wsheet.Range("B" & Trim(Str(cnt))).Borders.LineStyle = xlContinuous
Wsheet.Range("C" & Trim(Str(cnt))).Borders.LineStyle = xlContinuous
'Wsheet.Range("D" & Trim(Str(cnt))).Borders.LineStyle = xlContinuous
'Wsheet.Range("E" & Trim(Str(cnt))).Borders.LineStyle = xlContinuous
'Wsheet.Range("F" & Trim(Str(cnt))).Borders.LineStyle = xlContinuous
'Wsheet.Range("G" & Trim(Str(cnt))).Borders.LineStyle = xlContinuous
Wsheet.Range("A" & Trim(Str(cnt))).Font.Size = "9"
Wsheet.Range("B" & Trim(Str(cnt))).Font.Size = "9"
Wsheet.Range("C" & Trim(Str(cnt))).Font.Size = "9"
'Wsheet.Range("D" & Trim(Str(cnt))).Font.Size = "9"
'Wsheet.Range("E" & Trim(Str(cnt))).Font.Size = "9"
'Wsheet.Range("F" & Trim(Str(cnt))).Font.Size = "9"
'Wsheet.Range("G" & Trim(Str(cnt))).Font.Size = "9"
'Wsheet.Range("D" & Trim(Str(cnt))).Interior.ColorIndex = 35
'Wsheet.Range("E" & Trim(Str(cnt))).Interior.ColorIndex = 35
'Wsheet.Range("F" & Trim(Str(cnt))).Interior.ColorIndex = 35
'Wsheet.Range("G" & Trim(Str(cnt))).Interior.ColorIndex = 35
'Wsheet.Range("D" & Trim(Str(cnt))).NumberFormat = "@"
'Wsheet.Range("E" & Trim(Str(cnt))).NumberFormat = "@"
'Wsheet.Range("F" & Trim(Str(cnt))).NumberFormat = "@"
'Wsheet.Range("G" & Trim(Str(cnt))).NumberFormat = "@"
cnt = cnt + 1
Loop
RsAdo.MoveLast
Else
Wsheet.Cells(10, 1) = "None for this month"
Wsheet.Cells(10, 1).Font.Bold = True
Wsheet.Cells(10, 1).Font.ColorIndex = 5
End If
End Sub
With Regards,
Samson
|
|
|
|
|
Sounds like you have a user defined datatype in your database that Excel does not understand. See which column(s) it is and cast them to their underlying type.
I suspect if you step through in debug you will easily find the offending column.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Just guessing!!!
I think your not import the Excel component.
and when u give the long code mention the which line contain the error...
Ananda
|
|
|
|
|
Hi All,
I am interested to hear the pros and cons of two approaches and reusing a DataTable object or perhaps someone has a better idea.
I have a DataTable object that I reuse. By this I mean I load it with data (using da.fill(dt)) use the data in the program, I then reload it with different data and use this new data. It does not go out of scope.
Sometimes I don't want it to hold data as there is none to hold so I assign the DataTable to nothing (dt = Nothing). I do this so I can use the condition if dt is nothing then ...
Using .NET apparently the garbage collector does not destroy the object as long as I don't go out of scope, so when I load it with data again it holds the new values. This all works fine but in the microsoft documentation it has a phrase that makes me wary using this approach. It states "For example, if an object is set to Nothing inside a procedure and the next line of code creates an object of the same name, the first object may not yet be destroyed and a reference to the new object might incorrectly return the first object." The full reference is here :
http://msdn.microsoft.com/en-us/library/7cx5cffd(VS.71).aspx[^]
When I assign new data to the object by using the dataadapter fill command I suppose I am just assigning a reference to the memory that holds the data so I don't know if the above really applies.
For a simple example without all the fluff, consider;
dim dt as new Datatable
da.fill(dt)
(other code)
dt = nothing
(other code)
da.fill(dt)
(other code)
I'm not entirly comfortable with this approach as it seems bad to set it to nothing if I actually intend to reuse it again and again.
My alternative to the above if it is really bad is instead of setting it to nothing to use the dt.reset method to clear any data out of the datatable for example;
dim dt as new Datatable
da.fill(dt)
(other code)
dt.Reset
(other code)
da.fill(dt)
I can then use, if dt.tables.count=0 orelse dt.tables(0).rows.count=0 then .....
to test for no data elsewhere in the code.
I am assuming that reset clears out all data and when microsoft say 'Resets the system.data.datatable to its original state' I assume the original state is the state it was at when it was created?
Any Thoughts on this would be appreciated
|
|
|
|
|
Setting it to nothing is a waste of time. If you want to free memory, call the Dispose method THEN set it to nothing, to mark it as disposed, and certainly create a new object before reusing it.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hi Christian, I'm not trying to free memory. I'm setting the Datatable to nothing so I can test for it being nothing later in the code so I can control program flow based on if I loaded it with data or not. I agree with your suggestion though if I wanted to free memory.
|
|
|
|
|
IMHO that MSDN page is completely wrong. And I am sure Christian's advice is sound.
|
|
|
|
|
If your just dumping the old data, just create a new DataTable object and forget about worrying about this. The CLR GC will handle the situation appropriately and do cleanup when required.
dim dt as new Datatable
da.fill(dt)
(other code)
dt.Dispose()
dt = New DataTable
(other code)
da.fill(dt)
modified on Thursday, December 11, 2008 10:54 AM
|
|
|
|
|
I would suggest you dispose of the first DataTable though.
|
|
|
|
|
Whoops! I meant to put that in there... Strike 1!
|
|
|
|
|
Thanks for your suggestion Dave and your right I am dumping old data but also setting the datatable to a state where I can test it and control program flow. I did't go into too much detail in my original post but the Datatable is inside a class that stays around while the program is executing. I use various properties of the class to retreive and manipulate the data in the datatables (more than one) inside the class. As the datatables stay around for the life of the class and therefore the program, I can't really just create a new one as my properties need to reference the same datatable (which contains data or I set to Nothing indicating no data) to make sense of the data and the program needs to reference the same class. If the datatable happens to be disposed (as it contained no data) as in your example I would get an error when I reference it.
|
|
|
|
|
I think you have left out some things in your description. Setting the datatable reference to Nothing destroys the table, colums, data, everything. You cannot reuse that object. Now you're saying you WANT to reuse the datatable and its columns, but no data. Which is it??
Coding123456 wrote: my properties need to reference the same datatable (which contains data or I set to Nothing indicating no data) to make sense of the data and the program needs to reference the same class.
Coding123456 wrote: If the datatable happens to be disposed (as it contained no data) as in your example I would get an error when I reference it.
These two things are mutually exclusive. You cannot have it both ways. I think you need to rethink this data model.
|
|
|
|
|
Dave Kreskowiak wrote: I think you have left out some things in your description. Setting the datatable reference to Nothing destroys the table, colums, data, everything. You cannot reuse that object. Now you're saying you WANT to reuse the datatable and its columns, but no data. Which is it??
Setting the datatable to Nothing I agree it will destroy the table. Which is fine as I don't want to reuse it's columns or data. I just want to be able to test if the datatable is Nothing and if so run some code. Or sometime later when if it does contain data, run different code.
To put it a different way, if dt is nothing I know there is no data associated with it, otherwise I can read data from the datatable. I am using its 'nothingness' as a flag
Thanks for your comments to date I appreciate your interest. I realise that I may use one word that inadvertently changes the the exact meaning of what I am trying to describe.
|
|
|
|
|
Coding123456 wrote: Using .NET apparently the garbage collector does not destroy the object as long as I don't go out of scope
Correction: The garbage collector will not destroy the object until all references to it are unreachable.
Coding123456 wrote: For example, if an object is set to Nothing inside a procedure and the next line of code creates an object of the same name, the first object may not yet be destroyed and a reference to the new object might incorrectly return the first object
I have no idea what the name property on an object has to do with anything, unless there is some pooling going on somewhere which is keyed on the name property. If there was it should be well documented.
Setting the reference to Nothing makes it unreachable (so long as there are no other references to it.)
If the object implements the IDisposable interface then you should, as a matter of good practice, call Dispose on the object.
Coding123456 wrote: I'm not entirly comfortable with this approach as it seems bad to set it to nothing if I actually intend to reuse it again and again.
I don't see a problem with that. If you set it to nothing and there is a consirerable amount of time before assigning new data then do so because in the intervening time the Garbage Collector can get it. If it is the very next statement where you assign data I don't really see much point.
|
|
|
|
|
Hi Colin, you say that
Colin Angus Mackay wrote: Setting the reference to Nothing makes it unreachable (so long as there are no other references to it.)
If the object implements the IDisposable interface then you should, as a matter of good practice, call Dispose on the object.
When I set the datatable to Nothing I am making the data unreachable which is what I want to do and it also gives me a condition I can test for to control program flow i.e. if dt is nothing then...
I don't want to dispose it as I may want to do something like this;
If dt is nothing then
return "Default Name"
else
return cstr(dt.rows(0).item("Name"))
end if
Colin Angus Mackay wrote:
I don't see a problem with that. If you set it to nothing and there is a consirerable amount of time before assigning new data then do so because in the intervening time the Garbage Collector can get it. If it is the very next statement where you assign data I don't really see much point.
So you are saying when I set the dt=nothing the data it pointed to will get cleaned up and dt still hangs around safely for me to reuse. This is reasssuring.
The time to assign new data may be immediate or after some time. It is really not the very next statement I have just simplified the code.
Thanks for your reply
|
|
|
|
|
Coding123456 wrote: I don't want to dispose it as I may want to do something like this
Eh?! You've already made it unreachable, you can't dispose something that is unreachable, you have to wait until the Garbage Collector does it for you. I think you seem to misunderstand what the Dispose method is doing.
Some classes implement the IDisposable interface which gives you a Dispose method. If a class gives you a Dispose method then you MUST as a matter of good practice dispose the object BEFORE making it unreachable. If you don't then the garbage collector will have to clean up the additional mess for you. If a class implements Dispose it is effectively saying "I make a bit of a mess, but I can clean up after myself". You do not want the Garbage Collector calling Dispose for you. Ever!
Coding123456 wrote: So you are saying when I set the dt=nothing the data it pointed to will get cleaned up and dt still hangs around safely for me to reuse
dt is a reference to something. The data that was referenced to it will be cleaned up by the Garbage Collector when there are no more references to it (i.e. it becomes unreachable). You can safely assign another object to dt and it will refer to the new object.
|
|
|
|
|
I would like to check if it is true that both the listener and the client must be in the same file but different class to work? I try separating them as 2 just as i wan to put each in 2 separate CPU and it seen to have some error on the client side.
i Dim client as new tcpclient they underline it as error.
|
|
|
|
|
No, you can have them both in the same file, same class, different files, different classes, partial classes, ... whatever. They'll still work.
Subjugate wrote: i Dim client as new tcpclient they underline it as error.
Probably because you're missing Imports or you haven't specified the entire fully qualified name of your TcpClient class.
|
|
|
|
|
So i would like to ask if u have any example of tcplistener and tcpclient both as stand alone application to pass me? As i can only find file that combine them together online. I need to test them out on 2 seperate pc before i can progress in my project. Thanks for the help.
|
|
|
|
|
i had downloded the c# project of html to pdf conversion, that uses the itextsharp.dll, but pdf file is not open.
so is there any other way of conversion
can anyone help me.
thanx and regards.
Gauri
|
|
|
|
|
There's tons of libraries you can buy.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Attempting to write a script that searches and moves .pst files from network share then merges them into the users exchange mailbox under a subfolder (ie Archives > myarchive1 etc). We simply wish to run this as a scheduled task.
The following is not mine (thanks to the author) but needs some modifying and comments added.
Appreciate the help!
--------------------
Function GetStorePath(strStoreID)
Dim intStart
Dim intEnd
Dim strProvider
Dim strPathRaw
intStart = InStr(9, strStoreID, "0000") + 4
intEnd = InStr(intStart, strStoreID, "00")
strProvider = Mid(strStoreID, intStart, intEnd - intStart)
strProvider = Hex2ToString(strProvider)
Select Case LCase(strProvider)
Case "mspst.dll", "pstprx.dll"
If Right(strStoreID, 6) = "000000" Then
'2003
intStart = InStrRev(strStoreID, "00000000") + 8
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex4ToString(strPathRaw))
Else
'97
intStart = InStrRev(strStoreID, "000000") + 6
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
End If
Case "msncon.dll"
intStart = InStrRev(strStoreID, "00", Len(strStoreID) - 2) + 2
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
Case "emsmdb.dll"
GetStorePath = "Exchange store"
Case Else
GetStorePath = "Unknown store path"
End Select
End Function
Public Function Hex4ToString(Data)
Dim strTemp
Dim strAll
Dim i
For i = 1 To Len(Data) Step 4
strTemp = Mid(Data, i, 4)
strTemp = "&H" & Right(strTemp, 2) & Left(strTemp, 2)
strAll = strAll & ChrW(Eval(strTemp))
Next
Hex4ToString = strAll
End Function
Public Function Hex2ToString(Data)
Dim strTemp
Dim strAll
Dim i
For i = 1 To Len(Data) Step 2
strTemp = "&H" & Mid(Data, i, 2)
strAll = strAll & ChrW(Eval(strTemp))
Next
Hex2ToString = strAll
End Function
|
|
|
|
|
Noone is going to write your code for you. If you've got a specific question, we can help with that.
This looks like really, really OLD VB5 or 6 code. You'd be much better off scrapping this and starting from scratch, using the Outlook automation libraries to do this.
|
|
|
|
|