Probably a really simple question, converting a C app to VB6, don't know a command!

Soldato
Joined
18 Oct 2002
Posts
8,016
Before anyone starts - I program in VB6, I don't want this to turn into an arguement as to which is best.

Anyways, I've found some code which is in C or C#, and i'm just a little confused as to what a couple of lines are, and how I'd re-write it in VB6.

Searching is proving very difficult, as it involves =, < and + symbols, which search engines don't like! ;)

The lines are as follows, I've highlighted the bits VB6 is failing on in red:

mask = 1 << (i - 1);
arc = earthCircum / ((1 << zoom) * 256)
quad += cell;

(not all one after the other in a procedure)

I'm sure they're some kind of maths or comparison commands, but I'm not sure what they are/do!


Thanks in advance for any help! :)


Garry
 
quad += cell;

That just means quad = (quad + cell) - basically add whatever comes after the += to quad.

<< hmmm...
well that's the bitwise left shift operator (stolen from msdn)...
The << operator shifts the bits of expression1 left by the number of bits specified in expression2. For example:

var temp
temp = 14 << 2 The variable temp has a value of 56 because 14 (00001110 in binary) shifted left two bits equals 56 (00111000 in binary).

OR
It's a stream operator, writes to the stream... i'm confused by your thing in this case though. It's early and I'm ranting at IT because they've changed our DevPartner License without telling us.

Without knowing what "zoom" is... difficult to say, but i'm stupid anyway.
 
Thanks Jono :)


"zoom" is a zoom level from 1 to 19. It's basically for getting images from the Microsoft VirtualEarth servers for displaying in an app based on longitude/latitude.


The complete C code for the procedure(s) where there is the << are as follows:

Code:
		private int LatitudeToYAtZoom(double lat, int zoom)
		{
			double arc = earthCircum / ((1 << zoom) * 256);
			double sinLat = Math.Sin(DegToRad(lat));
			double metersY = earthRadius / 2 * Math.Log((1 + sinLat) / (1 - sinLat));
			int y = (int)Math.Round((earthHalfCirc - metersY) / arc);
			return y;
		}

		private static string TileToQuadKey(int tx, int ty, int zl)
		{
			string quad = "";
			for (int i = zl; i > 0; i--)
			{
				int mask = 1 << (i - 1);
				int cell = 0;
				if ((tx & mask) != 0)
				{
					cell++;
				}
				if ((ty & mask) != 0)
				{
					cell += 2;
				}
				quad += cell;
			}
			return quad;
		}
 
The << in this case are definitely bit-shift operators. I don't think VB6 has anything equivalent, but should be easy to replace nevertheless.

a << b is equivalent to a * 2^b where ^ represents "to the power of".
a >> b is equivalent to a / 2^b.

Therefore 1 << zoom is equivalent to 2^zoom. I think VB6 recognises the ^ operator as "to the power of" so you should be able to replace it like that. Don't quote me on that though!

Similarly, 1 << (i - 1) is equivalent to 2^(i - 1).

Note: from looking at the code you're trying to port, you may also have trouble with the & operator. In C this means "bitwise and". I think in VB6 the And operator does the same thing. Again, no quoting. :p :D
 
xyphic,

Brilliant, that is it exactly :cool:

That part of it is now working perfectly, confirmed with a few known bits of data :)

Many, many thanks! :D


Garry
 
Back
Top Bottom