|
-
Oct 31st, 2001, 01:18 PM
#1
Thread Starter
Hyperactive Member
"Constant Expression" error, um help
Hi, I keep getting:
"Constant expression required"
when I run my code, and it highlights this:
Code:
Dim myPic(intPicCount) As PictureBox
myPic is a Picturebox, and is;
Code:
Dim myPic() As PictureBox
so why isn't it working?
-
Oct 31st, 2001, 01:21 PM
#2
VB Code:
Dim myPic() As PictureBox '<-Keep This, and then do the Following when you want to incriment its dimensions
ReDim Preserve myPic(intPicCount) '<- use preserve if you have elements in myPic already, and you don't want to lose them. Otherwise its optional.
-
Oct 31st, 2001, 01:36 PM
#3
Thread Starter
Hyperactive Member
thanks, other question though;
how do I say if strMytext = Lowercase then
-
Oct 31st, 2001, 01:41 PM
#4
Thread Starter
Hyperactive Member
it wont let me do this either:
Code:
ReDim myPic(intPicCount) As PictureBox
myPic(intPicCount).AutoSize = True
myPic(intPicCount).Picture = LoadPicture(App.Path & "\" & strName & "\" & strTempItem & ".gif")
why not?
it gives error "Object variable not set"
-
Oct 31st, 2001, 01:53 PM
#5
Originally posted by AliBail
it wont let me do this either:
Code:
ReDim myPic(intPicCount) As PictureBox
myPic(intPicCount).AutoSize = True
myPic(intPicCount).Picture = LoadPicture(App.Path & "\" & strName & "\" & strTempItem & ".gif")
why not?
it gives error "Object variable not set"
You didn't do it right.
If you've already :
VB Code:
Dim myPic() As PictureBox
{hopefully in the gen declarations area}
then its already dimmed as a PictureBox.
Now, if intPicCount is a number, then do this:
NOT ReDim myPic(intPicCount) As PictureBox
its already a PictureBox. Don't repeat yourself
Now,
how do I say if strMytext = Lowercase then
VB Code:
If strMytext = Lcase(strMytext) Then
'do something
End If
-Lou
-
Oct 31st, 2001, 01:55 PM
#6
Thread Starter
Hyperactive Member
thank you so much, for some reason im not thinking right tonight
-
Oct 31st, 2001, 02:00 PM
#7
Thread Starter
Hyperactive Member
its still not letting me do it, same error, and it highlights where I am trying to set its autosize property to true!
Heres all the code (up till that point):
Code:
'Alistair D Baillie
Dim intPicCount As Long
Public Sub CreateGraphics(strName As String, strTheText As String)
Dim myPic() As PictureBox
Dim intNumberOfCharacters As Integer
Dim strTempItem As String
intNumberOfCharacters = 0
Do Until intNumberOfCharacters = Len(strTheText)
intNumberOfCharacters = intNumberOfCharacters + 1
strTempItem = Mid(strTheText, intNumberOfCharacters, 1)
If strTempItem = LCase(steTempItem) Then
strTempItem = strTempItem & "s"
End If
ReDim myPic(intPicCount)
myPic(intPicCount).AutoSize = True
myPic(intPicCount).Picture = LoadPicture(App.Path & "\" & strName & "\" & strTempItem & ".gif")
intPicCount = intPicCount + 1
Loop
-
Oct 31st, 2001, 02:40 PM
#8
BTW, theres a limit to how many controls you can have, but I forget what it is.
-Lou
-
Oct 31st, 2001, 02:48 PM
#9
Thread Starter
Hyperactive Member
lol
I think ive got around that problem with the code below (But it keeps getting stuck in a loop and crashing !!!)
Code:
'Alistair D Baillie
Public Sub CreateGraphics(strName As String, strTheText As String)
Dim intPicCount As Long
Dim intNumberOfCharacters As Integer
Dim strTempItem As String
intNumberOfCharacters = 0
intPicCount = 1
Do Until intPicCount = Len(strTheText)
strTempItem = Mid(strTheText, intPicCount, 1)
If strTempItem = LCase(strTempItem) Then
strTempItem = strTempItem & "s"
End If
'Now lets put them into one image
main.CreatePicture.PaintPicture LoadPicture(App.Path & "\blue\" & strTempItem & ".gif"), main.CreatePicture.Width, 0
Loop
Call SavePicture(main.CreatePicture.Picture, App.Path & "\output\demo.gif")
End Sub
-
Oct 31st, 2001, 03:03 PM
#10
Fanatic Member
Hi guys,
Sorry to intrude.
AliBail's first method was OK. The problem was that you can't just redimension the array. You must also set the new objects in the array as new PictureBox.
You were also using redim which clears the array. This then means that none of the objects in the array have been initialized and will therefore give an object error.
below i have created a form2 object to be used in my array
________________________________________
dim lArray() as form2
redim larray(5) as form2
set larray(1) = new form2
larray(1).show
________________________________________
you will need to do this for each object in your array.
-
Oct 31st, 2001, 03:09 PM
#11
Fanatic Member
Also, in your loop, you are not changing the intpiccount nor the strTheText. Your loop will never end if the values don't change. This is always the first thing to check for in infanate loops cause we often forget to increment the values.
-
Oct 31st, 2001, 03:11 PM
#12
Thread Starter
Hyperactive Member
Yep, i noticed that and changed it;
Code:
'Alistair D Baillie
Public Sub CreateGraphics(strName As String, strTheText As String)
Dim intPicCount As Long
Dim intNumberOfCharacters As Integer
Dim strTempItem As String
intNumberOfCharacters = 0
intPicCount = 1
Do Until intPicCount = Len(strTheText)
strTempItem = Mid(strTheText, intPicCount, 1)
If strTempItem = LCase(strTempItem) Then
strTempItem = strTempItem & "s"
End If
'Now lets put them into one image
main.CreatePicture.PaintPicture LoadPicture(App.Path & "\blue\" & strTempItem & ".gif"), main.CreatePicture.Width, 0
intPicCount = intPicCount + 1
Loop
main.CreatePicture.Refresh
Stop
Call SavePicture(main.CreatePicture.Picture, App.Path & "\output\demo.gif")
End Sub
The problem seems to lie with the fact that main.createPicture = 0 when I come to save it. Any1 know why it = 0? when ive been putting imags into it?
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
|