Results 1 to 12 of 12

Thread: "Constant Expression" error, um help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Scotland, UK
    Posts
    321

    Question "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?

  2. #2
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    VB Code:
    1. Dim myPic() As PictureBox         '<-Keep This, and then do the Following when you want to incriment its dimensions
    2. ReDim Preserve myPic(intPicCount)   '<- use preserve if you have elements in myPic already, and you don't want to lose them. Otherwise its optional.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Scotland, UK
    Posts
    321
    thanks, other question though;

    how do I say if strMytext = Lowercase then

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Scotland, UK
    Posts
    321
    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"

  5. #5
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    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:
    1. 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:
    VB Code:
    1. ReDim myPic(intPicCount)

    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:
    1. If strMytext = Lcase(strMytext) Then
    2. 'do something
    3. End If

    -Lou

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Scotland, UK
    Posts
    321
    thank you so much, for some reason im not thinking right tonight

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Scotland, UK
    Posts
    321
    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

  8. #8

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Scotland, UK
    Posts
    321
    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

  10. #10
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    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.

  11. #11
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    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.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Scotland, UK
    Posts
    321
    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
  •  



Click Here to Expand Forum to Full Width