You are here:

C++/converting to vb


Thank you for reply
but my problem is with this line of code:
   g_no -= g_days[i]+(i==1 && leap);
"g_days[i]" is numeric but "(i==1 && leap)" returns a boolean value.
i can't underestand adding a numeric value and a boolean value.
i guess it's a C++ special syntax.
any idea?

Followup To
Question -
i need to convert a C++ code to vb, i have problem with this part of the code:
for (i=0; g_no>=g_days[i]+(i==1 && leap); i++)
   g_no -= g_days[i]+(i==1 && leap);
gm = i+1;
gd = g_no+1;
can u please help me?

Answer -
Hello Mike, thank you for the question.

Although this question should have been refered to the Visual Basic section of this site, I happen to know enough syntax to help with this problem. This is assuming that you have declared all these variables elsewhere with a "Dim" statement except for the i. Visual Basic for-loop syntax make look a little weird the first time you see it. Also, in Visual Basic, arrays are declared/are indexed with parenthesis:

For i As Integer = 0 To 10 Step 1

array(i) = i

Next i

That is the valid syntax for the Visual Basic for-loop. In Basic the "==" expression uses only one "=" and the "&&" is used as "And". I really don't know enough about the language to say exactly how to code the loop you have provided for you, but I figured showing the syntax might help you some. I'm sure one of the Visual Basic guys on this site would know the definite answer. Thanks again for the question.

I hope this information was helpful.

- Eddie

Hello again Mike. Thanks for the question.

The expression (i==1 && leap) is either going to yield true or false, which is defined in the compiler as 1 and 0 respectively. So either 1 or 0 will be added to the array index. Once again, I must reiterate that I am far from an expert in Visual Basic, but I do know the basic syntax of it. It syntax would be something like this:

g_no -= g_days(i) + (i = 1 And leap = True)

I don't even know if (i = 1 And leap = True) will evaluate to a Boolean value in Visual Basic, but that would be the proper syntax to do it. I'm sure one of the guys in the Visual Basic section of this website would be a better help than I. Sorry I couldn't be of more help to you.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 All rights reserved.