VB to VC++

This is a discussion on VB to VC++ within the C++ Programming forums, part of the General Programming Boards category; I’m working on a simple chat client to practice network programming w/ VC++ .NET. I have a yahoo messenger login ...

  1. #1
    Pupil
    Join Date
    Oct 2005
    Location
    Toledo
    Posts
    27

    VB to VC++

    I’m working on a simple chat client to practice network programming w/ VC++ .NET. I have a yahoo messenger login example for the latest protocol (YMSG12) written in VB 6 and I’m converting everything over to VC++. Below are two functions for converting ASCII to HEX and vise versa. These helper functions are used when constructing the login packets. I’m not sure if these two functions can be converted to VC++. For instance “DoEvents” and “UBound”, I have no idea how to convert this, and I could not find anything on google.

    Code:
    Public Function ChrH(strString) As String
        'hex to ascii
        Dim A1	
        A1 = Split(strString, " ")
        Dim i As Integer
        For i = 0 To UBound(A1)
            ChrH = ChrH & Chr("&H" & A1(i))
            DoEvents
        Next i
    End Function

    Code:
    Public Function AscToHex(strString As String) As String
        'ascii to hex
        Dim i As Integer
        For i = 1 To Len(strString)
            If Len(Hex(Asc(Mid(strString, i, 1)))) = 1 Then
                AscToHex = AscToHex & "0" & Hex(Asc(Mid(strString, i, 1)))
            Else
                AscToHex = AscToHex & Hex(Asc(Mid(strString, i, 1)))
            End If
            If i <> Len(strString) Then AscToHex = AscToHex & " "
            DoEvents
        Next i
    End Function

  2. #2
    Registered User
    Join Date
    May 2007
    Posts
    147
    UBound is just the endpoint of the loop.

    In C++ you might ask for the size of an STL array.

    DoEvents invokes a message loop during what might be a long routine, possibly so it can be cancelled.

    You may either ignore it (eliminate it), or obviate it by running this in a thread, if you find that familiar. This will probably run fast enough in C++ that you don't need a DoEvent equivalent.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It would run fast enough in VB too. The author was just overly zealous about putting DoEvents everywhere.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Pupil
    Join Date
    Oct 2005
    Location
    Toledo
    Posts
    27
    Thank you, I’m glad to hear this, my past 3 years of programming involve C++ & JAVA I know very little about VB.

    It’s a shame, I can find some very good examples online, but, most are written in VB.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    For what it's worth, here's a proper C++ way of doing the second part.
    Code:
    std::string char_codes_to_hex_rep(const std::string &s)
    {
      std::ostringstream out;
      out << std::hex << std::setfill('0');
      for(std::string iterator i = s.begin(); i != s.end(); ++i) {
        out << std::setw(2) << static_cast<int>(*i);
      }
      return out.str();
    }
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Pupil
    Join Date
    Oct 2005
    Location
    Toledo
    Posts
    27
    CornedBee, you rock!

    I have been debugging this method all day long.

    Your’s works like a charm. Thank you so much

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You're welcome.

    As a rule, it doesn't pay to translate from VB to C++.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing an Array of Strings from VB to a C DLL
    By mr_nice! in forum Windows Programming
    Replies: 9
    Last Post: 03-08-2005, 06:16 AM
  2. C with VB ?
    By khpuce in forum Windows Programming
    Replies: 2
    Last Post: 02-21-2005, 08:00 AM
  3. Hai Everybody !VC dll in VB ?
    By samudrala_99 in forum Windows Programming
    Replies: 2
    Last Post: 06-20-2003, 08:22 AM
  4. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM
  5. Sending a string to C++ from VB 6.
    By VirtualAce in forum C++ Programming
    Replies: 4
    Last Post: 08-21-2001, 03:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21