|
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
|
|
|
|
|
Hi Kevin,
You are a life saver!
Johan
|
|
|
|
|
Don't Mention it, I spent at least a week a few months back searching for the same thing, I hope it all works out for you.
Kevin
|
|
|
|
|
Hi,
I have created a crytal report using TTX file and i am trying to connect ADO recodset to the report.
When crpReport.Preview of the following code is executed,I am getting the runtime error like "runtime error '20527' sql server error"
Please help me to solve this.
Dim crpApplication As CRPEAuto.Application
Dim crpReport As CRPEAuto.Report
Dim crpDatabase As CRPEAuto.Database
Dim crpTables As CRPEAuto.DatabaseTables
Dim crpTable As CRPEAuto.DatabaseTable
Set crpApplication = CreateObject("crystal.crpe.application")
Set crpReport = crpApplication.OpenReport(App.Path & "\Report1.rpt")
Set crpDatabase = crpReport.Database
Set crpTables = crpDatabase.Tables
Set crpTable = crpTables.Item(1)
Call crpTable.SetPrivateData(3, adoRs)
crpReport.Preview
Environment: Visual Basi 6, Crytal Report 6, Sybase
Thanks
Ramesh
|
|
|
|
|
hey guys
Im reading from a file using the following code :
Do While Not sr.Peek = -1 'end of file<br />
checkStr = sr.ReadLine<br />
If checkStr.Contains(Chr(34)) Then<br />
....<br />
else if checkstr.contains("123") Then<br />
....<br />
end if
the thing that i m asking .how can i transform the If/else statment to select case statement...
means :
is it feasible with<br />
select case checkstr<br />
case checkstr.contains(ch(34))<br />
.....<br />
case checkstr.contains("123")<br />
.....<br />
end case
Regards
Ramy
|
|
|
|
|
Select Case True
Case checkstr.contains(ch(34))
MsgBox(2)
Case checkstr.contains("123")
MsgBox(1)
Case Else
MsgBox(0)
End Select
|
|
|
|
|
'Select Case checkStr
'Case = (Chr(34))
'
'Case = "123"
'
'Case Else
'
'End Select
-------------------------
Check above post for right answer
-------------------------
-- modified at 10:45 Thursday 16th November, 2006
|
|
|
|
|
Yone,
Wouldn't that look for an exact match instead of searching the string for those characters?
Nathan
|
|
|
|