|
Hi Luc,
Thanks for a quick reply.
I looked at generics and was hoping there may be a complex alternative which i might find interesting
i have opted for the following to keep it simple
1 dictionary for quick retrieval by userid
2 lists for containing active and inactive users.
i wonder how this will scale for larger number of users!
Thanks to you i learnt about lambda expressions today.
Go you still prefer datatables for these kind of operations when dealing with disconnected data?
Cheers
Kalyan
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
HI to all.
I have a simple question. I'm trying to create a bitmap from a memory stream. The memory stream is filled with a byte array and there isn't image information, only raw pixel data.
Now I'm confusing because the C# sample code I found in internet runs without errors
<br />
private Image GetImage (long position, int size)<br />
{<br />
string string1;<br />
byte[] byteArray1;<br />
Bitmap bitmap1;<br />
Stream stream1 = ((Stream) null);<br />
BinaryReader binaryReader1 = ((BinaryReader) null);<br />
MemoryStream memoryStream1 = ((MemoryStream) null);<br />
try<br />
{<br />
string1 = string.Format ("{0}gallery{1:D2}.enc", Session.RootPath, this.index);<br />
stream1 = ((Stream) File.OpenRead (string1));<br />
binaryReader1 = new BinaryReader (stream1, Encoding.ASCII);<br />
long int64_1 = binaryReader1.BaseStream.Seek (position, SeekOrigin.Begin);<br />
byteArray1 = binaryReader1.ReadBytes (size);<br />
this.ColorBalance (byteArray1);<br />
memoryStream1 = new MemoryStream (byteArray1);<br />
try<br />
{<br />
bitmap1 = new Bitmap (((Stream) memoryStream1));<br />
}<br />
catch<br />
{<br />
bitmap1 = new Bitmap (64, 64);<br />
}<br />
}<br />
finally<br />
{<br />
if (memoryStream1 != null)<br />
{<br />
memoryStream1.Close ();<br />
memoryStream1 = ((MemoryStream) null);<br />
}<br />
if (binaryReader1 != null)<br />
{<br />
binaryReader1.Close ();<br />
binaryReader1 = ((BinaryReader) null);<br />
}<br />
if (stream1 != null)<br />
{<br />
stream1.Close ();<br />
stream1 = ((Stream) null);<br />
}<br />
}<br />
return bitmap1;<br />
}<br />
while the conversion to VB.Net (2008) written by me raise an exception
<br />
Private Function _getImage(ByVal _position As Long, ByVal _size As Integer)<br />
Dim _bmp As New Bitmap(64, 64)<br />
Try<br />
Dim _stream As Stream = File.OpenRead(_file)<br />
Dim _binaryReader As BinaryReader = New BinaryReader(_stream, Encoding.ASCII)<br />
<br />
Dim _int64 As Long = _binaryReader.BaseStream.Seek(_position, SeekOrigin.Begin)<br />
Dim _byteArray As Byte() = _binaryReader.ReadBytes(_size)<br />
<br />
_colorBalance(_byteArray)<br />
Dim _memoryStream As New MemoryStream(_byteArray)<br />
_bmp = Bitmap.FromStream(_memoryStream) '<--- "Invalid data" exception<br />
<br />
_memoryStream.Close()<br />
_binaryReader.Close()<br />
_stream.Close()<br />
Catch ex As Exception<br />
MessageBox.Show(ex.Message, "Get Image error", MessageBoxButtons.OK, MessageBoxIcon.Error)<br />
End Try<br />
Return _bmp<br />
End Function<br />
Why the C# code runs and the VB not? Where I'm wrong?
Thanks.
Perry
P.S.: sorry my english, if you can...
|
|
|
|
|
Instead of :
xry2006 wrote: _bmp = Bitmap.FromStream(_memoryStream)
I recommend :
_bmp = New Bitmap(_memoryStream)
A subtle difference I know, howeer the difference is more than just returning a bitmap rather than an image.
Bitmap.FromStream ends up calling GdipLoadImageFromStream in the GDIPlus.dll
New Bitmap(stream) calls GdipCreateBitmapFromStream in the GDIPlus.dll
I assume the Bitmap version includes more handling for different image types.
|
|
|
|
|
Hi. Thanks for the reply. I'd try your suggestion but the exception "Invalid parameter" remain.
|
|
|
|
|
Here is a direct translation of your c# code, done by SharpDevelop.
Could you try it out. Could be something you missed in translation, though I couldn't spot it.
Private Function GetImage(position As Long, size As Integer) As Image
Dim string1 As String
Dim byteArray1 As Byte()
Dim bitmap1 As Bitmap
Dim stream1 As Stream = DirectCast(Nothing, Stream)
Dim binaryReader1 As BinaryReader = DirectCast(Nothing, BinaryReader)
Dim memoryStream1 As MemoryStream = DirectCast(Nothing, MemoryStream)
Try
string1 = String.Format("{0}gallery{1:D2}.enc", Session.RootPath, Me.index)
stream1 = DirectCast(File.OpenRead(string1), Stream)
binaryReader1 = New BinaryReader(stream1, Encoding.ASCII)
Dim int64_1 As Long = binaryReader1.BaseStream.Seek(position, SeekOrigin.Begin)
byteArray1 = binaryReader1.ReadBytes(size)
Me.ColorBalance(byteArray1)
memoryStream1 = New MemoryStream(byteArray1)
Try
bitmap1 = New Bitmap(DirectCast(memoryStream1, Stream))
Catch
bitmap1 = New Bitmap(64, 64)
End Try
Finally
If memoryStream1 IsNot Nothing Then
memoryStream1.Close()
memoryStream1 = DirectCast(Nothing, MemoryStream)
End If
If binaryReader1 IsNot Nothing Then
binaryReader1.Close()
binaryReader1 = DirectCast(Nothing, BinaryReader)
End If
If stream1 IsNot Nothing Then
stream1.Close()
stream1 = DirectCast(Nothing, Stream)
End If
End Try
Return bitmap1
End Function
|
|
|
|
|
Hello Everyone
I am having a hard time here can anyone help me please
I am trying to have my timer reset i have it couting up at 1 second interval when i stop it and start it agine
it keeps counting from ware it left off , i want it to reset to 0
Thanks
Bob
Public Sub OnOff_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OnOff_Button.Click
If Form1.phidgetIFK.outputs(2) = False Then
Form1.phidgetIFK.outputs(2) = True
TextBox1.Text = "0"
Timer1.Enabled = True
Timer1.Interval = 1000
Else
Form1.phidgetIFK.outputs(2) = False
Timer1.Enabled = False
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Toolclick += 1
TextBox1.Text = Toolclick.ToString
End Sub
|
|
|
|
|
Bob Beaubien wrote: TextBox1.Text = Toolclick.ToString
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Hay Luc
Do you have a other Clue i still can figer it out ?
|
|
|
|
|
i got it luc i used this insted
TextBox1.Text = Val(TextBox1.Text) + 1
Thanks
Bob
|
|
|
|
|
either that or, better, reset the variable you were using when you need to.
Now name two reasons why the latter is better!
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Hi all,
I have a little problem with a pair of arrays, when them are involved in a comparation work:
In particular, I have an Array A As String and another array B As String.
Normally the program works with a single array A, but sometimes I need a second array B.
Array A is filled with numerical string (sometime with up 15000 elements).
Array B is filled with numerical string (sometime with up 15000 elements).
The code works in this way:
Each element of array B is compared with Each element of array A.
If a value of array B is = to some value in array A then the value in the array B is removed and the array is resized (progressively size-decreased) but preserving remaining different values (Redim Preserve).
In this way, at the end of comparation loop, the array B will contain only values that are not already contained in array A.
The code seems to be perfectly working until the number of elements in array A and B is down about 2200 + 2200 elements, but if numbers of arrays element go up, the program seems to work (in an infinite loop) but in reality it is quited (closed) from O.S.
In the fact the program name disappears from list of running program.
The following is the schematic code:
Do Until IndexB = ArrayB.GetLength(0)
For IndexA = 1 to ArrayA.GetLength(0)
If Val(ArrayB(IndexB)) = Val(ArrayA(IndexA)) Then
ArrayB(IndexB) = ArrayB(ArrayB.GetLength(0) - 1)
ReDim Preserve ArrayB((ArrayB.GetLength(0) - 1) - 1)
IndexB = IndexB - 1
Exit For
End If
Next
IndexB = IndexB + 1
Loop
Application is running in a Windows Mobile 6.1 Device.
Apparentely seems to be a memory problem, but I don't think so, because size of arrays is not exagerate and the device have enough available memory.
Thanks for help.
|
|
|
|
|
Hi,
this is horribly inefficient for many reasons:
- you are converting strings to numbers all the time; it they really are numbers, store them in a numeric data type, not string.
- ReDim Preserve is expensive as it has to allocate a new array, then copy all the data. When the number of items in a collection varies, you should consider using a real collection instead of an array; use a collection type if those are available, or create your own linked list structures.
- For two arrays of size S1 and S2, you are performing S1*S2 comparisons. It would be cheaper to sort the first array, sort the second array, and then perform the equivalent of a merge-sort on both. This will improve speed dramatically and reduce the memory load drastically.
So throw it all out; start using lists of numbers; then sort and merge. It would handle millions of numbers in a matter of seconds.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
modified on Friday, February 26, 2010 1:50 PM
|
|
|
|
|
As an alternative to the sort and merge approach, you may also try using a Dictionary/HashSet. If you have .NET 3.5 available, you could use the Except extension method (which I understand uses a HashSet internally) like so:
Dim temp = ArrayB.Select(AddressOf Double.Parse) _
.Except(ArrayA.Select(AddressOf Double.Parse)) _
.ToArray()
If you don't have the LINQ methods, you could do this yourself:
Dim parsedToRemove As New Dictionary(Of Double, Double)
Dim noDuplicates As New List(Of Double)
For Each parsedA In Array.ConvertAll(ArrayA, AddressOf Double.Parse)
If Not parsedToRemove.ContainsKey(parsedA) Then
parsedToRemove.Add(parsedA, parsedA)
End If
Next
For Each parsedB In Array.ConvertAll(ArrayB, AddressOf Double.Parse)
If Not parsedToRemove.ContainsKey(parsedB) Then
noDuplicates.Add(parsedB)
End If
Next
|
|
|
|
|
Thanks for replies.
Both contains good ideas to resolving the problem.
|
|
|
|
|
Hello
How can i make my program exit say when you would press somting like Ctrl+Esc ??
Thanks
Bob
|
|
|
|
|
What kind of application is it?
If it's a WinForms app, then simply Close() the main form when the right key combination is found in one of the KeyPress/KeyDown events.CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Right on Man
I got it thanks
Bob
|
|
|
|
|
Dear Friends.
I need to set a shortcut key for "activate my program" or "my program show a message" or ... . that means when user is everywhere of windows or on any program, he press Alt+F8 and then my program activates.
How can I set a shortcut key that works on everywhere of windows?Mehdi Ghiasi
modified on Thursday, February 25, 2010 5:42 AM
|
|
|
|
|
See this[^] useful article about global keyboard and mouse hooks.
I hope this helps.
Regards
|
|
|
|
|
Thanks a lot Mehdi Ghiasi
|
|
|
|
|
You are welcome!
|
|
|
|
|
I need to set the camera source for each of 4 video windows in C# without using the windows dialog box.
I have a video capture card that has 4 inputs that can be accessed simultaneously. I have a working application that calls the VideoCapture class. Each time after the first instance I get the Windows Video Device Selection pop up from which I have to manually choose the input for each remaining window. I could live with this except, whatever I choose as the last input is automatically assigned as the device to the first window the next time the application starts. This is unacceptable because the camera assignments are never in the same location.
I would prefer to assign each of the inputs in code and never see the Windows Video Device Selection pop up.
Anyone have an idea how to obtain and pass the device id to the WebCam_Capture.dll?
Thanks
|
|
|
|
|
I also have the same problem...
|
|
|
|
|
My company has a database (MSSQL 2005) system for managing and archiving communications that contain certain sensitive information. It is web-based and allows us to transmit information via https rather than potentially unsecured email. It uses two tables, one for the message itself and one for any attachements that go along with the message. The attachement table is very simple, with only three columns: INT CommId (which maps to the primary key of the messages table), VARCHAR(100) Descr (a user-friendly name for the attached file) and VARBINARY(max) Att (the attached file itself.) This system, clunky as it may seem, serves our security and data-retention needs very well and has allowed us to integrate it gracefully with several back-office apps.
We have an app written in VB6 that I am trying to translate to VB.net 2008. It processes client information and sends a secure communication to our field reps when something comes up for their attention. The communication has a PDF attachement which is the same for every rep but may be changed in the future.
The VB6 app uses the ADODB library -- specifically the ADODB.Stream object -- to put the PDF into the Attachement column. The code looks like this:
Set Strm = New ADODB.Stream
Strm.Type = adTypeBinary
Strm.Open
Strm.LoadFromFile DocPath
With AdodbCmd
.CommandText = InsertQuery
.Parameters.Append .CreateParameter("@CommId", adInteger, adParamInput, , CommId)
.Parameters.Append .CreateParameter("@Descr", adVarChar, adParamInput, 100, Descr)
.Parameters.Append .CreateParameter("@Att", adLongVarBinary, adParamInput, 2147483647, Strm.Read)
.Execute
End With
I want to do exactly this same thing using the 3.5 framework, without having to interop with the ADODB COM library. I cannot guarantee that future versions of the PDF will be below the 8000 character limit, so any solution needs to handle a file of arbitrary length.
Suggestions?modified on Thursday, February 25, 2010 9:59 AM
|
|
|
|
|