-
[RESOLVED] If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
I am trying to get a ListBox, itemdata to show a certain PictureBox in a control array, to be shown that has the same index number.
For example:
If List1.ItemData(1) Then Picture1(1).Visible = True
Thanks in advance!!
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
How about this:
Picture1(List1.ListIndex).Visible = True
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Thanks, I will try that!!
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
I would rather try this:
Code:
Picture1(List1.ListIndex).Visible = List1.ItemData(List1.ListIndex)
... if of course you do have as many pictureboxes as list1.listcount
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
I am getting an error message: It says that the control in the array, doesn't exist.
Yes, I know that. Because I haven't made it yet. But then we need error checking, to check if the control has been loaded at that time. Then if it hasn't then exit sub, if the control has been loaded then continue with the process.
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
So do error handling then. And make sure that you have as much picture boxes as there are items in the list. Rhino already told you about this "... if of course you do have as many pictureboxes as list1.listcount "
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
So its a For .... Next loop, right???
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Still getting the same error. Using this code:
Code:
Option Explicit
Dim aa As Long
Dim sMyItem As String
Public Sub Command1_Click()
For aa = 0 To Form1.List1.ListCount - 1
If sMyItem = Form1.List1.List(aa) Then Exit Sub
Next
Form11.BackGround1(Form1.List1.ListIndex).ZOrder "0" = Form1.List1.ItemData(Form1.List1.ListIndex)
Form11.BackGround1(Form1.List1.ListIndex).Visible = Form1.List1.ItemData(Form1.List1.ListIndex)
Exit Sub
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Compare Picture1.Count with List1.ListCount
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Getting an error process, happening!!
Error: I cannot use the set properties of the say for at least, to example: Two pictureboxes. I have tried to set them at run-time two different sizes. (Height and Width settings). But then that doesn't work at all. Even when I .Visible = True & .Zorder "0" one of them.
Here is the whole handler's source code to that problem that I am having:
Code:
Public Sub List1_Click()
On Error Resume Next
Dim aa As Long
If Form1.Text2.Text = "0" Then Exit Sub
If Form1.Text2.Text = "1" Then GoSub List1Item1
Exit Sub
List1Item1:
If Form1.List1.ItemData(Form1.List1.ListIndex) = "0" Then GoSub ItemAEquals1
If Form1.List1.ItemData(Form1.List1.ListIndex) <> "0" Then GoSub ItemAEquals2
Exit Sub
ItemAEquals1:
Form1.SSTab1.Tab = "1"
Form11.Hide
Form10.Hide
Form12.Hide
Form13.Hide
Form14.Hide
Exit Sub
ItemAEquals2:
Form1.SSTab1.Tab = "1"
Form11.Show vbModeless, Me
Form10.Hide
Form12.Hide
Form13.Hide
Form14.Hide
For aa = 0 To Form1.List1.ListCount - 1
Form11.BackGround1(Form11.BackGround1.Count - 1).ZOrder "0" = Form1.List1.ItemData(Form1.List1.ListIndex)
Form11.BackGround1(Form11.BackGround1.Count - 1).Visible = Form1.List1.ItemData(Form1.List1.ListIndex)
Next
Exit Sub
End Sub
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
I'm sorry to have to say this but that's terrible code.
Some things for you to think about and/or fix:
1) On Error Resume Next. When you use that it hides any errors you may be running into. There are sometimes reasons for doing that but I suspect that you are doing it just because you are getting an error that you don't know how to fix.
2) You have been told repeatadly that ItemData can only be numeric so why are you doing things like If Form1.List1.ItemData(Form1.List1.ListIndex) = "0" ?
3) There is no reason for you to use GoSubs. While there are rare (very rare) occasions when it is proper to use them, your code doesn't need them. For example:
Code:
If Form1.List1.ItemData(Form1.List1.ListIndex) = 0 Then
Form1.SSTab1.Tab = "1"
Form11.Hide
Form10.Hide
Form12.Hide
Form13.Hide
Form14.Hide
Exit Sub
Else
Form1.SSTab1.Tab = "1"
Form11.Show vbModeless, Me
Form10.Hide
Form12.Hide
Form13.Hide
Form14.Hide
Exit Sub
End If
There are other obvious improvments that could also be made to that code.
4) I have no idea what you are trying to do with these two lines.
Code:
Form11.BackGround1(Form11.BackGround1.Count - 1).ZOrder "0" = Form1.List1.ItemData(Form1.List1.ListIndex)
Form11.BackGround1(Form11.BackGround1.Count - 1).Visible = Form1.List1.ItemData(Form1.List1.ListIndex)
Next
For one thing the Visible property expects a True or False value so unless Form1.List1.ItemData(Form1.List1.ListIndex) translates to one of them you will get an error (which you won't see because of the On error Resume Next).
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Right Now: Problems fixed!! Removed the On Error statement. But then with the PictureBoxes. They run the control arrays, all on each other. Even when they have specific controls made on a certain PictureBox. They all show the same controls, in their positions that they were made in.
So far: I cannot move the controls, after they have been Loaded, using the Load statement. That will come in the near future of the project.
--
Are you sure that the statement "On Error Resume Next" is that kind of bad programming??? What can I use as error handling???
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Quote:
Originally Posted by
ThEiMp
Are you sure that the statement "On Error Resume Next" is that kind of bad programming??? What can I use as error handling???
Yes it is *that* bad. Look at this tutorial http://www.vb6.us/tutorials/error-handling-visual-basic
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Here is a very simple example.
Code:
Private Sub Form_Load()
On Error GoTo ErrorRoutine
MsgBox 7 / 0
Exit Sub
ErrorRoutine:
MsgBox "Error " & Err.Number _
& "(" & Err.Description & ") generated in Form_Load"
End Sub
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Now: About the getting the controls that were formed in a control array, to be in their respective PictureBoxes, as in the Container, that I have made for them. They don't escape, from the PictureBox. So then, why are they being overlapped, in every PictureBox, that I make in the Project???
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Quote:
Originally Posted by
MartinLiss
Here is a very simple example.
I have been a programmer for many years. In previous versions of VB, and Windows. And have never seen a statement like that!!
I was always told to do it like this:
Code:
MsgBox "Hello" , , "Message"
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
When you load those extra controls you have to Set their Container property if you want to 'embed' them in a Picture box. Then after that set their position within the container.
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Done that. But then I must make a proper reference to the actual PictureBox, that I wish to make as the Container.
Cause this is the code that I am using to do so:
Code:
MakeCommandButton1:
c = c + 1
Form12.Combo3.AddItem "Command" & c
Form14.Combo1.AddItem "Command" & c
Form12.Combo2.Clear
Form12.Combo2.AddItem "Click"
Form12.Combo2.AddItem "Double Click"
Load FrameBox1(c)
Load imgBox1(c)
Load labCaption1(c)
Set FrameBox1(c).Container = Form11.BackGround1(l)
Set imgBox1(c).Container = FrameBox1(c)
Set labCaption1(c).Container = FrameBox1(c)
FrameBox1(c).Top = Y - FrameBox1(c).Height / 2
FrameBox1(c).Left = X - FrameBox1(c).Width / 2
labCaption1(c).Caption = "Command" & c
FrameBox1(c).Visible = True
imgBox1(c).Visible = True
labCaption1(c).Visible = True
labCaption1(c).ZOrder "0"
Form1.Text3.Text = "0"
Exit Sub
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Quote:
Originally Posted by
ThEiMp
I have been a programmer for many years. In previous version of VB, and Windows. And have never seen a statement like that!!
I was always told to do it like this:
Code:
MsgBox "Hello" , , "Message"
I dont think Martin's idea was to tell you how to use the Message Box but rather how to use error handling and Err object. The MsgBox 7/0 is simply there to generate an error, because divison by zero is not allowed. If you would have tried the code first you would have noticed the difference. Doing it without error handling would have crashed your application while with error handling it would show a message and continue working.
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Quote:
Originally Posted by
ThEiMp
I have been a programmer for many years. In previous versions of VB, and Windows. And have never seen a statement like that!!
I was always told to do it like this:
Code:
MsgBox "Hello" , , "Message"
Well sure but you can always do something like Msgbox 4 + 7 which will display 11.
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
??? lol What???
Why not something like this:
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Here is code for a Listbox that is in a picturebox. The listbox's Index is zero so it's a control array and the last line moves the new member of the control array. What are you doing differently?
Load List1(1)
List1(1).Visible = True
List1(1).Move 500, 250
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
BTW that last line is the same as doing
List1(1).Top = 500
List1(1).Left = 250
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Quote:
Originally Posted by
ThEiMp
??? lol What???
Why not something like this:
You are *completely* missing the point of everything we are telling you...
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
The samething, that you are doing. But with things, like Event handling and also Sub handling, for the coding window.
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Wait: Can we do it like this???
Code:
Load List1(1)
List1(1).Visible = True
List1(1).Move X, Y
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Quote:
Originally Posted by
ThEiMp
Wait: Can we do it like this???
Code:
Load List1(1)
List1(1).Visible = True
List1(1).Move X, Y
Sure, if X and Y have the values of the proposed Top and Left.
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Major Problem #1:
Code:
Set Label1(a).Container = Form11.BackGround1(0)
This points to no kind of control array, in any aspect in the Project. I mean: That instead of .Index = "0", it must be something, and that has to be a valid Index. In my case: I must be able to make it the current PictureBox, that the end-user, had just clicked on with the mouse.
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Quote:
Originally Posted by
ThEiMp
Major Problem #1:
Code:
Set Label1(a).Container = Form11.BackGround1(0)
This points to no kind of control array, in any aspect in the Project. I mean: That instead of .Index = "0", it must be something, and that has to be a valid Index. In my case: I must be able to make it the current PictureBox, that the end-user, had just clicked on with the mouse.
That makes absolutely no sense so please try to say it it another way. Also since you say you "have been a programmer for many years. In previous versions of VB" then surely you must understand the dfference between strings and numbers, so why do you continue to do things like .Index = "0"???
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Well I was talking in pesudo code, and not VB or machine lingo.
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Okay, fine but how about rewording this?
"This points to no kind of control array, in any aspect in the Project. I mean: That instead of .Index = "0", it must be something, and that has to be a valid Index. In my case: I must be able to make it the current PictureBox, that the end-user, had just clicked on with the mouse."
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Right: I refer to my PictureBox control array, using the (l) for the Index. And also (0) for the Index, in the same project. But I had changed the code to view it, using the code in this thread. It is viewed right, but overlapping and not letting me see the previous PictureBox at all!!
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Code Repair: It now looks like this.
Is this correct, or there about???
Code:
Public Sub List1_Click()
Dim aa As Long
If Form1.List1.ItemData(Form1.List1.ListIndex) = "0" Then
Form1.SSTab1.Tab = "1"
Form11.Hide
Form10.Hide
Form12.Hide
Form13.Hide
Form14.Hide
Exit Sub
Else
Form1.SSTab1.Tab = "1"
Form11.Show vbModeless, Me
Form10.Hide
Form12.Hide
Form13.Hide
Form14.Hide
For aa = 0 To Form1.List1.ListCount - 1
Form11.BackGround1(Form11.BackGround1.Count - 1).ZOrder "0" = Form1.List1.ItemData(Form1.List1.ListIndex)
Next
End If
End Sub
-
1 Attachment(s)
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
I still don't understand but here is some code that may help you. Click on Command1 to create some listbox's in thepicturebox. Click on one of them, then click Command2 to move the one you just clicked.
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
I had a look at the zip file. It only displayed information, about moving controls. That part I have down patt. But I have to fix the reference to the Container. As a single and dynamic control, at run-time and not a design-time.
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
ItemData should be a number. Having said that (at least 3 times), why repeat things you don't have to?
Code:
Public Sub List1_Click()
Dim aa As Long
Form1.SSTab1.Tab = "1"
Form11.Hide
Form10.Hide
Form12.Hide
Form13.Hide
Form14.Hide
If Form1.List1.ItemData(Form1.List1.ListIndex) <> 0 Then
For aa = 0 To Form1.List1.ListCount - 1
Form11.BackGround1(Form11.BackGround1.Count - 1).ZOrder "0" = Form1.List1.ItemData(Form1.List1.ListIndex)
Next
End If
End Sub
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Maybe he doesn't understand that there is a difference between 0 and "0". If you put the number in quotes VB will treat it as a String.
.ItemData = 0
is not the same as
.ItemData = "0"
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Quote:
Originally Posted by
ThEiMp
I had a look at the zip file. It only displayed information, about moving controls. That part I have down patt. But I have to fix the reference to the Container. As a single and dynamic control, at run-time and not a design-time.
The added Msgbox will show you the container's index.
Code:
Private Sub Command2_Click()
List1(CurrentIndex).Move 0, 0
MsgBox List1(CurrentIndex).Container.Index
End Sub
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Thanks, but I am getting very tired!! It's showing. I am now at: 0555 hours (05:55 AM) and I haven't slept all night and all morning. So can we do this again, some other time???
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Okay, I'm back in the thick of it!!
I guess and ready to take it on again!!
Problem: Still the same, and YES!! Removed all " from the values, instead of the TextBoxes, which I capture data into to make my project work. Hence, the If Form1.Text2.Text = "0" Then, etc.... (Now only my AddItems, Captions and Text properties have " in them, that point to Strings, instead of values.)
Another Problem: Coming up against the Coding Section. The text data doesn't stay on the same line or cursor position, when entering in code!! But that is for another time!!
My source code, now looks like this. I am getting a process problem. That is like this: It goes to the end of .Count, but when required to go backwards into the .Count. Problems arise!!
They are as follows: They don't go back, they stay at the last created PictureBox and no matter what don't change. For any amount of code, I input into it!!
Code:
Public Sub List1_Click()
Dim aa As Long
If Form1.List1.ItemData(Form1.List1.ListIndex) = 0 Then
Form1.SSTab1.Tab = 1
Form11.Hide
Form10.Hide
Form12.Hide
Form13.Hide
Form14.Hide
Exit Sub
Else
Form1.SSTab1.Tab = 1
Form11.Show vbModeless, Me
Form10.Hide
Form12.Hide
Form13.Hide
Form14.Hide
For aa = 0 To Form1.List1.ListCount - 1
Form1.Label3.Caption = "Form" & (Form11.BackGround1.Count - 1)
Form11.TitleBar_FormCaption1.Caption = "Form" & (Form11.BackGround1.Count - 1)
Form11.BackGround1(Form11.BackGround1.Count - 1).Visible = True
Next
End If
End Sub
-
1 Attachment(s)
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
This can not be put simpler than the codes attached...
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Thanks for all of your help. I now, understand values and strings, alot more now!!
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
Problem: I found something about my project, when it executed in the compiled format of the project. It says that it cannot find Control Array item: "5". I know that, cause item "5", is made using a control array. And that the .ItemData = .ItemData + 1. It's execution value is 0, but then when it comes to that part of the code. It is value + 1. So then it will always add + 1 to the value, everytime is is run that block of code.
I get this error, after the control array to make the PictureBox, is executed. It is loaded fine, but then afte that my project crashes and then it says; as above in the problem statement block of this post.
Resoultion: I must have some error checking in the project, in that part of the code. To make it continue when there isn't as yet, an item "5".
-- How do I come up with a solution to my problem??? With my education of programming in COM, I say that I must go and do some error, checking. So the next few people, that read this post. Could you please, give me so source code, in order to do some error checking, in the process of my code below.
Thanks in advance...
Code:
Public Sub List1_Click()
If Form1.List1.ItemData(Form1.List1.ListIndex) = 0 Then
Form1.SSTab1.Tab = 1
Form11.Hide
Form10.Hide
Form12.Hide
Form13.Hide
Form14.Hide
Else
Form1.SSTab1.Tab = 1
Form11.Show vbModeless, Me
Form10.Hide
Form12.Hide
Form13.Hide
Form14.Hide
Form11.BackGround1(Form1.List1.ListIndex).Visible = True
Form11.BackGround1(Form1.List1.ListIndex).ZOrder 0
End If
End Sub
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
When you say "It says that it cannot find Control Array item: "5". I know that, cause item "5", is made using a control array. And that the .ItemData = .ItemData + 1." are you talking about two control arrays or just one?
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
One control array of PictureBoxes. And a ListBox, made a design-time that has some data filled at design-time. And then some data that is filled in a run-time. The ListBox reads the .ItemData, of the PictureBoxes.
-
Re: If List1.ItemData = "1" Then Form11.Picture1(l).Visible = True???
I am getting conflicting processes: Most probably in this position???
Code:
Form1.List1.AddItem "Form" & l & ":" & " " & Filename & ".frm"
Form1.List1.ItemData(Form1.List1.NewIndex) = Form1.List1.ItemData(Form1.List1.NewIndex) + 1
-- Also this found on the Form2.Command1_Click() handler.