It is currently Sat May 25, 2013 1:51 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: TypeCast double to integer for Array( Index )
PostPosted: Thu May 31, 2012 11:09 pm 
Offline
User
User

Joined: Wed May 09, 2012 12:40 am
Posts: 28
The following causes compiler to hiccup:
Code:
Define d1.d
Dim MyArray.d(10)

d1 = 2.0
MyArray( d1 ) = 123.45


So I changed it to this which works:
Code:
Define d1.d
Dim MyArray.d(10)

d1 = 2.0
MyArray( Int(d1) ) = 123.45


Question:
My snippet is just to demonstrate the issue where my index is being passed in by a 3rd party app as a double. Thus I need to typecast it to an integer for the array.

Is there a more efficient way to typecast from double to integer for the array index?


Top
 Profile  
 
 Post subject: Re: TypeCast double to integer for Array( Index )
PostPosted: Fri Jun 01, 2012 4:53 pm 
Offline
User
User

Joined: Wed May 09, 2012 12:40 am
Posts: 28
Is this more efficient?

Code:
Define d1.d,  i1.i
Dim MyArray.d(10)

d1 = 2.0
i1 = d1
MyArray( i1 ) = 123.45


Top
 Profile  
 
 Post subject: Re: TypeCast double to integer for Array( Index )
PostPosted: Fri Jun 01, 2012 11:54 pm 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2864
Location: Wales, UK
...the most efficient way would surely be to read the passed value as an int instead of as a double - how is the other app passing the value exactly?

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
 Post subject: Re: TypeCast double to integer for Array( Index )
PostPosted: Sat Jun 02, 2012 5:35 pm 
Offline
User
User

Joined: Wed May 09, 2012 12:40 am
Posts: 28
The 3rd party app is passing me an array of doubles. The array is multi purpose whereby sometimes the values in the array are to be used as doubles in math calculations, yet other times, as in my case, as an array index.


Top
 Profile  
 
 Post subject: Re: TypeCast double to integer for Array( Index )
PostPosted: Sat Jun 02, 2012 8:45 pm 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2864
Location: Wales, UK
Yes, but lets say your eyes are closed and nobody has told you what type of data you will receive - it could be bananas, it could be doubles.
Quote:
- how is the other app passing the value exactly?

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
 Post subject: Re: TypeCast double to integer for Array( Index )
PostPosted: Sat Jun 02, 2012 9:16 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 1387
Location: Boston, MA
How are you declaring your 3rd party dll?
Maybe use a prototype and call it differently depending on double array or integer array?
Code:
Prototype[C].i your_dll_fn(param1.i, param2.i, etc.i, *nPoints.i, *IntOrDbl_array)
Global.i hdll = OpenLibrary(#PB_Any, "C:\Your_dll_path\your_dll.dll")
If hdll
  Global Your_dll_fn.Your_dll_fn = GetFunction(hdll, "Your_dll_fn")
Else
  MessageRequester("", "Error opening dll", #MB_ICONERROR)
EndIf
Define.i nPts
Dim arD.d(10)
Dim arI.i(10)
; Call dll with Double array
  your_dll_fn(0, 0, 0, @nPts, arD())
; Or Call it with Integer array
  your_dll_fn(0, 0, 0, @nPts, arI())

If hdll
  CloseLibrary(hdll)
EndIf

_________________
To understand recursion, you must first understand recursion. ~ unknown
I never make stupid mistakes. Only very, very clever ones. ~ John Peel


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Exabot [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye