-
May 20th, 2021, 07:36 PM
#1
Thread Starter
Fanatic Member
Visual Basic has stopped working. Why?
Recently, it is very often that when I am developing into one of my VB6 projects, and then run it to test the new changes, I suddenly get this error:
https://i.imgur.com/6yd98aP.jpeg
which shows for one or two seconds, and then shows this:
https://i.imgur.com/iRMQU6M.jpeg
Then VB6 closes, and I have to reopen VB6 to continue my work.
It happens quite very often (maybe about one in three "Run" attempts), when I am working on one specific vbp project.
It never happens when I am working on other vbp projects.
Why does this happen?
And why so often?
And why only when I work on one specific vbp project?
Please help.
Thanks.
-
May 20th, 2021, 07:42 PM
#2
Re: Visual Basic has stopped working. Why?
See General protection fault for likely reasons.
-
May 21st, 2021, 07:18 AM
#3
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by dilettante
Thanks.
I read that article, but as for a solution, I couldn't think of anything that could fix the problem.
How about the execution properties of VB6.EXE?
My VB6.EXE has the following properties:
https://i.imgur.com/oqvLjUg.jpeg
Are these properties correct?
Should I change any of them?
Please help.
Thanks.
Ilia
-
May 21st, 2021, 07:19 AM
#4
Re: Visual Basic has stopped working. Why?
I think it's more likely to be a problem caused by your application.
Do you use subclassing? External OCX or DLL files?
-
May 21st, 2021, 03:44 PM
#5
Re: Visual Basic has stopped working. Why?
Have you even tried looking in the Event Log for the crash reason?
Yes, this is almost certainly your program's fault. You have a bug, probably passing bad parameter values to API calls. Unless you can isolate the problem to a small block of code you can show us there isn't much we can do to help.
-
Jul 7th, 2021, 09:55 PM
#6
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by Arnoutdv
I think it's more likely to be a problem caused by your application.
Do you use subclassing? External OCX or DLL files?
I do not use subclassing, but dlls.
I am going to post all the details including the code in a minute (post #8)
Thanks for your help
-
Jul 7th, 2021, 09:56 PM
#7
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by dilettante
Have you even tried looking in the Event Log for the crash reason?
Yes, this is almost certainly your program's fault. You have a bug, probably passing bad parameter values to API calls. Unless you can isolate the problem to a small block of code you can show us there isn't much we can do to help.
I am going to post all the details including the code in a minute (post #8)
Thanks for your help
-
Jul 7th, 2021, 10:14 PM
#8
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Here is the error that I get:
https://i.imgur.com/LQzDZrI.jpg
And here are what I get in the Event log:
https://i.imgur.com/lBctRgA.jpg
https://i.imgur.com/VP0uDQw.jpg
And here is the project:
https://www.mediafire.com/file/qo3qk...st009.zip/file
Here is how to recreate the problem:
Step1: Run the project: (Form1 appears)
Step2: On Form1 click on "Process", or press Alt+P: (Form2 appears)
Step3: On Form2 click on "Exit", or press Alt+X: (Form2 appears)
Repeat steps 2 and 3 until that error "Visual basic has stopped working" happens.
I get it after just one repeat in here.
You probably will also get it after one repeat. If not then repeat several times until it happens.
If you don't get the error, then please go to the following code in form2's Form_Load:
Code:
For i = 1 To 50
Load InkEdit1(i)
InkEdit1(i).Left = InkEdit1(i - 1).Left + InkEdit1(i - 1).Width + 30
InkEdit1(i).Top = InkEdit1(i - 1).Top
InkEdit1(i).Visible = True
Load InkEdit2(i)
InkEdit2(i).Left = InkEdit2(i - 1).Left + InkEdit2(i - 1).Width + 30
InkEdit2(i).Top = InkEdit2(i - 1).Top
InkEdit2(i).Visible = True
Next i
and change the loop counter from 50 to a larger number for example to 100, 200 or 500
I have a feeling that this problem has something to do with InkEdit text boxes, but I don't know why and how to fix it.
Please help.
Thanks a lot.
Ilia
-
Jul 7th, 2021, 11:17 PM
#9
Re: Visual Basic has stopped working. Why?
InkEdit is a very heavy control. 100 on a Form is crazy.
If you are only using InkEdit as a Unicode TextBox/RichTextBox you'd be well advised to use its "inkless" counterpart for pre-Vista Windows versions in compiled applications. This is part of the Tablet Ink SDK. To deploy it though you'll want to be sure to use a Fusion manifest in order to isolate it. You don't want to try to install the SDK version of the OCX (InkEd.dll is an OCX, the extension is just a name: there is nothing magical about the OCX extension which is an alias for DLL) on user's systems.
Most people don't have the SDK and its updates, and proper deployment is beyond them.
Don't use 100 InkEdit controls. At all.
If you need a Unicode TextBox (and most people emphatically DO NOT) there are probably better alternatives. Some are free, some cost money.
But I guess that might impact doing low-ball coding across labor markets, eh?
-
Jul 8th, 2021, 03:33 AM
#10
New Member
Re: Visual Basic has stopped working. Why?
Is Visual Basic Dead? – Yes, It’s Marked for Death
In a way, VB6 is dead because it is no longer being developed by Microsoft. Microsoft released the. NET Framework in 2001, along with a new language C# and an updated Visual Basic. Thanks
-
Jul 8th, 2021, 03:38 AM
#11
Re: Visual Basic has stopped working. Why?
-
Jul 8th, 2021, 03:40 AM
#12
Re: Visual Basic has stopped working. Why?
Originally Posted by marryf543
In a way, VB6 is dead because it is no longer being developed by Microsoft. Microsoft released the. NET Framework in 2001, along with a new language C# and an updated Visual Basic. Thanks
Er, I think you mean Microsoft released the Great Pretender, Visual Fred. A .Net language that somewhat superficially resembles VB but really is an entirely different thing.
-
Jul 8th, 2021, 04:28 AM
#13
Re: Visual Basic has stopped working. Why?
and change the loop counter from 50 to a larger number for example to 100, 200 or 500
Are you trying to simulate a grid control with a huge array of InkEdit controls?
-
Jul 8th, 2021, 08:21 AM
#14
Lively Member
Re: Visual Basic has stopped working. Why?
Originally Posted by IliaPreston
Repeat steps 2 and 3 until that error "Visual basic has stopped working" happens.
I get it after just one repeat in here.
You probably will also get it after one repeat. If not then repeat several times until it happens.
But it is obvious that it will go wrong, sooner or later.
Ilia, ANY controls loaded at runtime, MUST be Unloaded when close the form.
On the event:
Code:
Private Sub Form_Unload(Cancel As Integer)
of Form2 you have to add the code tu unload InkEdit1 controls.
-
Jul 8th, 2021, 06:57 PM
#15
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by Arnoutdv
Are you trying to simulate a grid control with a huge array of InkEdit controls?
No. Not a textual grid.
I am creating something similar to Windows Explorer (showing icons for files).
The icons are displayed in Pictureboxes.
However, the name of each file needs to be displayed below its icon.
To display the file name, I am using an InkEdit, because the file name may be unicode.
The size of the form and the sizes of icons dictate that there are almost always only 24 icons and therefore only 24 InkEdit textboxes.
The additional InkEdit textboxes (on the bottom of Form2) are just added for posting the project to this forum, because I noticed that with those additional InkEdit textboxes, the error "Visual Basic has stopped working" would happen after just one or two repeats of steps 2 and 3, whereas without them, I would get the error after 15 to 20 repeats.
And I wanted to make it easier for everybody in here to observe the problem.
-
Jul 8th, 2021, 07:11 PM
#16
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by LeoFar
...
Ilia, ANY controls loaded at runtime, MUST be Unloaded when close the form.
...
Definitely something that I didn't know.
And I am so pleased that you mentioned that.
And I will implement that advice.
Thanks a lot for your advice.
However, that is NOT what caused the error "Visual basic has stopped working" in my project.
Because there are ONLY 24 Pictureboxes and ONLY 24 InkEdit textboxes on Form2 in my project (the additional ones on the bottom of Form2 were just added for posting the project to this forum. The real project does not have them. see my previous post please)
And those 24 Pictureboxes and InkEdit textboxes are ALL added at design time. NOTHING is loaded at run time.
The Load statement to dynamically load new Pictureboxes and InkEdit textboxes are put in place only as an anticipation that future versions of the project will decide the number of Pictureboxes and InkEdit Textboxes dynamically.
In the current version of my project the Pictureboxes and their corresponding InkEdit Textboxes are NOT loaded at runtime because exactly 24 of them are put on the form at design time. So the Load statements do not happen.
And yet I do get that error (Visual Basic has stopped working) after 15 to 20 repeats of steps 2 and 3.
-
Jul 8th, 2021, 07:13 PM
#17
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Ilia, ANY controls loaded at runtime, MUST be Unloaded when close the form.
Is it true only about InkEdit Textboxes, or about any simple control for example ordinary textboxes, combo boxes, etc?
-
Jul 8th, 2021, 07:23 PM
#18
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by dilettante
InkEdit is a very heavy control. 100 on a Form is crazy.
If you are only using InkEdit as a Unicode TextBox/RichTextBox you'd be well advised to use its "inkless" counterpart for pre-Vista Windows versions in compiled applications. This is part of the Tablet Ink SDK. To deploy it though you'll want to be sure to use a Fusion manifest in order to isolate it. You don't want to try to install the SDK version of the OCX (InkEd.dll is an OCX, the extension is just a name: there is nothing magical about the OCX extension which is an alias for DLL) on user's systems.
Most people don't have the SDK and its updates, and proper deployment is beyond them.
Don't use 100 InkEdit controls. At all.
If you need a Unicode TextBox (and most people emphatically DO NOT) there are probably better alternatives. Some are free, some cost money.
But I guess that might impact doing low-ball coding across labor markets, eh?
Thanks for your help.
So, basically, I am wondering what is the best alternative to an InkEdit textbox in my project.
I need to display a unicode text in a box.
No editing is required (for example the user typing anything or pasting anything in there).
In fact you can see that in the project, the existing InkEdit Textboxes have their "Locked" property set to False.
So, it is just a DISPLAY of a unicode text.
With this limited functionality requirement, I am wondering if I have better options or not?
Please note: I really don't want to use a manifest. I used a manifest last year and I am so dissatisfied with it.
Is there a simple solution?
For example:
- any simple textbox that i can use that does the job?
- Can I use an ordinary Textbox or RichTextbox and use some API call to display unicode text in it?
- any other simple option?
Please help.
Thanks.
Ilia
-
Jul 9th, 2021, 05:21 AM
#19
Lively Member
Re: Visual Basic has stopped working. Why?
Originally Posted by IliaPreston
Is it true only about InkEdit Textboxes, or about any simple control for example ordinary textboxes, combo boxes, etc?
Already written: ANY controls.
-
Jul 10th, 2021, 05:43 PM
#20
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by LeoFar
Already written: ANY controls.
Thanks for your help
-
Jul 10th, 2021, 05:45 PM
#21
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by IliaPreston
Thanks for your help.
So, basically, I am wondering what is the best alternative to an InkEdit textbox in my project.
I need to display a unicode text in a box.
No editing is required (for example the user typing anything or pasting anything in there).
In fact you can see that in the project, the existing InkEdit Textboxes have their "Locked" property set to False.
So, it is just a DISPLAY of a unicode text.
With this limited functionality requirement, I am wondering if I have better options or not?
Please note: I really don't want to use a manifest. I used a manifest last year and I am so dissatisfied with it.
Is there a simple solution?
For example:
- any simple textbox that i can use that does the job?
- Can I use an ordinary Textbox or RichTextbox and use some API call to display unicode text in it?
- any other simple option?
Please help.
Thanks.
Ilia
Any help on this issue will be greatly appreciated.
Thanks.
Ilia
-
Jul 10th, 2021, 10:46 PM
#22
Re: Visual Basic has stopped working. Why?
-
Jul 11th, 2021, 07:58 PM
#23
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
I found this code in my own projects (I had probably found it somewhere on the web some years ago):
Code:
Public Sub DrawUnicodeOnPicturebox(ByRef Pct As PictureBox, ByVal sText As String)
Dim rct As RECT
'Pct.ScaleMode = vbPixels ...... Done in design mode (on the screen instead of in the code)
'Pct.AutoRedraw = True ...... Done in design mode (on the screen instead of in the code)
Pct.Cls
rct.Top = 0 'Set Margin
rct.Left = 0 'Set Margin
rct.Right = rct.Left + Pct.Width
rct.Bottom = rct.Top + Pct.Height
DrawTextW Pct.hDC, StrPtr(sText), Len(sText), rct, DT_WORDBREAK Or DT_CALCRECT
DrawTextW Pct.hDC, StrPtr(sText), Len(sText), rct, DT_WORDBREAK
Pct.Refresh
End Sub
I just tested it and it works perfectly.
Then I tried to modify it so that the text could be drawn on an ordinary VB6 Textbox
Here is the modified version:
Code:
Public Sub DrawUnicodeOnTextbox(ByRef T1 As TextBox, ByVal sText As String)
Dim rct As RECT
T1.Text = ""
T1.Refresh
rct.Top = 0 'Set Margin
rct.Left = 0 'Set Margin
rct.Right = rct.Left + T1.Width
rct.Bottom = rct.Top + T1.Height
DrawTextW T1.hWnd, StrPtr(sText), Len(sText), rct, DT_WORDBREAK Or DT_CALCRECT
DrawTextW T1.hWnd, StrPtr(sText), Len(sText), rct, DT_WORDBREAK
T1.Refresh
End Sub
But, this one doesn't work.
It doesn't write anything into the textbox
I don't know why it doesn't draw the text in there.
The nature of the job (drawing the text in a certain rectangle on the screen) is the same.
So, why doesn't it work?
Please help.
Thanks.
-
Jul 11th, 2021, 08:21 PM
#24
Re: Visual Basic has stopped working. Why?
In the first example you are drawing to the PictureBoxes hDC (correct). In the second example, you are trying to draw to a TextBoxes hWnd (incorrect). Why are you trying to draw text on TextBox?
-
Jul 11th, 2021, 08:47 PM
#25
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by jpbro
In the first example you are drawing to the PictureBoxes hDC (correct). In the second example, you are trying to draw to a TextBoxes hWnd (incorrect). Why are you trying to draw text on TextBox?
Drawing the text on a Picturebox definitely is fine for me.
However, I just thought why not EXPERIMENT with this idea a bit further to see how I can get it to work for a standard VB6 Textbox as well. (Just to learn something from this, and to enjoy the challenge)
Bottom line is that if I can't get it to work with a Textbox, I will use the Picturebox, as that works fine for my project.
But, before giving up on the Textbox, I want to do my best to see if I can get it to work).
Regarding the hDC and hWnd, unfortunately I don't know the difference (Please forgive me for my ignorance).
As far as I understand (which is certainly wrong) each one of the hDC and hWnd is the handle of the control, and therefore should be the same thing.
Not sure though.
If you could explain the difference, it would be greatly appreciated.
Thanks.
Ilia
-
Jul 14th, 2021, 12:16 PM
#26
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Actually, after some experimentation, I found a way to do that (display unicode text in a standard VB6 Textbox).
And I put it in here, so that it may one day be helpful to someone:
Code:
Public Sub DrawUnicodeOnTextbox(ByRef TextBoxToDrawOn As TextBox, ByVal sText As String)
Dim rct As RECT
Dim TextBoxhDC As Long
TextBoxToDrawOn.Text = ""
TextBoxToDrawOn.Refresh
rct.Top = 0 'Set Margin
rct.Left = 0 'Set Margin
rct.Right = rct.Left + TextBoxToDrawOn.Width
rct.Bottom = rct.Top + TextBoxToDrawOn.Height
TextBoxhDC = GetDC(TextBoxToDrawOn.hwnd)
DrawTextW TextBoxhDC, StrPtr(sText), Len(sText), rct, DT_WORDBREAK Or DT_CALCRECT
DrawTextW TextBoxhDC, StrPtr(sText), Len(sText), rct, DT_WORDBREAK
'TextBoxToDrawOn.Refresh
End Sub
-
Jul 14th, 2021, 12:27 PM
#27
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by jpbro
Thanks again for your help.
As I said, the following code does the job:
Code:
Public Sub DrawUnicodeOnPicturebox(ByRef Pct As PictureBox, ByVal sText As String)
Dim rct As RECT
'Pct.ScaleMode = vbPixels ...... Done in design mode (on the screen instead of in the code)
'Pct.AutoRedraw = True ...... Done in design mode (on the screen instead of in the code)
Pct.Cls
rct.Top = 0 'Set Margin
rct.Left = 0 'Set Margin
rct.Right = rct.Left + Pct.Width
rct.Bottom = rct.Top + Pct.Height
DrawTextW Pct.hDC, StrPtr(sText), Len(sText), rct, DT_WORDBREAK Or DT_CALCRECT
DrawTextW Pct.hDC, StrPtr(sText), Len(sText), rct, DT_WORDBREAK
Pct.Refresh
End Sub
And I am going to use that in my project.
But, there is still one problem.
The line is NOT broken into a new line when it reaches the right border of the Picturebox.
Even though my code (above) uses the DT_WORDBREAK, it does NOT continue the rest of a long line in a new line.
Here is a screen print:
https://i.imgur.com/fQ01NLl.jpeg
Please help
Thanks.
-
Jul 15th, 2021, 09:05 AM
#28
Re: Visual Basic has stopped working. Why?
It looks like your Pct.ScaleMode = vbPixels has been commented out, have you set the ScaleMode of the PictureBox to vbPixels in the Properties pane? If not, your ScaleMode is probably vbTwips, and your draw rectangle will be 10-15x the width/height you want as most APIs use Pixels exclusively.
-
Jul 15th, 2021, 05:05 PM
#29
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by jpbro
It looks like your Pct.ScaleMode = vbPixels has been commented out, have you set the ScaleMode of the PictureBox to vbPixels in the Properties pane? If not, your ScaleMode is probably vbTwips, and your draw rectangle will be 10-15x the width/height you want as most APIs use Pixels exclusively.
Let me first thank you for your help.
Yes. I have definitely set the Scalemode to pixels in design mode.
Here is the test project:
https://www.mediafire.com/file/yk8nj...st010.zip/file
And here is a new screen print of this test:
https://i.imgur.com/AGIp596.jpeg
As you see, the text is truncated off when it reaches the right border of the pictureboxes.
It does not continue to the next line.
It should continue to the next line.
I don't know how to make that happen.
Please help
Thanks a lot.
Ilia
-
Jul 15th, 2021, 05:31 PM
#30
Re: Visual Basic has stopped working. Why?
-
Jul 17th, 2021, 04:37 PM
#31
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by Arnoutdv
Thanks for your help.
I used DT_EDITCONTROL
But, that doesn't work either.
Please help.
Thanks.
-
Jul 17th, 2021, 07:20 PM
#32
Re: Visual Basic has stopped working. Why?
Please post your latest code (or small sample), with API & constant declarations.
-
Jul 18th, 2021, 05:05 PM
#33
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by jpbro
Please post your latest code (or small sample), with API & constant declarations.
Thanks a lot for your response.
Here is the new test project:
https://www.mediafire.com/file/qt0we...st011.zip/file
Please note that there are three command buttons, each of which using a different function to write to the picture boxes.
The first two command buttons use DrawTextW and the third one uses DrawTextExW
None of them does it properly.
All three of the above codes truncate off the line when it reaches the right border of the Picturebox.
They must break the line into a new line when it reaches the right border of the Picturebox, but they don't.
Please help.
Thanks again
Ilia
-
Jul 18th, 2021, 10:08 PM
#34
Re: Visual Basic has stopped working. Why?
Thanks for supplying the demo code.
You are using the PictureBox's Width property which will be in the container control's ScaleMode (in this case Twips). You should use the PictureBox's ScaleWidth property instead (which will be in the PictureBox's ScaleMode units - e.g. Pixels).
For example:
Code:
Public Sub Test1_DrawUnicodeOnPicturebox(ByRef Pct As PictureBox, ByVal sText As String)
Dim rct As RECT
Pct.Cls
rct.Top = 0 'Set Margin
rct.Left = 0 'Set Margin
rct.Right = Pct.ScaleWidth
rct.Bottom = Pct.ScaleHeight
DrawTextW Pct.hDC, StrPtr(sText), Len(sText), rct, DT_WORDBREAK Or DT_EDITCONTROL
Pct.Refresh
End Sub
-
Jul 20th, 2021, 08:38 PM
#35
Thread Starter
Fanatic Member
Re: Visual Basic has stopped working. Why?
Originally Posted by jpbro
Thanks for supplying the demo code.
You are using the PictureBox's Width property which will be in the container control's ScaleMode (in this case Twips). You should use the PictureBox's ScaleWidth property instead (which will be in the PictureBox's ScaleMode units - e.g. Pixels).
For example:
Code:
Public Sub Test1_DrawUnicodeOnPicturebox(ByRef Pct As PictureBox, ByVal sText As String)
Dim rct As RECT
Pct.Cls
rct.Top = 0 'Set Margin
rct.Left = 0 'Set Margin
rct.Right = Pct.ScaleWidth
rct.Bottom = Pct.ScaleHeight
DrawTextW Pct.hDC, StrPtr(sText), Len(sText), rct, DT_WORDBREAK Or DT_EDITCONTROL
Pct.Refresh
End Sub
Yes. It works fine now.
Thanks a lot for all your help.
Ilia
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|