|
|
I have a simple VB6 class in a DLL that has two functions , AllocateLargeArray and DeAllocateLargeArray. I am driving the DLL from an MFC App and in this App I have a button that creates an interface to the VB Class and calls the two functions then releases.
If I then look at the Apps Private bytes (VM Size in TM) of the process the value seems to initially increase lots say to 1900k then on subsequent presses of the button drop to 1600k again to 1300k again to 1000k and then shoot back up to 1900k !
Can anyone tell me why is behaviour ?
To aid here is a a snippet of the code I have in VB.
Thanks.
<br />
Option Explicit<br />
<br />
Dim mCollection As Collection<br />
<br />
Public Function AllocateLargeArray()<br />
Dim loc As MyStruct<br />
Dim ii As Integer<br />
<br />
Set mCollection = Nothing<br />
Set mCollection = New Collection<br />
<br />
For ii = 1 To 10000<br />
Set loc = New MyStruct<br />
mCollection.Add loc<br />
Next ii<br />
End Function<br />
<br />
Public Function DeAllocateLargeArray()<br />
Dim ii As Integer<br />
ii = 1<br />
<br />
Do While ii <= mCollection.Count<br />
mCollection.Remove ii<br />
Loop<br />
<br />
Set mCollection = Nothing<br />
End Function<br />
|
|
|
|
|
First, don't use Task Manager to get the memory statistics. Use Performance Monitor instead. Next VB6's memory management is just about entirely automatic.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
For viewing the private bytes values I was using process explorer rather than Task Manager though bar the dodgy naming for certain values task manager should be ok.
Also im not sure what you mean by 'entirely automatic'. Surely there has to be some reasoning to what seems to be happening.
|
|
|
|
|
Well, Task Manager is about the worst tool you can use unless you REALLY know what your looking at.
For example, under the .NET CLR, you're seeing the memory reserved for the .NET CLR virtual machine your app is running in, not the amount of memory your app is actually using.
As for the VB^ memory manager, I haven't touched VB6 since Visual Studio .NET 2002 Beta 1 came out, about 5-6 years ago.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi there!
I'm making a syntax highlighter and I've come a long way, everything works perfectly... as long as you write on the first line. When moving to the next lines and writing the words that are supposed to be highlighted only the first line is colored, with the color that's set for the most recent match, why does this occur and how can I solve it?
'searches teh text and colors it...<br />
Private Sub ExtendedRichTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExtendedRichTextBox.TextChanged<br />
<br />
Dim selectionAt As Integer = ExtendedRichTextBox.SelectionStart<br />
<br />
'find out the linenumber...<br />
lineNumber = ExtendedRichTextBox.GetLineFromCharIndex(ExtendedRichTextBox.SelectionStart()) + 1<br />
<br />
If ExtendedRichTextBox.GetFirstCharIndexFromLine(lineNumber) = -1 Then<br />
line = ExtendedRichTextBox.Text.Substring(ExtendedRichTextBox.GetFirstCharIndexOfCurrentLine())<br />
startCharIndex = 0<br />
Else<br />
line = ExtendedRichTextBox.Text.Substring(startCharIndex, ExtendedRichTextBox.GetFirstCharIndexFromLine(lineNumber) - ExtendedRichTextBox.GetFirstCharIndexOfCurrentLine)<br />
End If<br />
<br />
'regular expression...<br />
Dim reg_exp As Regex<br />
<br />
'give reg_exp some values...<br />
For i As Integer = 0 To 4<br />
<br />
'give reg_exp a value from the array...<br />
reg_exp = New Regex(syntaxText(i))<br />
<br />
'search for matches...<br />
Dim match As Match<br />
match = reg_exp.Match(line)<br />
<br />
'give the match the right color...<br />
If reg_exp.IsMatch(line) Then<br />
<br />
With ExtendedRichTextBox<br />
.Select(match.Index, match.Length)<br />
.SelectionColor = syntaxColor(i)<br />
.SelectionStart = selectionAt<br />
.SelectionColor = textColor<br />
End With<br />
<br />
End If<br />
Next<br />
<br />
End Sub
Thank you in advance!
|
|
|
|
|
Hi,
Apparently you have written an entire class (Regex), as well as a few functions that are called but not shown in your example. I don't have an ExtendedRichTextBox in my toolbox, so I am guessing that this too is either self made or maybe comes from a third party addon to .NET?
Anyway, all I could find in your code was that you give your variable startCharIndex a value of 0 if something happens, but if it doesn't, this variable does not get a value assigned. The only other code I see that seems funny to me, is the whole last "with ExtendedRichTextBox" bit (unless your function syntaxColor() does something to the color of the selected text before you change it to textColor.
Otherwise my guess is, that the mistake should be searched in another part of your code.
Good luck with this one,
Johan
|
|
|
|
|
I am creating a unique serial number for my ticket submissions.
I use the two letter state abbreviation, the julian date, and milleseconds to create the ticket number. ex"Ticket #: IA20063171383477656". This has been working great. But recently my code has
became flawed. My tickets are getting a hyphen inserted between the julian date and the milliseconds. I found this is because of a bug in the TimeGetTime() function. It starts to give negative numbers after a certain amount of uptime. How do I fix this negative number?
I need to keep the tickets sequential through the day. So 12:00am to 11:59pm will be one sequence of tickets then the sequence will change to the next julian date. Can someone please help me?
I have placed my code below.
Thanks
<script runat="server">
Public Function Date2Julian(ByVal vDate As Date) As Long
Date2Julian = CLng(Format(Year(vDate), "0000") _
+ Format(DateDiff("d", CDate("01/01/" _
+ Format(Year(vDate), "0000")), vDate) _
+ 1, "000"))
End Function
</script>
<script runat="server">
Sub SendMail(sender As Object, e As System.EventArgs)
Dim MyDate as String
MyDate = Date.Now.ToString("MM/dd/yyyy")
Dim Julian as String
Julian = "IA" & Date2Julian(MyDate)& TimeGetTime()
Ticket_ID.Value= Julian
End Sub
</script>
|
|
|
|
|
You didn't post the code your using to define TimeGetTime, but I'm betting that your using an Integer, or some other signed data type, to return the value of TimeGetTime. Use an unsigned data type to return the time in milliseconds, like UInt32 or UInteger.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I get TimeGetTime() from winmm.dll out of the Windows multimedia SDK.
Private Declare Function timeGetTime Lib "winmm.dll" () As Integer
|
|
|
|
|
The C function header specifies a DWORD return value, which is an unsigned 32-bit integer. You have to use the equivilent type in your own code:
Private Declare Function timeGetTime Lib "winmm.dll" () As UInt32
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Ok,
That removed the negative value. But it also shortened the length of the string.
My main worry is that I will somehow get the same number within a 24 hour period
due to rounding. This would place new tickets in front of old tickets and place them
out of sequence.
Old Format - Ticket #: IA20063171394281750
New Format - Ticket #: IA2006320857714024
Instead of using timegettime() is there any way to get the milliseconds since midnight of today.
Basically I need it to reset every 24 hours.
If todays julian date is 320 I want the ticket to look like IA 2006320 and then the milliseconds since midnight. This way it does not duplicate within a 24 hour period.
Can you please tell me how to do that?
|
|
|
|
|
It's simple math...
Dim currentTime As DateTime = DateTime.Now()
Dim msSinceMidnight As Integer
msSinceMidnight = currentTime.Millisecond + _
currentTime.Second * 1000 + _
currentTime.Minute * 60000 + _
currentTime.Hour * 3600000
Instead of going through all this, why not just have the database use a compound key and generate the last part of the key with an autonumber field?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I did this but it didn't work
<script runat="server">
Public Function Serialize() as String
Dim currentTime As DateTime = DateTime.Now()
Dim msSinceMidnight As Integer
msSinceMidnight = currentTime.Millisecond + _
currentTime.Second * 1000 + _
currentTime.Minute * 60000 + _
currentTime.Hour * 3600000
End Function
</script>
It gives me an error in VS 2005. "Function 'Serialize' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used."
Also is there a way to pad the string with zeros so that the string is always the same length?
There are 86400000 milliseconds in a day starting at 00000001 and ending at 86400000.
Thanks
|
|
|
|
|
Uhhh...of course it didn't work! Your function didn't return any value, as detailed by the error message you got. You also specified a return type of String, but didn't do any conversion of the number to a string, before you DIDN'T return the value.
This is BASIC 101 stuff you missed. I would highly suggest picking up a book on VB.NET before you try to put together a web site using it.
Public Function Serialize() As String
Dim currentTime As DateTime = DateTime.Now()
Dim msSinceMidnight As Integer
msSinceMidnight = currentTime.Millisecond + _
currentTime.Second * 1000 + _
currentTime.Minute * 60000 + _
currentTime.Hour * 3600000
Return String.Format("00000000", msSinceMidnight)
End Function
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hello,
I have just had a error deploying a clickonce application. The error is below and has been solved
System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {10020200-E260-11CF-AE68-00AA004A34D5} failed due to the following error: 80040154.
The above problem caused me hours to solve. However, was solved my simply by doing the following: regsvr32 sqldmo.dll. to register the dll on the client machine.
I have created a deployment using the MSI, and never had this problem. But clickOnce does cause this problem if the dll does not exist and is not registered on the client machine.
Is there any way that you can use clickone to add this dll on the client's machine, so I don't have to go to trouble of registering manually.
When I publish this file I have added all the required dlls.
This is what I have done:
1. In the solution explorer | references | properties | set the sqldmo local copy to true
2. On the publish tab | Application File | set the publish status for the sqldmo.dll to include and required
3. Prereqisities | Added the .net framework, CR Reports .Net, MS Data Access components.
VB 2005 & SQL Server 2005.
Many thanks for any help,
Steve
|
|
|
|
|
I need to highlight the an item in the list box, here is the code:
If MyCameraSchedules.Length = 1 Then
lstScheduleNames.SelectedIndex = 0
Else
lstScheduleNames.SelectedIndex = MyCameraSchedules.Length - 1
End If
So basically if I have more than 1 schedule, I want to highlight the last schedule in the list box, if only 1 then highlight the first item which is index 0. However, I get an Exception complaining object reference not set to an instance of object.
I also refresh() the listbox, but doesn't help.
Anyone?
Waiting
|
|
|
|
|
Given the code you gave, the only thing that would be not set to an instance would be the MyCameraSchedules and not the listbox. Have you verified that MyCameraSchedules is set?
|
|
|
|
|
It should be as simple as this:
If MyCameraSchedules.Length > 0 And lstScheduleName.Items.Count >= MyCameraSchedules.Length Then
lstScheduleNames.SelectedItem = lstScheduleNames.Items.Count - 1
End If
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks, but for some odd reason that still doesn't highlight the item if there is only one item in the list box.
If there are more items, then it always highlights the first item.
What I need to do is highlight the first item if only item, otherwise highlight the last.
Thanks b4 hand
Yoshimitsu
|
|
|
|
|
Thanks Dave, This solved the problem
If MyCameraSchedules.Length = 1 Then
lstScheduleNames.SelectedIndex = lstScheduleNames.Items.Count - 1
Else
lstScheduleNames.SelectedIndex = MyCameraSchedules.Length - 1
End If
Yoshimitsu
|
|
|
|
|
I have been trying to write data from a windows app to an Excel file (I have tried creating a new file and appending an existing one).
The web provided me with an abundance of different ways to access an Excel file, but all of these methods are either outdated (.NET claims "old format or invalid type library"), require the use of rather complicated ASP.NET code, or use xml conversion (which example code was also partly outdated).
In the end all I managed was creating a text file with the data, tab, and enter characters, and saving it as an Excel file. This method is extremely clumsy, because I have to count how many tabs and enters I need to write, to be able to determine where any piece of data ends up on the sheet, not to mention that any form of formatting is impossible. And in the end Excel still needs to "import" the file.
I have trouble believing that I am the only one who needs to export data to Excel from windows apps.
can anybody please put me on the right track?
Thanks,
Johan hakkesteegt
|
|
|
|
|
Hi Johan,
I Frequently have to move data from VB.NET to excel, I find using Excels XML ability extremely useful because you just have to flush tags to a file, and name it .xml of .xls and it will open in Excel perfectly. Excel in XML also gives you full control of formatting and data typing. My Advice to you is to create an excel file with the formatting you wish to use, and then save it as type .XML Then open the file in word or even visual studio and examine the tags. Copy the headers and footers, then write some code to flush the content tags out. If you would like to see some examplse I have a few general purpose vb functions that I could send you.
|
|
|
|
|
Hi Kevin,
If you could provide me with some example code, I would be very greatfull, especially if it contains something about placement of data and the actual saving it back to an excel file (that can be opened by a regular user). Ofcourse general purpose functions are always appreciated!
Johan
|
|
|
|
|
Here is a simple app that takes a dataset and writes a worksheet per data table in the set
Public Sub writeToExcel(ByVal source As DataSet)
Dim doc As New System.IO.StreamWriter("Excel.xls") 'use .xls even though its an xml file
Dim startExcelXML As String = ""
startExcelXML &= "<xml version>"
startExcelXML &= vbNewLine & "<Workbook " + "xmlns=""urn:schemas-microsoft-com:office:spreadsheet"""
startExcelXML &= vbNewLine & Microsoft.VisualBasic.Chr(10) & "" + " xmlns =""urn:schemas-microsoft-com:office:office"""
startExcelXML &= vbNewLine & "xmlns:x=""urn:schemas- microsoft-com:office:" + "excel"""
startExcelXML &= vbNewLine & "xmlns:ss=""urn:schemas-microsoft-com:" + "office:spreadsheet"">"
'write the styles tags that format the data and cells properly
startExcelXML &= vbNewLine & "<Styles>"
startExcelXML &= vbNewLine & " <Style ss:ID=""Default"" ss:Name=""Normal"">"
startExcelXML &= vbNewLine & " <Alignment ss:Vertical=""Bottom""/>"
startExcelXML &= vbNewLine & " <Borders/>"
startExcelXML &= vbNewLine & " <Font/>"
startExcelXML &= vbNewLine & " <Interior/>"
startExcelXML &= vbNewLine & " <NumberFormat/>"
startExcelXML &= vbNewLine & " <Protection/>"
startExcelXML &= vbNewLine & " </Style>"
startExcelXML &= vbNewLine & "<Style ss:ID=""ColHeader"">"
startExcelXML &= vbNewLine & "<Alignment ss:Horizontal=""Center"" ss:Vertical=""Bottom""/>"
startExcelXML &= vbNewLine & "<Font x:Family=""Swiss"" ss:Size=""8"" ss:Bold=""1""/>"
startExcelXML &= vbNewLine & "<Interior ss:Color=""#C0C0C0"" ss:Pattern=""Solid""/>"
startExcelXML &= vbNewLine & "</Style>"
startExcelXML &= vbNewLine & " <Style ss:ID=""Reg"">"
startExcelXML &= vbNewLine & " <Font " + "x:Family=""Swiss"" ss:Bold""0""/>"
startExcelXML &= vbNewLine & " </Style>"
startExcelXML &= vbNewLine & "</Styles>"
'write the header to the file
doc.WriteLine(startExcelXML)
'write one sheet per table
For Each tab As DataTable In source.Tables
Dim sheetname As String = "<Worksheet ss:Name="
sheetname &= Microsoft.VisualBasic.Chr(34)
sheetname &= tab.TableName.Trim
sheetname &= Microsoft.VisualBasic.Chr(34)
sheetname &= ">"
doc.WriteLine(sheetname)
doc.WriteLine("<Table>")
'write the column headers
doc.WriteLine("<Row>")
For Each col As DataColumn In tab.Columns
doc.Write("<Cell ss:StyleID=""ColHeader""><Data ss:Type=""String"">")
doc.Write(col.ColumnName)
doc.WriteLine("</Data></Cell>")
Next
doc.WriteLine("</Row>")
'write the table
For Each row As DataRow In tab.Rows
doc.WriteLine("<Row>")
'Dim i As Integer
For i As Integer = 0 To tab.Columns.Count - 1
doc.Write("<Cell ss:StyleID=""Reg""><Data ss:Type=""String"">")
doc.Write(row.Item(i))
doc.WriteLine("</Data></Cell>")
Next
doc.WriteLine("</Row>")
Next
doc.WriteLine("</Table>")
doc.WriteLine("</Worksheet>")
Next
doc.WriteLine("</Workbook>")
doc.Close()
End Sub
this can be opened in excel. You will have to add your own formating to make the sheet look like you want, to do that just make changes, save it and open it and see what it did to the tags. Then make your code do the same.
Hope this helps
Kevin
|
|
|
|