|
Hi All,
I need to loop through a listbox and get all the selected items. Everywhere I searched they reccommend:
Dim item as ListItem
for each item in MyListBox
if item.selected
...
end if
next
However, .NET tells me that ListItem is not a defined type.
Thanks for any help
Yoshi
|
|
|
|
|
For i as int16 = 0 to lstBox.SelectedItems.count - 1
msgbox(lstBox.SelectedItems(i).ToString)
Next
or
For Each sItem as String In lstBox.SelectedItems
msgbox(sItem)
Next
|
|
|
|
|
I keep getting this error message when trying to insert files into sql database: Unclosed quotation mark before the character string ". Line 1: Incorrect syntax near '82'.
I have tried so many things to try and fix this problem.
Here is some code that I have to insert the file:
Dim Conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data Feeds\Current\Honda\OEM;Extended Properties=""Text;HDR=No;FMT=FixedLength"""
Dim SQLstr As String = "SELECT * FROM FULL_MC.dat"
Dim da As New OleDb.OleDbDataAdapter(SQLstr, Conn)
For Each row In dtTable.Rows
sSuggestedretailprice = Replace(row("suggestedretailprice"), "*", "")
If IsNumeric(row("dealernetpricedollars").ToString) Then
FormatCost = Format(CSng(row("dealernetpricedollars")), "c").ToString()
Else
ErrorLog(row("dealernetpricedollars").ToString & " Not Valid Dealer Cost for partnumber " & row("PartNumber").ToString())
End If
If IsNumeric(row("suggestedretailprice").ToString) Then
FormatMSRP = Format(CSng(sSuggestedretailprice), "c").ToString()
Else
ErrorLog(row("suggestedretailprice").ToString & " Not Valid Dealer MSRP for partnumber " & row("PartNumber").ToString())
End If
If InvalidCharacterCheck(row("PartNumber").ToString) Then
ErrorLog("Not Valid partnumber: " & row("PartNumber").ToString())
Else
CheckforProducts = ProductExist(row("PartNumber").ToString(), "1")
If CheckforProducts.Rows.Count > 0 Then
UpdateProduct(RemoveQuotes(row("PartNumber").ToString()), "0", row("mostforwardpartnumber").ToString(), row("supercededate").ToString(), RemoveQuotes(row("PartDesc").ToString()), "0", "0", "0", "0", "0", "1", FormatCost, FormatMSRP)
Else
InsertProducts(RemoveQuotes(row("PartNumber").ToString()), "0", row("mostforwardpartnumber").ToString(), row("supercededate").ToString(), RemoveQuotes(row("PartDesc").ToString()), "0", "0", "0", "0", "0", "1", FormatCost, FormatMSRP)
End If
End If
Next row
|
|
|
|
|
I guess that your 'RemoveQuotes' method is not working. Your first step should be to step in to UpdateProduct, and see what is being passed in.
There's obviosly an error in your SQL, so you need to see the SQL string.
Christian Graus - C++ MVP
|
|
|
|
|
What specific brand of database are you using? They handle apostrophes in different ways.
What does the RemoveQuotes method do?
What does the InsertProducts method do?
As you get that kind of error, I assume that you assemble the SQL query youself? Have you considered using parameterised queries instead?
---
b { font-weight: normal; }
|
|
|
|
|
Or, better yet, a stored proc ? :P
Christian Graus - C++ MVP
|
|
|
|
|
Hi
Thanks for any one try to help me
How can i show a form inside another form >>
jooooo
|
|
|
|
|
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim oFrm As New Form3
oFrm.TopLevel = False
oFrm.Show()
Me.Controls.Add(oFrm)
end sub
|
|
|
|
|
|
The easiest was is to make the contents of the form a control, which you can then put where-ever you like.
Christian Graus - C++ MVP
|
|
|
|
|
|
You just add it the same as any in built control, in the designer, or in code.
Christian Graus - C++ MVP
|
|
|
|
|
|
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
|
|
|
|