Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > General > Chit Chat
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Chit Chat The place for open discussions.

To C programmers

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-15-2011, 07:28 AM
alfcen's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Okinawa, Ryukyu Islands
Posts: 810
Send a message via Skype™ to alfcen
Awards Showcase
Beta Tester 
Total Awards: 1
Default To C programmers

Hi,
Trying to convert a routine in C to B4A and get false results, believing that the code marked in red is wrongly converted. Anyone who could fix that for me?
Thanks a lot!
Robert


Code:
int get_new_uranometria_page( const double ra, const double de)
{
   
int zone = (int)( (90. - de) * 16. / 180. + .5);
   const 
char zone_splits[17] = { 1610121518182020,
               
20181815121061 };
   
int rval = (int)( (24. - ra) * (double)zone_splits[zone] / 24. + .5);
   rval %= zone_splits[zone];
   
while( zone--)
      rval += zone_splits[zone];
   
return( rval + 1);
}
Code:
Sub PageNewUranometria(ra As Double, de As DoubleAs Int
    
Dim zone, rval As Int
    
Dim zone_splits() As Int
    zone = 
Floor(90 - de) * 16 / 180 + 0.5
    zone_splits = 
Array As Int(161012151818202020181815121061)
    rval = ((
24 - ra) * zone_splits(zone) / 24 + .5)
    rval = rval 
Mod zone_splits(zone)
<font color=
"Red">    Do While rval = rval - 1
        zone = zone - 
1
        rval = rval + zone_splits(zone)
    
Loop</font>
    
Return rval + 1
End Sub

Last edited by alfcen : 10-15-2011 at 07:33 AM.
Reply With Quote
  #2 (permalink)  
Old 10-15-2011, 07:53 AM
derez's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Posts: 978
Awards Showcase
Beta Tester Competition Winner 
Total Awards: 2
Default

I'm not sure what should happen in the line
Code:
while( zone--)
I guess it check the value of zone after reducing it , I don't know when it is true and when false (positive ?)
In your translation you test
Code:
Do While rval = rval - 1
and it will never be true so the loop will not run.
__________________
David Erez
Ramat Hasharon, Israel

Last edited by derez : 10-15-2011 at 07:56 AM.
Reply With Quote
  #3 (permalink)  
Old 10-15-2011, 07:59 AM
alfcen's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Okinawa, Ryukyu Islands
Posts: 810
Send a message via Skype™ to alfcen
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
I'm not sure what should happen in the line
while( zone--)
That's exactly what I do not understand either.
Anyway, thanks for writing, Derez
Reply With Quote
  #4 (permalink)  
Old 10-15-2011, 10:43 AM
Basic4ppc Expert
 
Join Date: Jun 2011
Location: Hertfordshire, UK
Posts: 1,126
Send a message via Yahoo to thedesolatesoul
Default

Quote:
Originally Posted by alfcen View Post
That's exactly what I do not understand either.
Anyway, thanks for writing, Derez
That is a post-decrement.
The zone-1 statement will be executed AFTER the while check.
If you want it to happen before then make it: --zone

EDIT:
I think this should be:
Code:
Do While (zone > 0)
        zone = zone - 
1
        rval = rval + zone_splits(zone)
    
Loop

Last edited by thedesolatesoul : 10-15-2011 at 10:46 AM.
Reply With Quote
  #5 (permalink)  
Old 10-15-2011, 10:58 AM
alfcen's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Okinawa, Ryukyu Islands
Posts: 810
Send a message via Skype™ to alfcen
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Hi thedesolatesoul,

Quote:
Do While (zone > 0)
Bingo! That was the key. The results are poin-point.
Thanks so much for your expert help.

Cheers
Robert
Reply With Quote
  #6 (permalink)  
Old 10-15-2011, 12:04 PM
Basic4ppc Expert
 
Join Date: Jun 2011
Location: Hertfordshire, UK
Posts: 1,126
Send a message via Yahoo to thedesolatesoul
Default

Im no expert
Glad it is solved!

Sent from my GT-I9000 using Tapatalk
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
11111111: Everyone a happy Programmers Day! alwaysbusy Basic4android Updates and Questions 8 09-13-2011 10:51 PM
FMOD 3 programmers API nicolasWhite Questions (Windows Mobile) 1 06-08-2010 12:44 PM
Any freelance programmers available? ohkovar Chit Chat 6 12-05-2008 07:07 PM
Programmers reference for Basic4PPC scott93727 Tutorials 2 05-27-2008 02:46 PM
Programmers reference for Basic4PPC scott93727 Share Your Creations 0 05-27-2008 12:43 AM


All times are GMT. The time now is 08:10 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0