Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VB guy neds help with real code

VB guy neds help with real code

VB guy neds help with real code

Hi all,
I know that this may not be the correct forum, but I thought I would give it a shot....
I have a snipet of C code I need a little translation on. I only know a small amount of C or ++ so I am kind of stuck. I understand that there are some values assigned in the code that you cant see because it is missing, but I am hoping that you can do you best. My main focus is what occurs with the sprintf call. Any help at all would be greatly appreciated. Here is the code:

void IS_NewPalletNumber( char PalletNumber[] )
   int PalletSeed;

   static char GrafTable[] = "0123456789ABCDEFGHJKLPQRTUVYX#";

   if ( LogSettings.PalletNumber >= IS_MaxPalletNumber ) {
       LogSettings.PalletNumber = 0;

   PalletSeed = LogSettings.PalletNumber;

   /* Keep the pallet numbers unique between 10 machines */
   PalletSeed += ((MachineNumber-1) * 2000);

   sprintf( PalletNumber,"%c%03d",
       GrafTable[10+(PalletSeed/1000)], PalletSeed % 1000 );

}/* IS_NewPalletNumber */

Thanks again,

RE: VB guy neds help with real code

OK, I'll give it a shot. I'm doing this from memory (which is rapidly failing me) so it may not work like it's supposed to.

SUB NewPalletNumber (PalletNumber$)
    REM void IS_NewPalletNumber( char PalletNumber[] )

    REM static char GrafTable[] = "0123456789ABCDEFGHJKLPQRTUVYX#";
    dim GrafTable$[30]
    GrafTable$[0] = "0"
    GrafTable$[1] = "1"
    GrafTable$[2] = "2"
    REM You get the general idea. You could also set this up as a string then use
    REM the INSTR function but this gives you an idea of how the C code worked
    GrafTable$[29] = "#"

    REM I assume in the original C code that LogSettings is a structure. In the
    REM BASIC code I'll assume that LSPalletNumber% and MaxPalletNumber%
    REM are global variables. MaxPalletNumber% is set somewhere else.
    REM LSPalleNumber% = LogSettings.PalletNumber
    REM MaxPalletNumber% = IS_MaxPalletNumber
    REM if ( LogSettings.PalletNumber >= IS_MaxPalletNumber) {
    REM  LogSettings.PalletNumber = 0;
    REM }/*if*/
    IF LSPalletNumber% >= MaxPalletNumber% THEN LSPalletNumber% = 0

    REM PalletSeed = LogSettings.PalletNumber;
    PalletSeed% = LSPalletNumber%

    REM /* Keep the pallet numbers unique between 10 machines */
    REM PalletSeed += ((MachineNumber-1) * 2000);
    REM I'm also assumming that MachineNumber% is a global set somewhere else
    PalletSeed% = PalletSeed% + ((MachineNumber% - 1) * 2000)

    REM sprintf( PalletNumber,"%c%03d", GrafTable[10+(PalletSeed/1000)], PalletSeed % 1000 );
    REM I'm going to break this into parts to make it easier to understand
    I% = 10 + (PalletSeed% / 1000)
    J% = PalletSeed% mod 1000
    X$ = LTRIM$(RTRIM$(STR$(J%)))
    WHILE LEN(X$) < 3
        X$ = "0" + X$
    PalletNumber$ = GrafTable$[I%] + X$

    REM LogSettings.PalletNumber++;
    LSPalletNumber%  = PalleNumber% + 1

I hope that helps. As you can see, sprintf does a lot. It sets up the return string and formats it, too.

James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close