-
Aug 6th, 2013, 01:20 AM
#1
Weird Button Array Problem
Very strange.
I have Command1(0) and Command1(1)
Both buttons have exactly the same properties except for the Index and Caption.
These buttons are on an application I wrote some time back and it worked at that time. I left it alone in it's directory for all this time and when I went back to the directory and brought up the project this weird thing took place:
Command1(0) is not detected by Sub Command1_MouseDown(...) but Command1(1) is detected.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Aug 6th, 2013, 02:08 AM
#2
Re: Weird Button Array Problem
Originally Posted by jmsrickland
Very strange.
I have Command1(0) and Command1(1)
Both buttons have exactly the same properties except for the Index and Caption.
These buttons are on an application I wrote some time back and it worked at that time. I left it alone in it's directory for all this time and when I went back to the directory and brought up the project this weird thing took place:
Command1(0) is not detected by Sub Command1_MouseDown(...) but Command1(1) is detected.
I have encountered the same problem in the past button instead of the buttons being in an array they were called "Button1", "Button2", etc. I don't know why the problem occurs but all I can suggest is deleting the buttons and creating them again. Maybe Microsoft has written an article on this problem?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Aug 6th, 2013, 03:37 AM
#3
Re: Weird Button Array Problem
Do you mean an error is being raised?
-
Aug 6th, 2013, 03:45 AM
#4
Re: Weird Button Array Problem
Originally Posted by dee-u
Do you mean an error is being raised?
No, I think what he means is that even though he has
vb Code:
Private Sub Command1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) MsgBox "Hello" End Sub
only one of the buttons produces the message box while the other does nothing.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Aug 6th, 2013, 09:51 AM
#5
Re: Weird Button Array Problem
JMS
It's a long shot, but this may be of some use ,,,
In Design mode, bring up the Form and the Properties window.
Click on Command1(1)
Does the Index read as 1? ,,, Given that this one works, I imagine it will.
Click on Command1(0)
Does the Index read as 0? ,,, Given that this one doesn't work, the Index shown may be a clue.
Spoo
-
Aug 6th, 2013, 12:18 PM
#6
Re: Weird Button Array Problem
Code:
Private Sub Command1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Index
Case 0
picRubberBandButton(1).ZOrder 0
RuberBandEnabled = True
picPinBoard.MousePointer = 2
Case 1
picRubberBandButton(0).ZOrder 0
RuberBandEnabled = False
picPinBoard.Cls
mniSaveSelectedAsSnapShot.Enabled = False
picPinBoard.MousePointer = 1
End Select
End Sub
Only Command1(1) fires the MouseDown event so only Case 1 is executed. Command1(0) does not fire the MouseDown event at all
The properties are correct, ie, Command1(0) has an Index of 0 and Command1(1) has an Index of 1
If I start a new VB project and duplicate this code and button array I do not have this problem; it only occurs on the original project and it occurs on all versions of the VB project since I copy the project files from one version to the next version making changes along the way so it must have started with version 1. I know for a fact that when I created the projects this problem did not occur at that time. Now, a year later I re-open the project to discover this strange happening.
I will do what NW suggested and delete and re-create the button array and see what happens
EDIT: I did what NW suggested. Same problem
EDIT: I added another button, Command1(2) to the array. It works. So, only Index 0 does not fire the MouseDown event but Index 1 and Index 2 does fire the MouseDown event
Last edited by jmsrickland; Aug 6th, 2013 at 01:19 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Aug 6th, 2013, 12:57 PM
#7
Re: Weird Button Array Problem
Have you tried putting a Breakpoint on the 'Select Case' statement, clicked on Command1(0) and see what happens?
If nothing happens, then what you clicked on was not Command1(0), check the control's name on the Form etc. If it does break, then F8 through the code and see what happens. Is there any code in the MouseUp or Click events that may be misleading you?
-
Aug 6th, 2013, 01:11 PM
#8
Re: Weird Button Array Problem
Could there possibly be some other code that is executing when you mouse down on the troublesome button preventing the code there from executing?
-
Aug 6th, 2013, 01:19 PM
#9
Re: Weird Button Array Problem
Originally Posted by DataMiser
Could there possibly be some other code that is executing when you mouse down on the troublesome button preventing the code there from executing?
To test....comment out EVERYTHING else in the form, run and try????
-
Aug 6th, 2013, 03:23 PM
#10
Re: Weird Button Array Problem
Originally Posted by Doogle
Have you tried putting a Breakpoint on the 'Select Case' statement, clicked on Command1(0) and see what happens?
If nothing happens, then what you clicked on was not Command1(0), check the control's name on the Form etc. If it does break, then F8 through the code and see what happens. Is there any code in the MouseUp or Click events that may be misleading you?
It is definitely Command1(0) that I click on. It doesn't even fire up the MouseDown event which I have already stated more than once
I know it's Command1(0) because for one thing when I click on it in design mode it opens up the Command1_MouseDown event sub and another reason I know it's Command1(0) is because I checked the properties
Originally Posted by DataMiser
Could there possibly be some other code that is executing when you mouse down on the troublesome button preventing the code there from executing?
No, I already striped out all code and objects down to just the two buttons and the MouseDown event. Problem still same.
I even copied this code and the buttons to a blank project. Same problem
But if I start a new project, put on Command1(0) and Command1(1) and re-write the MouseDown event it works
Funny thing that I noticed is that Command1(0) appears to have a transparency-like property or an invisible-like property because if I move this button on top of another object and click on the button it actually makes the object under the button respond even though the button itself is neither invisible, transparent, disabled, or anything like that. In fact it is an exact copy of Commend1(1) which works.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Aug 6th, 2013, 03:40 PM
#11
Re: Weird Button Array Problem
I just found out something. I don't think it has anything to do with the problem but it turns out they are not command buttons at all; they are pictureboxes that just had the name Command1. I think at one time for whatever reasons I had which I don't remember for sure I probably started out using command buttons but didn't like them or something so I switched over to pictureboxes and named them Command1 just to keep syntax compatible in the code. I think that at that time I didn't know how to put a picture on a button so I just did away with the buttons and subsituted them with pictureboxes with a pictures.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Aug 6th, 2013, 03:53 PM
#12
Re: Weird Button Array Problem
Originally Posted by jmsrickland
I just found out something. I don't think it has anything to do with the problem but ,,,
Hmm..
It might be a problem if the "detection" is expected to occur in a .. no, check that.
The parameters are the same for each type of control
CommandButton
Code:
Private Sub CB1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'
End Sub
PictureBox
Code:
Private Sub PB1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'
End Sub
Spoo
Last edited by Spoo; Aug 6th, 2013 at 04:01 PM.
-
Aug 6th, 2013, 05:55 PM
#13
Re: Weird Button Array Problem
@jmsrickland,
Does the problem occur if you recreate the project from scratch? One of the files that make up the project might be corrupt.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Aug 6th, 2013, 06:48 PM
#14
Re: Weird Button Array Problem
Originally Posted by Nightwalker83
@jmsrickland,
Does the problem occur if you recreate the project from scratch? One of the files that make up the project might be corrupt.
If I completely start over with a new project it's OK. If I copy the existing code and the controls over to a new project the problem remains. If I add a 3rd control Index 2 then Index 2 and 1 work but not Index 0. It's always control with Index 0 that wont trigger the MouseDown event
I did this:
1) Add a 3rd control. Now I have Index 2. Both index 1 and index 2 work but not index 0
2) Delete control index 0
3) Make control with index 2 to be index 0
4) Now what was control index 2 which worked is now control with index 0 and it doesn't work
This tells me it isn't the control itself but it's the index number that doesn't work.
But what about the fact that you can mouse down through it to a control under this one? That is really bizzar.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Aug 6th, 2013, 07:22 PM
#15
Re: Weird Button Array Problem
Are you sure the name of the commanbutton which has an index of 0 is Command1? That's really weird if such is the case. Perhaps posting the project here could be the last resort if you want it sorted out.
-
Aug 6th, 2013, 08:51 PM
#16
Re: Weird Button Array Problem
I'm just going to ask, just to be sure....you DID delete both controls (PBs or CBs or whatever they are), and then add a new Commandbutton and make a two button array from it..RIGHT?
I only say this because of an experience I had recently on a thread involving ADODC's. OP had a similar situation in that his ADODC was 'replaced' somehow with a picturebox. I had him delete the PB, and add a new ADODC and everything was fine (i actually took his code/project and discovered that the PB had magically replaced what must have been a corrupt ADODC.
If you did as I asked, and it still doesn't (didn't) fix it...I'm outa here and just observing to see which expert will come up with the solution.
-
Aug 6th, 2013, 09:37 PM
#17
Re: Weird Button Array Problem
Are you sure the command button index is going "0", "1", etc and have not changed?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Aug 6th, 2013, 09:43 PM
#18
Re: Weird Button Array Problem
Perhaps Command1(0) is disabled?
-
Aug 6th, 2013, 09:44 PM
#19
Re: Weird Button Array Problem
I think it has to do with saving your project/moving files around maybe?
If vb does not recognize the objects it replaces them with another object. (as sam pointed out file is "corrupted")
Might not be the reason but it happened to me a lot of times before when I only copied objects from one project to another.
For example load ms common controls 6.0, add a progress bar, keep project opened. (you do not have to save or anything)
Open a new vb window start new project DO NOT ADD m common controls 6.0, copy the progress bar from the first opened project and paste it in your new project.
See what happens.
It might also be that vb or you saved the project and moved it? or delete one of its file by accident and vb did not recognize the object (control) anymore and decided to load a picturebox instead?
It's hard to know what happened because like you said it's an old project!
Edit:
Sorry forgot to add when it says cannot load progressbar... click ok then it will prompt a messsage saying would you like to continue press YES and see what the control is.
-
Aug 6th, 2013, 10:34 PM
#20
Re: Weird Button Array Problem
If there was a problem loading controls there should have been a log file created by the same name as the form in question telling what problems were encountered.
-
Aug 6th, 2013, 10:35 PM
#21
Re: Weird Button Array Problem
True, just giving suggestions.
Who knows what JMS did back in the day hahaha
-
Aug 6th, 2013, 11:25 PM
#22
Re: Weird Button Array Problem
Another couple of stupid questions;
1. Do any of the events trigger (e.g. Click , KeyPress) for element zero?
2. When you replaced element zero with element two did it retain the 'transparent' properties? (i.e. could you 'click through' it to activate another object underneath it)
This smells of sub-classing where messages relating to element zero are being intercepted, but if you've removed all the code except for the MouseDown event, as indicated in Post#10, I can't see how that could be the problem. I assume you've already closed and re-opened the IDE and re-booted. I could just about understand it if it were a Custom Control rather than the VB6 intrinsic PictureBox, but then again you'd know if it was - it would stick out like a sore thumb in the Project Components List.
Sorry, third stupid question: Does the compiled .exe exhibit the same problem or is it just when run in the IDE?
This 'transparent' like 'property' just doesn't belong to a 'standard' PictureBox without some jiggery-pokery. I'm sure I've seen threads here asking how that sort of thing can be done.
From what you've told us so far we can deduce that the problem is unique to this particular Project and appears to be confined to element zero of the Control Array, so that begs the questions: What is 'special' about this Project (eg. Components, References)? and what is 'special' about element zero? It may be worthwhile creating a working version and looking at the .vbp files of the working and non-working Projects ,with Notepad, to see if there's any noticable differences
It might be interesting to dynamically load element zero at run-time and see what happens when you click on it. i.e. leave Command1(1) (which you know behaves as expected) on the Form, remove Command1(0) and in the Form_Load event Load Command1(0) etc. If it still falis then that would suggest that the problem is confined to element zero.
Perhaps you could .zip up the Project so we can have a play with it? - this is just too interesting ....'impossibilities' like this are few and far between !
EDIT: For what it's worth, my 'gut feel' is that the PictureBox component in use is not a 'standard' PictureBox or there's some code still lurking around in the cut down Project that's causing this behaviour.(Sub_Main perhaps?)
Last edited by Doogle; Aug 7th, 2013 at 01:13 AM.
-
Aug 7th, 2013, 12:21 AM
#23
Re: Weird Button Array Problem
Could you upload the stripped down project or form that exhibits this behavior?
-
Aug 7th, 2013, 12:27 AM
#24
Re: Weird Button Array Problem
Originally Posted by Doogle
Perhaps you could .zip up the Project so we can have a play with it? - this is just too interesting ....'impossibilities' like this are few and far between !
I'd like to play with it too.
The project you know, nothing else.
-
Aug 7th, 2013, 12:39 PM
#25
Re: Weird Button Array Problem
I was going to upload the project but I find out that wont do any good since I already uploaded it to another computer and it works on the 2nd computer. Now I'm beginning to think it's either the PC or it's VB playing tricks.
It's not really causing a problem with me getting the project finished since I can use the picturebox buttons index 1 and 2 and simply do away with index 0 but it still boggles my mind as to what is actually happening.
Maybe I'll just re-install VB and see what happens.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
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
|