-
Nov 30th, 2017, 12:43 PM
#1
Thread Starter
Addicted Member
[RESOLVED] How can "true" be an invalid property ?
Good evening everybody,
Two pieces of code
Code:
Private Sub InitSources(Flag As Boolean)
' ...
End Sub
Code:
Private Sub KN_Change(Index As Integer) ' KN is a textBox
' ...
InitSources (True) ==> error 380 Invalid property value
' ...
End Sub
Most of the time the call to InitSources works fine, in some circumstances which I cannot reproduce it gives an error 380.
To my opinion "True" is always a boolean, how can that property be invalid ?
-
Nov 30th, 2017, 12:57 PM
#2
Re: How can "true" be an invalid property ?
Originally Posted by Herve_be
Good evening everybody,
Two pieces of code
Code:
Private Sub InitSources(Flag As Boolean)
' ...
End Sub
Code:
Private Sub KN_Change(Index As Integer) ' KN is a textBox
' ...
InitSources (True) ==> error 380 Invalid property value
' ...
End Sub
Most of the time the call to InitSources works fine, in some circumstances which I cannot reproduce it gives an error 380.
To my opinion "True" is always a boolean, how can that property be invalid ?
There must be something else involved.
Can you provide an example project to recreate the error?
-
Nov 30th, 2017, 12:59 PM
#3
Re: How can "true" be an invalid property ?
The error is occurring inside the InitSources code. We need to see more of that sub.
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Nov 30th, 2017, 03:06 PM
#4
Re: How can "true" be an invalid property ?
Perhaps in some case you have a var named True that is not a boolean type.
My suggestion, add a breakpoint before the call then step through the code and check the value of true
-
Nov 30th, 2017, 03:54 PM
#5
Re: How can "true" be an invalid property ?
Originally Posted by DataMiser
Perhaps in some case you have a var named True that is not a boolean type.
He'd be getting a type mismatch error if that were the case...
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Nov 30th, 2017, 04:21 PM
#6
Re: How can "true" be an invalid property ?
Originally Posted by DataMiser
Perhaps in some case you have a var named True that is not a boolean type.
My suggestion, add a breakpoint before the call then step through the code and check the value of true
AFAIK that's not possible to do:
Code:
Private True as String
-
Nov 30th, 2017, 04:34 PM
#7
Re: How can "true" be an invalid property ?
Indeed it is:
Code:
Private [True] as String
Although, I suppose it could be argued that it's no longer named True, but [True]... but there it is.
-tg
-
Nov 30th, 2017, 05:16 PM
#8
Re: How can "true" be an invalid property ?
Originally Posted by techgnome
Indeed it is:
Code:
Private [True] as String
Although, I suppose it could be argued that it's no longer named True, but [True]... but there it is.
-tg
You can't.
Code:
Private [True] as String
But you gave an idea for other thing, thanks:
Code:
Public Enum BooleanEx
[False] = 0
[True] = -1
[Automatic] = 2
End Enum
Last edited by Eduardo-; Nov 30th, 2017 at 05:25 PM.
-
Dec 1st, 2017, 03:25 AM
#9
Thread Starter
Addicted Member
Re: How can "true" be an invalid property ?
Originally Posted by DataMiser
My suggestion, add a breakpoint before the call then step through the code and check the value of true
I cannot reproduce the case, if I do so it works fine.
Originally Posted by ColinE66
The error is occurring inside the InitSources code. We need to see more of that sub.
Each sub has its own trapping
Code:
Private Sub KN_Change(Index As Integer)
67580 On Error GoTo KN_Change_Error
67590 If Val(KN(Index).Text) = 0 Then KN(Index).Text = "1"
67600 KN(Index).Text = Str$(Int(Val(KN(Index))))
67610 n(Index) = Val(KN(Index).Text)
67620 KW(Index) = Str$(Val(KDs(Index).Text) * (n(Index) - 1))
67630 InitSources (True)
67640 On Error GoTo 0
67650 Exit Sub
KN_Change_Error:
67660 ErrHdl ("KN_Change dans Angles")
End Sub
Code:
Private Sub InitSources(Flag As Boolean)
3620 On Error GoTo InitSources_Error
3630 X0 = Graph(0).ScaleWidth / 2 'Position de l'axe des X sur le graphique
3640 Y0 = Graph(0).ScaleHeight / 2 'Position de l'axe des Y sur le graphique
3650 d1 = 10 * Val(KDs(1))
3660 d2 = 10 * Val(KDs(2))
3670 If Flag = True Then ReDim Sources(n(1) * n(2))
3680 Activesources = 0
3690 For j = 1 To n(2)
3700 For i = 1 To n(1)
3710 srcnr = (j - 1) * n(1) + i
3720 Sources(srcnr).X = X0 - d1 * (n(1) - 1) / 2 + (i - 1) * d1 'x de la source
3730 Sources(srcnr).Y = Y0 - d2 * (n(2) - 1) / 2 + (j - 1) * d2 'y de la source
3740 If Sources(srcnr).Angle = 0 Then Sources(srcnr).Angle = Val(KA(0)) 'La première fois, l'angle est à zéro !
3750 If Sources(srcnr).Color <> 0 Then Activesources = Activesources + Val(KR(1)) * Val(KR(2))
3760 Next i
3770 Next j
3780 On Error GoTo 0
3790 Exit Sub
InitSources_Error:
3800 ErrHdl ("InitSources dans Angles")
End Sub
The error handling routine build 2 files, one with the error code, the other with a screen capture, and saves them on the user's disk
Code:
Public Sub ErrHdl(ByVal ProcMod As String)
52010 MsgTxt = "Erreur " & Err.Number & " (" & Err.Description & ")" & Chr$(10) & "ligne " & Erl & " procédure " & ProcMod
52020 MsgBox ("Erreur fatale !" & Chr$(10) & MsgTxt & Chr$(10) & Chr$(10) & _
"Le rapport d'erreur et une copie de la fenêtre du logiciel vont être sauvés."), vbCritical
Dim TimeStamp As String
Dim ParFileName As String
52030 TimeStamp = Format(Now, "yymmddhhmmss")
52040 ParFileName = App.Path & "\" & TimeStamp & ".err"
52050 Open ParFileName For Output As #1
52060 Print #1, Left$(TimeStamp, 6) & ":" & Right$(TimeStamp, 6) & ":" & Err.Number & ":" & Err.Description & ":" & Erl & ":" & ProcMod
52070 Close #1
'Use the keybd_event API to take a screen shot.
52080 keybd_event vbKeySnapshot, 1&, 0&, 0&
52090 DoEvents
'Save the image from clipboard
52100 ParFileName = App.Path & "\" & TimeStamp & ".bmp"
52110 SavePicture Clipboard.GetData(vbCFBitmap), ParFileName
52120 End
End Sub
I've got the screen shot but entering the sames data doesn't give an error.
The other error report file contains 380:Invalid property value:63760:KN_Change dans Angles
63760 is the line number of InitSources (True)
if the error had occurred in InitSources the error report would contain ...........InitSources dans Angles
-
Dec 1st, 2017, 04:00 AM
#10
Re: How can "true" be an invalid property ?
you could try changing to
Code:
67630 Call InitSources (True)
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 1st, 2017, 04:02 AM
#11
Thread Starter
Addicted Member
Re: How can "true" be an invalid property ?
Well, I've found another similar error, I can reproduce it : the error is well in InitSource !
Suppose I have an error in InitSource : it calls ErrHdl with "InitSources dans Angles" as parameter
Suppose I have also an error in ErrHdl : it jumps to line 67660 in KH_Change which calls ErrHdl with "KN_Change dans Angles" as parameter which is saved in the error report file.
How can I prevent error in ErrHdl ?
On Error resume next ?
-
Dec 1st, 2017, 04:20 AM
#12
Re: How can "true" be an invalid property ?
probably you should assign the error code and description to your parameter for errhdl and clear the error before calling errhdl
unless you clear any errors somewhere they can be passed forwards, i am fairly sure that resume or resume next will clear any error, but as you are not doing that, the errors remain current, in the following procedures
it would also be possible that your error file and image could be overwritten as it is only recorded to the nearest second
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 1st, 2017, 04:35 AM
#13
Thread Starter
Addicted Member
Re: How can "true" be an invalid property ?
Originally Posted by westconn1
probably you should assign the error code and description to your parameter for errhdl and clear the error before calling errhdl
This would be a hard job to modify each call to ErrHdl : they are hundreds !
Can I clear the error inside ErrHdl instead ? How ?
Originally Posted by westconn1
unless you clear any errors somewhere they can be passed forwards, i am fairly sure that resume or resume next will clear any error, but as you are not doing that, the errors remain current, in the following procedures
All right so why not "on error resume next" in ErrHdl ?
Meanwhile I've found what goes wrong in ErrHdl
Code:
310 keybd_event vbKeySnapshot, 1&, 0&, 0&
320 DoEvents
330 ParFileName = App.Path & "\" & TimeStamp & ".bmp"
340 SavePicture Clipboard.GetData(vbCFBitmap), ParFileName
Sometimes I've an error 380 "Invalid property value" on line 340
-
Dec 1st, 2017, 05:31 AM
#14
Re: How can "true" be an invalid property ?
Can I clear the error inside ErrHdl instead ? How ?
Err.Clear
All right so why not "on error resume next" in ErrHdl ?
or any other on error, should do the same, which would enable to error handle the errorhandler
either would have to be after the first line, else you will not get correct message
it would also be possible that your error file and image could be overwritten
this would not be the case at all, i did not see you have End statement in your error handler, you should avoid using End, unless all your code is just in modules, you should unload all forms, dispose of objects etc and exit gracefully
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 1st, 2017, 05:34 AM
#15
Re: How can "true" be an invalid property ?
Originally Posted by Herve_be
Code:
Private Sub KN_Change(Index As Integer) ' KN is a textBox
' ...
InitSources (True) ==> error 380 Invalid property value
' ...
End Sub
If you use parentheses in a Sub then you must use Call:
Code:
Call InitSources(True)
else use simply:
-
Dec 1st, 2017, 05:53 AM
#16
Thread Starter
Addicted Member
Re: How can "true" be an invalid property ?
Originally Posted by gibra
If you use parentheses in a Sub then you must use Call:
Code:
Call InitSources(True)
else use simply:
Both are accepted and work the same, this is not the cause of the problem which is that there is an error in the error handler which is still running under the previous error.
Meanwhile I've found what goes wrong in ErrHdl
Code:
310 keybd_event vbKeySnapshot, 1&, 0&, 0&
320 DoEvents
330 ParFileName = App.Path & "\" & TimeStamp & ".bmp"
340 SavePicture Clipboard.GetData(vbCFBitmap), ParFileName
Sometimes I've an error 380 "Invalid property value" on line 340 : what can be the reason of this error ?
-
Dec 1st, 2017, 06:18 AM
#17
Re: How can "true" be an invalid property ?
Originally Posted by Herve_be
Sometimes I've an error 380 "Invalid property value" on line 340 : what can be the reason of this error ?
Because the latest versions of Windows can interpret, and block, code that 'simulates' the keyboard and/or mouse, as also happens for SendKeys
Also, access to Clipboard sometimes fails (however you should call Clipboard.Clear before capture)
I use this class to capture desktop and save to bitmap file:
Code:
Option Explicit
Rem ------------------------------------------------------------------------------------------
Rem clsCaptureScreen.cls
Rem ------------------------------------------------------------------------------------------
Rem How to use:
Rem Dim lngCapture As Long
Rem Dim sFilePath As String
Rem Dim CCaptureScreen As clsCaptureScreen
Rem Set CCaptureScreen = New clsCaptureScreen
Rem sFilePath = App.Path & "\Screenshot.bmp"
Rem CCaptureScreen.OutputFileName = sFilePath
Rem lngCapture = CCaptureScreen.CaptureScreen(myPictureBox)
Rem If lngCapture <> 1 Then ERROR
Rem ------------------------------------------------------------------------------------------
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long
Private mvarOutputFileName As String
Public Property Get OutputFileName() As String
OutputFileName = mvarOutputFileName
End Property
Public Property Let OutputFileName(ByVal vData As String)
mvarOutputFileName = vData
End Property
Public Function CaptureScreen(ByRef pic As VB.PictureBox) As Long
If mvarOutputFileName = vbNullString Then
CaptureScreen = -1
Exit Function
End If
pic.AutoRedraw = True
pic.Width = Screen.Width
pic.Height = Screen.Height
BitBlt pic.hDC, 0, 0, Screen.Width \ Screen.TwipsPerPixelX, Screen.Height \ Screen.TwipsPerPixelY, GetDC(GetDesktopWindow), 0, 0, vbSrcCopy
ReleaseDC GetDesktopWindow, GetDC(GetDesktopWindow)
SavePicture pic.Image, mvarOutputFileName
CaptureScreen = 1
End Function
-
Dec 1st, 2017, 07:17 AM
#18
Re: How can "true" be an invalid property ?
> "Both are accepted and work the same"
In this context, yes they do the same thing but, as soon as you start playing with Classes and trying to pass Object references around, then that insignificant little space before the opening brace becomes a whole new heap of Trouble.
It makes VB evaluate the Default Property for the object and passes that to the function instead of the [intended] object reference.
Code:
Sub WhatIs( byval thing as variant )
Debug.Print TypeName( thing )
end Sub
Dim sc as SomeClass: Set sc = New SomeClass()
WhatIs sc
Call WhatIs(sc)
WhatIs (sc) ' A big fat error at best or, in the worst case, the function
' gets passed a property value instead of the complete object.
Regards, Phill W.
-
Dec 1st, 2017, 08:41 AM
#19
Thread Starter
Addicted Member
Re: How can "true" be an invalid property ?
Originally Posted by gibra
Originally Posted by Herve_be
Sometimes I've an error 380 "Invalid property value" on line 340 : what can be the reason of this error ?
Because the latest versions of Windows can interpret, and block, code that 'simulates' the keyboard and/or mouse, as also happens for SendKeys
Also, access to Clipboard sometimes fails (however you should call Clipboard.Clear before capture)
Thanks for the Capture screen function
but I dont think Windows blocks keybd_event vbKeySnapshot, 1&, 0&, 0&
because what happens is that, after the error 380 on SavePicture Clipboard.GetData(vbCFBitmap), ParFileName
the error handler routine enters again, takes a snapshot and it works, i've got the .bmp file.
If Windows were blocking the vbKeySnapshot it would block it each time not only the first time.
I will try to Clipboard.Clear before capture.
-
Dec 1st, 2017, 09:31 AM
#20
Re: How can "true" be an invalid property ?
In short- your error handler needs some error handling. At the moment, the error in your error handling sub is bubbling back up to the calling sub. You could use OERN, but you probably would want something in the error handler to tell you something went wrong in there too.
-tg
-
Dec 1st, 2017, 09:39 AM
#21
Thread Starter
Addicted Member
Re: How can "true" be an invalid property ?
Originally Posted by techgnome
You could use OERN
What's this ?
-
Dec 1st, 2017, 10:18 AM
#22
Re: How can "true" be an invalid property ?
OERN = On Error Resume Next
-tg
-
Dec 1st, 2017, 10:22 AM
#23
Thread Starter
Addicted Member
Re: How can "true" be an invalid property ?
If I get an error on
keybd_event vbKeySnapshot, 1&, 0&, 0&
or
SavePicture Clipboard.GetData(vbCFBitmap), ParFileName
I cannot do anything else to report the error (msg to user is useless) so the whole process may terminate, that's what I did.
-
Dec 3rd, 2017, 04:45 AM
#24
Thread Starter
Addicted Member
Re: How can "true" be an invalid property ?
Originally Posted by westconn1
you should avoid using End, unless all your code is just in modules, you should unload all forms, dispose of objects etc and exit gracefully
The program has one main form which contains a lot of buttons each one calling a dedicated form i.e.
If an error occurs in one sub-form a good idea is to close that sub-form instead of end-ing everything.
The error is trapped (on error goto) by calling a common error handling routine located in a separate module.
At the end of this error handling routine I replaced "end" by "Unload Me" but get this
How can I find the form which has called the error handler and unload it ?
-
Dec 3rd, 2017, 05:55 AM
#25
Thread Starter
Addicted Member
Re: How can "true" be an invalid property ?
-
Dec 3rd, 2017, 06:04 AM
#26
Re: [RESOLVED] How can "true" be an invalid property ?
I replaced "end" by "Unload Me" but get this
Me can only refer to an object module, form or class, not a standard module
the only simple solution that comes to mind is to unload all forms except mainform or whatever you call it
Code:
for each f in forms
if not f.name = "mainform" then unload f
next
note form names are case sensitive
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 3rd, 2017, 06:23 AM
#27
Thread Starter
Addicted Member
Re: [RESOLVED] How can "true" be an invalid property ?
Originally Posted by westconn1
the only simple solution that comes to mind is to unload all forms except mainform
Not possible to find the form from which the error handler routine has been called and unload that one only ?
-
Dec 3rd, 2017, 03:18 PM
#28
Re: [RESOLVED] How can "true" be an invalid property ?
Not possible to find the form from which the error handler routine has been called
only if you pass the form to the error handler, with the procedure name
you could have a list of forms that you do not want to close if they are open
or have some lookup table of procedure names to the containing form, which would only be possible if you do not use the same procedure names in different forms, though you would only have to lookup procedure names for currently opened forms
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 4th, 2017, 03:21 AM
#29
Thread Starter
Addicted Member
Re: [RESOLVED] How can "true" be an invalid property ?
Hi,
I've found a simple solution.
The problem is that if an error is trapped in a form it calls an error handler module which cannot unload the form.
The solution is, at the end of the error handler, to exit thus come back in the form which can unload itself.
For instance
Code:
Private Sub KT_Change()
On Error GoTo KT_Change_Error
...
KT_Change_Error:
ErrHdl ("KT_Change dans Salinite")
Unload Me
End Sub
Code:
Public Sub ErrHdl(ByVal ProcMod As String)
...
Exit Sub
End Sub
Well thanks a lot and good bye.
-
Dec 4th, 2017, 03:32 AM
#30
Re: [RESOLVED] How can "true" be an invalid property ?
i thought you did not want to go back to edit every procedure that called the error handler, else that solution was too obvious
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 4th, 2017, 03:43 AM
#31
Thread Starter
Addicted Member
Re: [RESOLVED] How can "true" be an invalid property ?
As far as the editing is limited to adding "Unload Me" behind each call is a good compromise.
-
Dec 4th, 2017, 11:31 AM
#32
Thread Starter
Addicted Member
Re: [RESOLVED] How can "true" be an invalid property ?
Better solution :
Unload Screen.ActiveForm
-
Dec 28th, 2017, 05:48 AM
#33
Thread Starter
Addicted Member
Re: How can "true" be an invalid property ?
Originally Posted by westconn1
you have End statement in your error handler, you should avoid using End, unless all your code is just in modules, you should unload all forms, dispose of objects etc and exit gracefully
Trying to avaid End I now unload the concerned form.
The problem now is that when the error handler ends the unloaded form goes on and gives an error 364 Object was unloaded at the first try to acces one of it's form object !
How can I end properly ?
This subject being closed I opened a new one How to exit from VB6 error handler
Last edited by Herve_be; Dec 28th, 2017 at 05:56 AM.
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
|