Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB guy neds help with real code

Status
Not open for further replies.

woyler

Programmer
Jun 20, 2001
678
US
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;
}/*if*/

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 );

LogSettings.PalletNumber++;
}/* IS_NewPalletNumber */

Thanks again,
Bill
 
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.
Code:
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$ = &quot;0&quot; + X$
    WEND
    PalletNumber$ = GrafTable$[I%] + X$

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

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top