Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_NEWIMAGE can't accept variables as dimensions?
#1
I am working on a project in which I would like to create images using _NEWIMAGE and calculated image dimensions. I have found that an 'Illegal Function Call' error is raised when I try to create an image like this:

DIM AS LONG Pict
DIM AS INTEGER iy
.
.
.
Pict =_NEWIMAGE(64, iy, 32)

Does _NEWIMAGE accept only numeric values for the dimensions? The wiki doesn't specifically say so but all of the examples use numeric dimension values. 

TIA
It's not the having, it's the doing.
Reply
#2
(02-17-2026, 12:59 AM)bobalooie Wrote: I am working on a project in which I would like to create images using _NEWIMAGE and calculated image dimensions. I have found that an 'Illegal Function Call' error is raised when I try to create an image like this:

DIM AS LONG Pict
DIM AS INTEGER iy
.
.
.
Pict =_NEWIMAGE(64, iy, 32)

Does _NEWIMAGE accept only numeric values for the dimensions? The wiki doesn't specifically say so but all of the examples use numeric dimension values. 

TIA

  A variable should be acceptable.


   If that is the full code your using then your getting the illegal function call because iu isn't assigned a value (thus is 0)  You can't do a _NEWIMAGE with a 0 dimension !
Reply
#3
(02-17-2026, 01:02 AM)ahenry3068 Wrote:   A variable should be acceptable.


   If that is the full code your using then your getting the illegal function call because iu isn't assigned a value (thus is 0)  You can't do a _NEWIMAGE with a 0 dimension !

The variable's value is calculated before reaching this point in the code. It is a non-zero value.
It's not the having, it's the doing.
Reply
#4
(02-17-2026, 01:04 AM)bobalooie Wrote:
(02-17-2026, 01:02 AM)ahenry3068 Wrote:   A variable should be acceptable.


   If that is the full code your using then your getting the illegal function call because iu isn't assigned a value (thus is 0)  You can't do a _NEWIMAGE with a 0 dimension !

The variable's value is calculated before reaching this point in the code. It is a non-zero value.
   In that case please print out the values just prior to the _newimage.     !     The code you have should work if iy is a valid value !

Also make sure the variable is **in scope** you may think your initializing it but really getting the WRONG iy if the one your assigning isn't in the scope of the _newimage
Reply
#5
(02-17-2026, 01:11 AM)ahenry3068 Wrote:
(02-17-2026, 01:04 AM)bobalooie Wrote:
(02-17-2026, 01:02 AM)ahenry3068 Wrote:   A variable should be acceptable.


   If that is the full code your using then your getting the illegal function call because iu isn't assigned a value (thus is 0)  You can't do a _NEWIMAGE with a 0 dimension !

The variable's value is calculated before reaching this point in the code. It is a non-zero value.
   In that case please print out the values just prior to the _newimage.     !     The code you have should work if iy is a valid value !

Also make sure the variable is **in scope** you may think your initializing it but really getting the WRONG iy if the one your assigning isn't in the scope of the _newimage

The action is all within a SUB, including the variable declarations, so everything is in the local scope. I have single-stepped through the code and put the variables on the watchlist. The iy values start at 16 and can be increased but never reduced.
It's not the having, it's the doing.
Reply
#6
(02-17-2026, 01:22 AM)bobalooie Wrote:
(02-17-2026, 01:11 AM)ahenry3068 Wrote:
(02-17-2026, 01:04 AM)bobalooie Wrote: The variable's value is calculated before reaching this point in the code. It is a non-zero value.
   In that case please print out the values just prior to the _newimage.     !     The code you have should work if iy is a valid value !

Also make sure the variable is **in scope** you may think your initializing it but really getting the WRONG iy if the one your assigning isn't in the scope of the _newimage

The action is all within a SUB, including the variable declarations, so everything is in the local scope. I have single-stepped through the code and put the variables on the watchlist. The iy values start at 16 and can be increased but never reduced.
   I know I use variables with _NEWIMAGE,  But I believe in double checking.  

This code DOES NOTHING REALLY,   But it compiles and runs without an error ! 

Code: (Select All)

Dim IX As Integer
Dim IY As Integer

Dim IMG As Long

IX = 64
IY = 16

IMG = _NewImage(IX, IY, 32)

   Please Humor me and do a PRINT IY right before the NewImage !   
(If you doing other things that would make that output hard to read then do a _DEST CONSOLE before the print ! )
Reply
#7
If your calling the creation from within a Sub and the variable iy isnt shared then the sub cant access it.

So i.e 

DIM Shared AS INTEGER Iy

Would probably fix it 

Though without your full code this is just a guess...

Unseen
Reply
#8
(02-17-2026, 01:51 AM)Unseen Machine Wrote: If your calling the creation from within a Sub and the variable iy isnt shared then the sub cant access it.

So i.e 

DIM Shared AS INTEGER Iy

Would probably fix it 

Though without your full code this is just a guess...

Unseen

     I also suspect this, and did ask if the variable was in scope.   He says everything is declared in the same sub ?? 
There has to be an incorrect value somewhere which is why I asked him to print out the value right before his call to _NewImage !
Reply
#9
Works fine for me _NewImage with variables in a sub:
Code: (Select All)
Option _Explicit
Screen _NewImage(800, 600, 32): _ScreenMove 280, 60
Dim I
For I = 1 To 100
    Line (Rnd * _Width, Rnd * _Height)-(Rnd * _Width, Rnd * _Height), _RGB32(Rnd * 255), BF
Next
Sleep
testNewImage


Sub testNewImage
    Dim SCR&, W, H, SQUARTER&
    SCR& = _ScreenImage
    W = _Width(SCR&) / 2
    H = _Height(SCR&) / 2

    SQUARTER& = _NewImage(W, H, 32)

    _PutImage , SCR&, SQUARTER&, (0, 0)-(W - 1, H - 1)
    Cls
    _PutImage , SQUARTER&, 0
    Print SCR&, W, H, SQUARTER&
End Sub

  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#10
If @BPlus says it works then (as far as im concerned) IT WORKS! I've grown enough now (maturity!) to accept i dont know everything!

If you guys dont figure it out then call upon the gods (Steve, Pete, dBox, Petr) and they will help you!

john
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Setting mouse to ignore outside of _NewImage PhilOfPerth 11 710 12-18-2025, 07:20 PM
Last Post: Pete
  getting the number of dimensions in an array on the fly? madscijr 7 712 09-16-2025, 12:34 AM
Last Post: madscijr
  Why are SINGLE variables faster than INTEGER variables ? Elzaimer 18 2,309 07-07-2025, 05:01 AM
Last Post: ahenry3068
  Why do FOR/NEXT variables end up +1 more? Dav 14 2,830 08-26-2023, 09:25 PM
Last Post: Kernelpanic

Forum Jump:


Users browsing this thread: 1 Guest(s)