|
Very nice indeed. I hadn't considered the multiple zero, and leading zero scenarios yet, good catch.
Now I haven't bothered (yet) checking for decimal separators, as I was looking to limit to whole integers, so using Luc's advice, I got this:
In a generic KeyPress event that handles all textboxes:
Select Case True
Case e.KeyChar = CChar("-")
If sender.SelectionStart > 0 Or sender.Text.Contains("-") Then
e.Handled = True
End If
Case Not Char.IsDigit(e.KeyChar)
e.Handled = True
End Select
...and in a generic Leave event that handles all textboxes:
If sender.text.length < 1 Or sender.text = "0" Or sender.text = "-" Then
MsgBox("The field may not be empty, and the value may not be zero or just minus.", MsgBoxStyle.Critical)
sender.text = "1"
sender.focus()
End If
Now that you made me aware of it, I think I'll just use the Leave event to drop leading zeros and check for multiple-zeros-only.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hello my favorite forum!
I have problem i have converted vb6 code to vb.net its a application for images...
and i have problem with Image descriptor to picturebox to image to bitmap??? not shure...
i have:
Structure imgdes
Dim ibuff As Integer
Dim stx As Integer
Dim sty As Integer
Dim endx As Integer
Dim endy As Integer
Dim buffwidth As Integer
Dim palette As Integer
Dim colors As Integer
Dim imgtype As Integer
Dim bmh As Integer
Dim hBitmap As Integer
End Structure
Structure GUID
Dim Data1 As Integer
Dim Data2 As Short
Dim Data3 As Short
'Dim Data4() As Byte
<VBFixedArray(7)> Dim Data4() As Byte
'UPGRADE_TODO: "Initialize" must be called to initialize instances of this structure. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="B4BFF9E0-8631-45CF-910E-62AB3970F27B"'
Public Sub InitializeMe()
ReDim Data4(7)
End Sub
End Structure
Public Function image_to_picturebox(ByRef srceimg As imgdes) As System.Drawing.Image
Dim rcode As Object
Dim retval As Integer
Dim Pic As New PicBmp
' IPicture requires a reference to "Standard OLE Types."
' in VB6 Select: Project, References, and check OLE Automation
Dim IPic As System.Drawing.Image
'UPGRADE_WARNING: Arrays in structure IID_IDispatch may need to be initialized before they can be used. Click for more: 'ms-help:
Dim IID_IDispatch As New GUID
Dim tempimage As imgdes
If (srceimg.hBitmap = 0) Then
' We have a packed dib, gotta make it a dib section-type of image
'UPGRADE_WARNING: Couldn't resolve default property of object rcode. Click for more: 'ms-help:
rcode = dibtoimage(srceimg.bmh, tempimage)
'UPGRADE_WARNING: Couldn't resolve default property of object rcode. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
If rcode = NO_ERROR Then
' Replace previous image
freeimage(srceimg)
copyimgdes(tempimage, srceimg)
End If
End If
' Fill in with IDispatch Interface ID.
IID_IDispatch.InitializeMe()
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
' Fill Pic with necessary parts.
With Pic
.Size = Len(Pic) ' Length of structure.
.Type = 1 ' Type of Picture (bitmap).
.hBmp = srceimg.hBitmap ' Handle to bitmap.
.hPal = 0 ' Handle to palette (may be null).
End With
' Create Picture object.
retval = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
'MsgBox(retval.ToString)
If (retval = 0) Then
image_to_picturebox = IPic
Else
image_to_picturebox = My.Resources.notavi
End If
End Function
Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (ByRef PicDesc As PicBmp, ByRef RefIID As GUID, ByVal fPictureOwnsHandle As Integer, ByRef IPic As System.Drawing.Image) As Integer
and the problem is that "retval = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)" returns -2147467262 and should return 0 but i dont think its problem with OleCreatePictureIndirect!
i think its problem somewhere in IID_IDispatch or Pic can annyone help?
i left all those update comments from microsoft so maybe it can be helpful?!?
Thanks
|
|
|
|
|
First of all, what exactly are you trying to do?
There may be much better ways to do it now with managed code, rather than trying to upgrade old VB6 codebase.
|
|
|
|
|
hi Dave!
daveauld wrote: First of all, what exactly are you trying to do?
this is vb6 application http://rapidshare.com/files/389129825/compar.zip.html[^] and i need the compare two images in my application like i would with this application! this is the easiest way i explain...
daveauld wrote: There may be much better ways to do it now with managed code, rather than trying to upgrade old VB6 codebase.
i know i made mine but its to slow and i dont get good results and here i get all good with this one!
Thanks
|
|
|
|
|
sorry, but i will not download the file from the link while at work, so don't know what the applications does.
in what way are you trying to compare? visually? file content? byte by byte? pixel x pixel?
Maybe your version that runs slow just needs the implementation overhauled and maybe is doing things not required?
|
|
|
|
|
daveauld wrote: sorry, but i will not download the file from the link while at work, so don't know what the applications does.
dont worry! :P be happy...
daveauld wrote: in what way are you trying to compare? visually? file content? byte by byte? pixel x pixel?
i need visualy compare, exsample:
compare of two scanned images (exsample of small busines card), one scaned image is original and other one is a little ripped off "distroyed" and i need to detect which part is different (which part is missing) and how much percent of it! hope u understand. thats the problem with my code becose i scan pixel by pixel and scanned image have manny pixels :P and gives me nothing becose every pixel is different (i also tried to give some tolerancy for pixels but didnt success) so i want to convert that vb6 code becose it works (fast, and gives me what i need) just i dont understand in that vb6 code nothing why is using ole, guid, dispatch, imagedescriptor!?!? i only worked with bitmap, and graphics (i am new in visualy and .net drawing)
Thanks
|
|
|
|
|
I know what your on about, but do not have the experience with any imaging techniques.
I was thinking out of the box, and the difference between 2 images is similiar to how motion detection works. (or one method of it).
Maybe this article could help you come up with a solution.
It is in C#, but should be easily done in vb.net
Motion Detection Algorithms[^]
|
|
|
|
|
awww nice article! will be useful for my home door unlocker face recognition software! :P
but its to much i go look in this code now to complete my problem now!
i will keep trying to make the updated vb6 code to work... will wait to see what microsoft will tell becose i sent them email with my problem!
Annyway Dave thank you werry much to waisting your time on me! :P
|
|
|
|
|
|
Hi All,
I have written a small program that loops through a number of SQL Server Reporting Services reports using the vb.net WebBrowser object to display on a large flat screen TV.
All works well, on the first loop all data is shown correctly. However the following loops just show the same data, even if the base data has changed. How do I clear the cache on this.
I have tried displosing of the WebBrowser object when it gets to the end of each run, and then creating a new one. I have tried various different commands to clear cache. But the only ways I can refresh the data is to either restart the program, or wait until the page is fully loaded and then cause a page refresh (which looks a bit messy).
I would be grateful if anyone has any ideas on this.
Many thanks.
|
|
|
|
|
Perhaps you'll find this[^] article helpful.
My advice is free, and you may get what you paid for.
|
|
|
|
|
The alternative is that your code has a bug. Not having seen any, we can't tell for sure.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
We had a similar issue, but not with reporting services reports. We tried setting the webpage expiration, telling it to never cache, disposing of the WebBrowser object (it does not dispose by the way, it hangs around attached to the calling process and then complains if you try to use it again), all to no avail.
The only solution was to remove the URL from the cache. If fact we ended up coding that into every call (remove from cache, then navigate), in the one class that everything else calls of course.
Here is the remove from cache code.
Public Shared Sub DeleteFromUrlCache(ByVal url As String)
Dim apiResult As Long = DeleteUrlCacheEntry(url)
If apiResult <> 0 Then
Return
End If
Dim lastError As Integer = Marshal.GetLastWin32Error()
If lastError = ERROR_ACCESS_DENIED Then
Throw New ApplicationException(String.Concat("Access denied: ", url))
End If
End Sub
Public Const ERROR_ACCESS_DENIED As Integer = 5
<DllImport("wininet.dll", SetLastError:=True)> _
Private Shared Function DeleteUrlCacheEntry(ByVal lpszUrlName As String) As Long
End Function
|
|
|
|
|
Thats brilliant, Man from U.N.C.L.E., just what I need. Seems to be a bit of a weekness in the WebBrowser control. But this work around is very good.
Thanks again.
|
|
|
|
|
Avoid inserting a duplicate record using vb.net
|
|
|
|
|
Just query the database to see if the data exists, if it doesn't, call your insert method.
This requires two calls to the server and could prove costly. You should do this in your Stored Procedure on the server.
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
Why don't you set up the database columns to not accept Duplicate values. This would negate 2 calls to the database and would make your inserts faster.
|
|
|
|
|
You are doing it again.
Please do not post the same question again, and again.
If you do not get an answer right away, have patience. People will answer in their own good time, not in yours.
When you do not understand the answer, or if you think that people have not understood your question, and you want to ask your question in other words, use the same post. At the bottom of each answer is a Reply link. Please, please, please, use it.
That way it will be easier for people to understand your problem and help you find a solution.
Creating a new post each time, is unnecessary and irritates a lot of people here.
My advice is free, and you may get what you paid for.
|
|
|
|
|
faisalali_78 wrote: Avoid inserting a duplicate record using vb.net
OK, I will.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Try also to avoid it using C++, C#, COBOL, PYTHON, VB6, VBA, JAVA, and any other language you can think of / know how to use.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Great idea. Thanks for the tip!
|
|
|
|
|
avoiding duplication, how we can check before inserting data in a table in vb.net
|
|
|
|
|
Erhm... perform a select before you insert?
|
|
|
|
|
Hello,everyone!Need help about adding controls.Now I want to do this:if there is one pannel with some controls such as text box or combo box,when I clicked the button "Add" ,a same pannel wiht same controls would display under the first pannel;then the button "Add" go down below the second pannel.Then I clicked button once again,there will be three same peannel.
What I should do to achieve this ?Please give me some suggestions!Thanks a lot!
modified on Tuesday, May 18, 2010 10:44 PM
|
|
|
|
|
For a WinForm app, there seem to be two very different ways to add controls to a form:
- one is by using the "Visual Designer"
- the other is by adding some code that creates and adds controls at run-time.
However, the designer basically does two things for you:
1. it adds code to some file, which you may not have seen yet; if your form is called Form1, it consists of several files, including Form1.vb; the designer creates and controls Form1.designer.vb (you may have to fiddle some buttons/settings for Studio to show it in the Solution pane, can't remember the details).
2. and then it lets Studio execute such code, and that is how the controls suddenly appear on you form. (No they are not really drag-and-dropped, your drag operation tells the Designer to add and then execute code!)
So the suggestion is clear: do it once with designer, then go and peek inside that auto-generated file.
BTW: do not edit the designer files, just learn from them, and add similar things to your code.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|