|
Posted by Andy B on April 24, 2005, 1:02 pm
Please log in for more thread options Thanks Greg,
It sounds perfect.
greg.driver@btinternet.com wrote in message
> Andy,
>
> This is a MapBasic function (Mapinfo scripting language) that I've
> written to do what you want:
> <-------
> '// function to return the tile letters (ie SU) given the x,y coords
> Function GetTileLetters(ByVal szXcoord As Float, ByVal szYcoord As
> Float) as String
> Dim x, y As Float
> Dim FirstLet, SecondLet As String
> szXcoord = szXcoord + 1000000
> szYcoord = szYcoord + 500000
>
> '// do the 500km squares first
> x = (szXcoord/500000) MOD 5
> y = (szYcoord/500000) MOD 5
>
> If (ASC("A")+(x+5*(4-y))) >= ASC("I") Then
> FirstLet = CHR$(ASC("A")+(x+5*(4-y))+1)
> Else
> FirstLet = CHR$(ASC("A")+(x+5*(4-y)))
> End If
>
> '// do the 100km squarea
> x = (szXcoord/100000) MOD 5
> y = (szYcoord/100000) MOD 5
>
> If (ASC("A")+(x+5*(4-y))) >= ASC("I") Then
> SecondLet = CHR$(ASC("A")+(x+5*(4-y))+1)
> Else
> SecondLet = CHR$(ASC("A")+(x+5*(4-y)))
> End If
>
> GetTileLetters = FirstLet + SecondLet
>
> End Function
> ------->
> ASC() returns the ASCII character code - ASC("A") = 65
> CHR$() returns the character-string of the corresponding ASCII code -
> CHR$(65) = "A"
>
> I got it from somewhere on the web but can't remember where.
>
> Let me know if you need anything clarifying.
>
> Gref
|