Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Visual Basic to C++ Syntax Translation

syntax

  • Please log in to reply
15 replies to this topic

#1 Dren

Dren

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 232 posts

Posted 21 July 2008 - 09:35 AM

Hello,

I’m sorry for being off all the time (for nearly 2 years I guess) but I promise I won’t be again. When I was here for the first time I met TcM, he helped me translate something using a HEX-Editor and suggested me to start programming on Visual Basic 6 and I did so. For about 2 years I have been coding on VB6 and now I’m trying to start coding on C++. It doesn’t seem to be much hard because I have some C++ books but I can’t find some functions that I use on VB6 so I came back here to ask.

So, could anyone please tell me these functions on C++?

The VB6 functions:
Len()
Rigt()
Left()
Mid()
Chr() “or should I write my own?

Seems I have problems only with string functions. I don’t even know how to set a String Variable, only Char. As I read in one of my books C++ doesn’t support string variables longer than 1 characters so I have to use Arrays(wich I don’t know how in C++), I hope that’s not true.

Today I wrote a program for converting Base10 numbers to Base16 but I couldn’t print the output backwards.

The last question, do you suggest me C++ or Visual C++. I code only for Microsoft OS-es.

Thanks a lot,
Dren
  • 0

#2 marwex89

marwex89

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2857 posts

Posted 21 July 2008 - 10:06 AM

Include <cstring> and take a look at the high-level functions there.

string s1, s2; // Empty strings
string s3 = "Yo dude"; // Initialized
string s4("I am cool"); // Also initialized
s2 = "C++ sucks"; // Assigning to a string
s1 = s3 + " " + s4; // Combining strings
s1 += "8"; // Appending to a string
"There are libraries for everything!" (C++ librarian) :D
  • 1
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#3 Dren

Dren

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 232 posts

Posted 21 July 2008 - 10:36 AM

Include <cstring> and take a look at the high-level functions there.

string s1, s2; // Empty strings
string s3 = "Yo dude"; // Initialized
string s4("I am cool"); // Also initialized
s2 = "C++ sucks"; // Assigning to a string
s1 = s3 + " " + s4; // Combining strings
s1 += "8"; // Appending to a string
"There are libraries for everything!" (C++ librarian) :D


WoooooW, THANK U MAN, THANK U SO MUCH, that is relly GREAT. I Googled cstring C++ library and got all the functions I needed except Chr().

About the last questin, what do you suggest? Visual C++ or C++?

Thanks A TON :D
  • 0

#4 MeTh0Dz

MeTh0Dz

    CC Leader

  • Just Joined
  • PipPipPipPipPipPipPip
  • 1726 posts

Posted 21 July 2008 - 10:55 AM

What do you mean Visual C++ or C++?
  • 0

#5 marwex89

marwex89

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2857 posts

Posted 21 July 2008 - 02:00 PM

Visual C++ = Microsoft Visual Studio (not 2008, that is MANAGED C++, but earlier) C++

C++ means usually GNU free compiler, like MingW.

I use the last one, but many people use the Express edition of VS. Try both, it's free :D
  • 0
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#6 MeTh0Dz

MeTh0Dz

    CC Leader

  • Just Joined
  • PipPipPipPipPipPipPip
  • 1726 posts

Posted 21 July 2008 - 02:04 PM

Oh okay? Lol, I kind of thought that, but wasn't really sure what someone would want to know about them.

Personally I use Dev-Cpp and Code::Blocks, which use Gcc/MingW.
  • 0

#7 marwex89

marwex89

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2857 posts

Posted 21 July 2008 - 02:17 PM

About char().... In C++ that's just a cast from an integer to char (32bit and 8bit), which can be done like this:

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char * argv[])
{
    [COLOR=Red]int ASCII = 65;[/COLOR]
   // [COLOR=Lime]int ASCII = 0x41;[/COLOR] // In hexadecimal, if you need it
    [COLOR=Red]char c1 = static_cast<char>( ASCII );[/COLOR] // Declare c1 as char, and perform cast
    cout << c1 << endl; // Display character (Uppercase A)
    system("PAUSE");
    return (EXIT_SUCCESS);
}

  • 0
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#8 Dren

Dren

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 232 posts

Posted 21 July 2008 - 05:03 PM

GOD **** IT :eek: I need study these **** libraries first :mad: That is GREAT Bro, I REALLY APPRECIATE YOUR HELP :D :D :D

About the C++ or VC++ that was what I was thinking of. So U suggest me C++? I dont have that but can I use the VC++ 6 ConsoleApplication method instead?

Will it be easier for me to get from C++ coding to VC++ creating forms and linking their objects to the code or am I wrong? I really need some suggestions, yesterday I started this and Im NOT going to give up.

THANX AGAIN marwex89, U R MY BRO :D
  • 0

#9 marwex89

marwex89

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2857 posts

Posted 21 July 2008 - 05:17 PM

No problem :D
VC++ and C++ is just the same... It doesn't really matter to most people, I guess it would take you about a week to get into VC++ IDE (wild guess) and their linking and form creating.

There is no form creating in C++ (Dev-C++, NetBeans etc), so unless you want to hard code your forms, I suggest you at least try Visual Studio to see if that's OK.

Warning: Pro edition = $$$, use Express :)

Using VC++ console app:
That's a template, with compiler and linking options set etc. All common C++ IDEs have those.

Any more I could help you with while we're at it? :D

EDIT:
BTW, you have VisualStudio 6???
Use it. Period :D
See a comparison on web between C++ in VS6 and newer. If nothing you absolutely MUST have, use VS6, I guess.

Edited by marwex89, 21 July 2008 - 05:20 PM.

  • 0
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#10 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 21 July 2008 - 07:04 PM

Len() has several equivalents in C++.

1) For structures and primitives like int, etc., use sizeof().
2) For strings, use strlen() for primitive strings, i.e. char arrays. (include string.h)
3) I don't know how to get the length of a string string.
4) For dynamically allocated memory, use _msize() (include memory.h or malloc.h)
  • 0

#11 Dren

Dren

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 232 posts

Posted 22 July 2008 - 02:33 PM

No problem :D
VC++ and C++ is just the same... It doesn't really matter to most people, I guess it would take you about a week to get into VC++ IDE (wild guess) and their linking and form creating.


I just started but I have a problem. I have downloaded a book from a link that I found here in CodeCall called "Sams Teach Yourself Visual C++ in 21 Days"
and thats with the whole meaning of the word GREAT but when I try to compile some projects i get this error:


--------------------Configuration: P1 - Win32 Debug--------------------
Compiling resources...
Error executing rc.exe.


I really dont know why?


There is no form creating in C++ (Dev-C++, NetBeans etc), so unless you want to hard code your forms, I suggest you at least try Visual Studio to see if that's OK.

Warning: Pro edition = $$$, use Express :)

Using VC++ console app:
That's a template, with compiler and linking options set etc. All common C++ IDEs have those.

Any more I could help you with while we're at it? :D


Dont worry about this Bro, in my country there are no copyright laws so I use torrents to download stuff. At the moment Ive got VS6 and VS2008 Pro. Im planning to get from VS6 to VS .NET, am I going backwards?

Ive got an other questions. I know im getting you all bored but CodeCall users know how to respect ppl. who dont know stuff, U GUYS RULE.

I need to know the Visual Basic's PSet function for C++, is that possible?

THANX A LOT BROTHERS,
Dren
  • 0

#12 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 22 July 2008 - 02:52 PM

No, you're catching up with everyone else by switching to .NET.

Drawing on forms is kinda involved for a novice C++ programmer, even using MFC. I strongly suggest you stay away from Win32 (i.e. GUI) programming for a bit until you've got the basics down. Start with console programs first, then work your way up. To draw on a form, you need all these fun things like handles, brushes, device contexts, etc. which Visual Basic conveniently hides from you.

As for your rc.exe (Resource Compiler), you could put your code in a new project; sometimes the project files get messed up and you can't really reset them too well. If that doesn't work, post your resource file (usually called something like projectname.rc or resource.rc) as well as the header file for it (usually resource.h). There might be some syntax violation or perhaps a file missing that rc.exe is looking for. Is there any more text in the error message, or is that it?
  • 0





Also tagged with one or more of these keywords: syntax

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download