473,473 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Translate from C to VBA?

Hi folks, I'm using a web page I've found as a reference to some pet
project I'm working on in Access and I'm having trouble "translating"
some of the procedures to VBA.

I think the stuff is in some version of C (of which I know nothing
about) and I would really appreciate it if someone might be able to
explain some of these operators to me. The article I'm looking at is at:

http://www-cs-students.stanford.edu/...es/HexLOS.html

Here's an expression in the article with much of what is puzzling me:

if (dx % 2) { // so dx is divisible by two
dx *= 2;
dy *= 2;
}

What does % mean?
// must mean a comment, similar to ' in VBA?
What do the {} represent that is different from ()?
*= is, presumeably, the same as just *?
In other procs, there are +=, presumeably this means +?

What does floor mean? The same as min? Is ceiling the same as max?

Thank you very, very much in advance for any help on this! 8)
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #1
5 3913
If dx Mod 2 Then ' so dx is divisible by two
dx *= 2
dy *= 2
End If

http://authors.aspalliance.com/aldot...translate.aspx

Hope this is helpful

--

/ Sean the Mc /

"Opinions are like flatulence - everyone loves the sound of their own, but
anyone else's usually just stinks !"
-anonymous
"Tim Marshall" <TI****@PurplePandaChasers.Moertherium> wrote in message
news:d0**********@coranto.ucs.mun.ca...
Hi folks, I'm using a web page I've found as a reference to some pet
project I'm working on in Access and I'm having trouble "translating" some
of the procedures to VBA.

I think the stuff is in some version of C (of which I know nothing about)
and I would really appreciate it if someone might be able to explain some
of these operators to me. The article I'm looking at is at:

http://www-cs-students.stanford.edu/...es/HexLOS.html

Here's an expression in the article with much of what is puzzling me:

if (dx % 2) { // so dx is divisible by two
dx *= 2;
dy *= 2;
}

What does % mean?
// must mean a comment, similar to ' in VBA?
What do the {} represent that is different from ()?
*= is, presumeably, the same as just *?
In other procs, there are +=, presumeably this means +?

What does floor mean? The same as min? Is ceiling the same as max?

Thank you very, very much in advance for any help on this! 8)
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me

Nov 13 '05 #2
DFS
Tim Marshall wrote:
Hi folks, I'm using a web page I've found as a reference to some pet
project I'm working on in Access and I'm having trouble "translating"
some of the procedures to VBA.

I think the stuff is in some version of C (of which I know nothing
about) and I would really appreciate it if someone might be able to
explain some of these operators to me. The article I'm looking at is
at:

http://www-cs-students.stanford.edu/...es/HexLOS.html
That is object-oriented C++ code. You can see the objects in the very first
line:

dx = B.x - A.x;

The x coordinate is a member variable of class objects A and B.


Here's an expression in the article with much of what is puzzling me:

if (dx % 2) { // so dx is divisible by two
dx *= 2;
dy *= 2;
}

What does % mean?
That's the modulus operator.

// must mean a comment, similar to ' in VBA?
Yes.
What do the {} represent that is different from ()?
They're just brackets containing the statements to be executed following the
evaluation of the if condition.

*= is, presumeably, the same as just *?
Not quite. This operator multiplies and assigns at the same time.

dx *= 2 means multiply dx * 2 and assign the result to dx. Same thing as dx
= dx * 2.

In other procs, there are +=, presumeably this means +?
Same as above, it increments and assigns at the same time.

dx += 2 means add 2 to dx and assign the result to dx. Same thing as dx =
dx + 2.

What does floor mean? The same as min? Is ceiling the same as max?
Floor2 and ceil2 are macro functions that accept an argument and return a
value, just like a VBA function.

C++: #define Floor2 (X) (((X) >= 0) ? ((X>>1) : (((X)-1)/2))

VBA: Public Function Floor2(X as integer) as Integer
If X >= 0 then
'shift the value of X one bit to the right - I think
else
X = (X-1)/2
endif
End Function
is a bitwise operator

Thank you very, very much in advance for any help on this! 8)



Nov 13 '05 #3
DFS wrote:
Tim Marshall wrote:
< SNIP >

C++: #define Floor2 (X) (((X) >= 0) ? ((X>>1) : (((X)-1)/2))

VBA: Public Function Floor2(X as integer) as Integer
If X >= 0 then
'shift the value of X one bit to the right - I think
else
X = (X-1)/2
endif
End Function


< SNIP >

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Some more C stuff:

The expression X >> 1 shifts the bits in the value X to the right by 1
position, which is equivalent to integer-divide X by 2 (X \ 2).
Shifting to the left, X << 1, is equivalent to multiplying X by 2 (X *
2).

E.g.:

4 decimal = 00000100 >> 1 yields 00000010 (2 decimal): 4/2 = 2
00000100 << 1 yields 00001000 (8 decimal): 4*2 = 8

X >> 2 would translate to X \ (2*2) : 4\(2*2) = 1
X >> 3 would translate to X \ (3*2) : 8\(3*2) = 1

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQijNBoechKqOuFEgEQJaJwCg6fpWF2ZC7MNNA0iqE9ly+x FwWz8AnRvX
PdTDr7zT0/vP99ou/apKJ0Hw
=zWxy
-----END PGP SIGNATURE-----
Nov 13 '05 #4
Sorry - Never followed the link - just looked at the posted bit
My mistake

--

/ Sean the Mc /

"Opinions are like flatulence - everyone loves the sound of their own, but
anyone else's usually just stinks !"
-anonymous
"DFS" <no****@DFS.com> wrote in message news:Kn***************@fe02.lga...
Tim Marshall wrote:
Hi folks, I'm using a web page I've found as a reference to some pet
project I'm working on in Access and I'm having trouble "translating"
some of the procedures to VBA.

I think the stuff is in some version of C (of which I know nothing
about) and I would really appreciate it if someone might be able to
explain some of these operators to me. The article I'm looking at is
at:

http://www-cs-students.stanford.edu/...es/HexLOS.html


That is object-oriented C++ code. You can see the objects in the very
first
line:

dx = B.x - A.x;

The x coordinate is a member variable of class objects A and B.


Here's an expression in the article with much of what is puzzling me:

if (dx % 2) { // so dx is divisible by two
dx *= 2;
dy *= 2;
}

What does % mean?


That's the modulus operator.

// must mean a comment, similar to ' in VBA?


Yes.
What do the {} represent that is different from ()?


They're just brackets containing the statements to be executed following
the
evaluation of the if condition.

*= is, presumeably, the same as just *?


Not quite. This operator multiplies and assigns at the same time.

dx *= 2 means multiply dx * 2 and assign the result to dx. Same thing as
dx
= dx * 2.

In other procs, there are +=, presumeably this means +?


Same as above, it increments and assigns at the same time.

dx += 2 means add 2 to dx and assign the result to dx. Same thing as dx =
dx + 2.

What does floor mean? The same as min? Is ceiling the same as max?


Floor2 and ceil2 are macro functions that accept an argument and return a
value, just like a VBA function.

C++: #define Floor2 (X) (((X) >= 0) ? ((X>>1) : (((X)-1)/2))

VBA: Public Function Floor2(X as integer) as Integer
If X >= 0 then
'shift the value of X one bit to the right - I think
else
X = (X-1)/2
endif
End Function
is a bitwise operator

Thank you very, very much in advance for any help on this! 8)


Nov 13 '05 #5
MGFoster wrote:
DFS wrote:
Some more C stuff:


MG and DFS, I really appreciate your responses, thanks a million! 8)

Thanks also to WAT, thought is appreciated! 8)
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bengt Richter | last post by:
Just thought None as the first argument would be both handy and mnemonic, signifying no translation, but allowing easy expression of deleting characters, e.g., s = s.translate(None,...
1
by: shank | last post by:
I'm sure this is a stretch, but is there some kind of component that I could install to translate from English to Spanish on the fly? I have a lot of equipment features and specifications that I...
4
by: Gadrin77 | last post by:
I have data that looks like <Root> <Main Value="Line1|Line2.|Line3|Line4.|Line5"/> </Root> I'm using Translate(@Value, "|.", ",")
6
by: bobueland | last post by:
The module string has a function called translate. I tried to find the source code for that function. In: C:\Python24\Lib there is one file called string.py I open it and it says
6
by: Anders K. Olsen | last post by:
Hello group I'm trying to list the users and groups who has read access to a file. I use .NET 2.0 and FileInfo.GetAccessControl().GetAccessRules(...) and then loop through the...
1
by: peterbe | last post by:
This has always worked fine for me. Peter fine Now if I do it with a unicode string: Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/string.py", line...
9
bvdet
by: bvdet | last post by:
I have done some more work on a simple class I wrote to calculate a global coordinate in 3D given a local coordinate: ## Basis3D.py Version 1.02 (module macrolib.Basis3D) ## Copyright (c) 2006...
1
by: =?Utf-8?B?R2F1cmF2?= | last post by:
Hi, I am using the Translate() function in one of the .XSLT file to remove the spaces, like this: <xsl:for-each select=".//Illustration"> <xsl:value-of select="translate(./@illusName, ' ',...
3
by: Kenneth McDonald | last post by:
I have the need to occasionally translate a single word programatically. Would anyone have a Python script that would let me do this using Google (or another) translation service? Thanks, Ken
4
by: kovariadam | last post by:
Hi, Does anybody know why i get this error: SQL0176N The second, third or fourth argument of the TRANSLATE scalar function is incorrect. SQLSTATE=42815 with this query: SELECT...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.