By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,205 Members | 938 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,205 IT Pros & Developers. It's quick & easy.

Help to CC++ a Visual Basic 6.0

P: 2
Hello to all, I have a problem that I cannot solve, I have a file in C++ and like not like translating it to visual BASIC, I write to them to be able to receive aid and that somebody helps me to translate it to Visual BASIC 6,0, the code is the following one

#ifndef _INC_C_DEM
#define _INC_C_DEM

************************************************** ***************************************
#include <afx.h>
#include <math.h>

************************************************** ***************************************
class C_DEM
{
public:
C_DEM();
~C_DEM() {};

DWORD Init( const char *Filename );
short GetElevM( float &Lat, float &Lon );
float GetElevF( float &Lat, float &Lon );

private:
FILE *m_fpIn;

float m_LatConv;
float m_LonConv;
float m_DenConv;

long m_Line;
long m_Elem;
long m_Offset;

short m_Elev;
};

#endif // _INC_C_DEM

///////////////////////////////////////////////////////////////////////////////
//
// C_DEM.cpp
//
// This class is used to access a digital elevation map (DEM) in order to
// get the elevation at a specified latitude and longitude
//
// Notes:
// Returned elevation of 9999 indicates an error
// Returned elevation of -9999 indicates water

#include "C_DEM.h"

///////////////////////////////////////////////////////////////////////////////

C_DEM::C_DEM()
{
m_LatConv = (float) (89.0 + (239.0 / 240.0));
m_LonConv = (float) -(179.0 + (239.0 / 240.0));
m_DenConv = (float) (1.0 / 120.0);
}

///////////////////////////////////////////////////////////////////////////////

DWORD C_DEM::Init( const char *Filename )
{
m_fpIn = fopen( Filename, "rb" );
if( m_fpIn == NULL )
{
return( GetLastError() );
}

return( ERROR_SUCCESS );
}

///////////////////////////////////////////////////////////////////////////////

short C_DEM::GetElevM( float &Lat, float &Lon )
{
if( m_fpIn == NULL )
{
return( 9999 );
}

m_Line = (long) ((m_LatConv - Lat) / m_DenConv);
m_Elem = (long) fabs((double)((m_LonConv - Lon) / m_DenConv));

m_Offset = (m_Line * 86400) + (m_Elem * 2);
if( fseek( m_fpIn, m_Offset, SEEK_SET ) != 0 )
{
return( 9999 );
}
else
{
if( fread( &m_Elev, 2, 1, m_fpIn ) != 1 )
{
return( 9999 );
}
else
{
return( m_Elev );
}
}
}

///////////////////////////////////////////////////////////////////////////////

float C_DEM::GetElevF( float &Lat, float &Lon )
{
m_Elev = GetElevM( Lat, Lon );
if( (m_Elev == 9999) || (m_Elev == -9999) )
{
return( (float) m_Elev );
}
else
{
return( (float) m_Elev / (float) 0.3048 );
}
}
Nov 13 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.