|
Hi,
I have a VB 6 application which crashes giving system message about the crash.
Scenario:
There is a simple form where there is one text box and 2 command buttons, submit and cancel.The text box is restricted to accept only numeric values. Once valid data is entered into the textbox i press ENTER + (some other key) simultaneously. The entire application crashes!
The ENTER + (some other key) press happens by mistake for sure, but i cant afford to loose all that data because of the crash.
If i knew the exact cause of the crash i could handle that event.
Can you help me out here? Have any of you faced such a situation?
-Shruti
|
|
|
|
|
First, why do you torture yourself with vb6, when vb.net is available and free (Visual Studio 2008 Express)?
Your application crashes after you have pressed enter + (some other key), because enter is not numeric (it is a control key), but it is an actual value entered.
So validate the value entered in the textbox before you use it. At the same time this will prevent the program from crashing when the user copy-pastes a value into the textbox.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Yes i understand, but when i debug i can see the control directly going to the submit button's click event when i press ENTER.
Another point, while debugging i do not get any errors. It crashes only once the application is installed.
-Shruti
|
|
|
|
|
After having pressed enter, and before doing anything with whatever value was entered in the textbox, do you validate the entered value?
What it sounds like, is that the following sequence of events takes place:
1. the user (you) enters "123" in the textbox
2. the user (you) presses the enter key (and possibly some other key as well) while the caret is still in the textbox
3. the textbox now contains the value "123Chr(13)"
4. somehow the click event of the submit button is fired
5. some code executes, that expects to receive a numerical value from the textbox (i.e. 123) but receives "123Chr(13)"
6. crash.
When you debug do you walk through the code all the way to point 5 ?
My advice is free, and you may get what you paid for.
|
|
|
|
|
Yes i do run through all 5 points of the code
|
|
|
|
|
It sounds to me like
1 - you ignored the point that VB6 is obsolete, and skills in VB6 close to useless
2 - you pretty much missed the point being made to you on what you should do to debug it
3 - you probably have code that assumes that you entered a number, when the enter character means the parsing code fails
4 - you somehow expect us to magically fix your problems, despite not posting any code, or even showing signs of knowing which code it is that is blowing up
I think you've got some problems
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
You could try to see if you can find out anything about the error by adding some error handling:
Private Sub YourSub()
On Error GoTo ErrHandler
'Your code that uses the value from the textbox here'
ErrHandler:
MsgBox (Err.Description)
End Sub
then compile you app and run it.
My advice is free, and you may get what you paid for.
modified on Wednesday, September 2, 2009 6:55 AM
|
|
|
|
|
Hi,
I am trying to draw a line in picture box control using the following code in the Picturebox Paint Event : -
Dim g As Graphics = MainPanel.CreateGraphics
g.DrawLine(Pens.Red, Convert.ToInt32(0), Convert.ToInt32(0), Convert.ToInt32(190), Convert.ToInt32(190))
But , unfortunately the line is not drawn can anybody tell the reason
Thanks
|
|
|
|
|
Download Visual Basic Power Pack 2 or 3 both available and it contains several controls like Line Shape , Rectangle, Oval Shape and Print form
Best Of Regards,
SOFTDEV
Sad like books with torn pages, sad like unfinished stories ...
|
|
|
|
|
Generally speaking the picturebox control is meant to display an image, not to draw in. If you want to draw a line, don't do it in the picturebox but rather on top of it.
Alternatively, you could first create an image of the line and then load that image into the picturebox.
My advice is free, and you may get what you paid for.
|
|
|
|
|
kjsl2k9 wrote: Dim g As Graphics = MainPanel.CreateGraphics
g.DrawLine(Pens.Red, Convert.ToInt32(0), Convert.ToInt32(0), Convert.ToInt32(190), Convert.ToInt32(190))
All of this code is bad. Every last bit of it. Handle a paint event, never call CreateGraphics unless you're drawing a rubber band. Draw directly onto the form, not into a picture box, that's not what it's for. Use the graphics object passed into the paint event.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Please I would like your help in the following questions,(Please supply code example.)
:
1. How can I make a program’s able to link with its database independent of location?
There is a program I am trying to create. It works fine only if the database is placed in a particular location. I would like the program to be such that a user can install the program in any location and my program can look for and locate the database.
In a multi-tier network application, let us assume the following conditions exist:
• The front –end is in VB.NET/ C# .NET. (I am at home with any of them so you can write the code in any of these languages) The back-end is an oracle database.
2. How can I link the two? The front-end is not in the same computer as the database.
3. How can I make my apps able to read/ write real-time data?
Thank you .
ihe
|
|
|
|
|
ihe wrote: 1. How can I make a program’s able to link with its database independent of location?
You will need to have some sort of local data store (or registry entry etc) that records the location of your database. When your system opens, it attempts to connect to the database, if it fails, it prompts the user to locate the database and saves it to the data store (or registry entry etc).
ihe wrote: 2. How can I link the two?
Using Connections.
ihe wrote: The front-end is not in the same computer as the database.
This is standard design.
ihe wrote: 3. How can I make my apps able to read/ write real-time data?
Write your application to get data from the database (through the connection) and display it to the user, then write data to the database when the user clicks update (or save, or do it, or whatever).
|
|
|
|
|
Please can you give sample codes?
ihe
|
|
|
|
|
Please don't cross post. Did you want VB or C# code ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Please in any (Vb.NET or C#.NET). I write in the two languages.
ihe
|
|
|
|
|
Hello gurus,
I'd really need someone advanced in graphics since I have a weird error which I can't locate at all. I think it's connected with a piece of code that's supposed to display a grayscale image:
arrayImage = dpx.GS16ArrayFromRawArray(dpx.DPXPixelArray)
gch = GCHandle.Alloc(arrayImage, GCHandleType.Pinned)
Dim pBuf As IntPtr = gch.AddrOfPinnedObject
Dim stride As Integer = Width * 2
Me.CurrentBitmap = New Bitmap(Width, Height, stride, Imaging.PixelFormat.Format16bppGrayScale, pBuf)
gch.Free()
I might have to mention that I use the exact same process (with adapted parameters) to read an RGB image from a byte array (24bppRGB). The image data in this case are supplied as an array of UInt16 - and the values seem to fit. When stepping through the code, everything seems to be fine.... but a little bit later in connection with the update of a progressBar , I get an InvalidArgumentException.
The stack trace leaves me the following:
bei System.Drawing.Graphics.CheckErrorStatus(Int32 status)
bei System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
bei System.Drawing.Graphics.DrawImage(Image image, Rectangle rect)
bei System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
bei System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
bei System.Windows.Forms.Control.WmPaint(Message& m)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.Run(ApplicationContext context)
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
bei HeadersTwo.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Zeile 81.
bei System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()
Does anyone of you probably have an idea where to start looking for the error?
Thanks a lot!
Mick
|
|
|
|
|
I am pretty sure your calculation of stride is wrong, unless it means something different to what it meant when I used the term in my image processing days. I am also surprised that a 16 bit conversion exists inside the framework, but I guess it looks like it does.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi,
yes you can construct an image/bitmap from raw data with one of its constructors.
However the documentation clearly states "The caller is responsible for allocating and freeing the block of memory specified by the scan0 parameter, however, the memory should not be released until the related Bitmap is released." so the way I understand it is you should not free the GCHandle right away, the raw data should not be allowed to move around for as long as your bitmap is alive.
|
|
|
|
|
Aahhh - I see! I thought I had taken care of this issue by assigning the new bitmap to the Me.CurrentBitmap property, which is later used as the source of a picture box... I should have assigned a copy and then freed the original, right?
What do you say regarding Christian's hint about the stride parameter?
[EDIT:]
I just replaced the relevant lines with
Dim arrBmp As New Bitmap(Width, Height, stride, Imaging.PixelFormat.Format16bppGrayScale, pBuf)
Me.CurrentBitmap = New Bitmap(arrBmp, arrBmp.size)
gch.Free()
and now I'm receiving an ArgumentException in the second line.
modified on Wednesday, September 2, 2009 2:20 PM
|
|
|
|
|
Hi,
1. yes, a good approach would be to create the bitmap, make a copy, dispose of the original, then free the GCHandle. The bad thing is this temporarily takes twice the amount of memory.
2. MSDN says stride must be a multiple of 4, so width should be even (or rounded up, raw data permitting).
3. you have to look at Exception.ToString() to get all the available details. If still insufficient, experiment with different parameter combinations. And maybe after all, 16-bit isn't supported after all? the doc says it gets converted to some other format right away.
|
|
|
|
|
Hi Luc,
I'll follow that approach. Btw it's been your own idea from an older thread.
Width is 1024, so I guess it should be allright.
Exception.ToString() shows a ArgumentException "Invalid Parameter". Finally it refers to the line where I try to assign the first bitmap to a new one... Does that tell you anything? Since that happens when I try to assign the 16-bit-Grayscale format to a regular bitmap, I'm afraid it really might not be supported. Or - as the doc says - that it's converted to anything special that doesn't want to be converted to a normal thing...
Since I actually just want to display a grayscale, I could anyway live much better with 8-bit. BUT: There's no such PixelFormat as "8bppGrayscale", just indexed colours which loads (!) but shows a weird picture of course. Do you by any chance know which PixelFormat I'd have to choose for a simple grayscale image?
Thanks
Mick
|
|
|
|
|
Michael Schäuble wrote: your own idea Wink from an older thread.
yep. copying an image solves a file-locked problem in Image.FromFile; using FromStream does the same.
I have used this code:
byte[] bytes=new byte[32*1024];
GCHandle handle=GCHandle.Alloc(bytes, GCHandleType.Pinned);
IntPtr ptr=handle.AddrOfPinnedObject();
Bitmap bm1=new Bitmap(16, 16, 1024, PixelFormat.Format8bppIndexed, ptr);
log("bm1 OK");
Bitmap bm4=new Bitmap(1000, 1000);
Graphics g=Graphics.FromImage(bm4);
g.DrawImage(bm1, 0, 0);
log("bm4 drawn");
Bitmap bm2=new Bitmap(bm1);
bm1.Dispose();
handle.Free();
Bitmap bm3=new Bitmap(bm2);
bm2.Dispose();
log("size ="+bm3.Size);
bm3.Dispose();
to experiment and find out which formats are acceptable; it seems Format16bppGrayScale is the
odd one out: .NET is willing to construct a bitmap (bm1) but refuses to use it (either in bm4 or in bm2)
Work arounds:
1.
Format1bppIndexed is the one closest to what you could use, but I have no idea on how to install an appropriate lookup table.
2.
What is bound to work is convert the raw data to a format that will be understood, such as Format32bppRgb
All it takes is replacing each 16-bit value X by a new value Y where Y equals something like X/4 * 0x1010101 which assumes X has 10 significant bits, so 2 bits need to be thrown out, and the gray value gets copied to all bytes (that's what the multiplication does when using unsigned arithmetic).
modified on Wednesday, September 2, 2009 3:59 PM
|
|
|
|
|
Hello everyone,
I got a really strange problem. I could make 2 computers to communicate to each other through hyperterminal, 115200,8,n,1 Hardware(CTS,RTS).
Then I decide to make a VB6 program in one of those (with the same parameters). Sending data from VB6 is just fine (the hyperterminal in the other computer shows the same data), but when it receives any data the program crashes and the program manager shows 99% of the cpu is beings used by VB6
Note.: There´re no infinite loops neither "OnComm" function is avaible in the algorithm.
Did anyone have this problem? Or knows how to solve it?
Thanks
|
|
|
|
|
Why would you use VB6 ? It's out of date, and was always rubbish.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|