Hi There,

It is my first post. I am currently workign for a company and have just been moved into R+D. Part of my new job involves C++ Programming.

I am having trouble with numerous things, (was thrown in the deepend)
Basically, This program is designed to keep track of all surfacemounth component activity, jobs, reference numbers, part locations etc...

The thing i am having trouble with is this...
Every PCB has a specific lay file which basically shows all the different components and their quantities taken from the stores location.

This new addition to the program I am working on will enable each tube/reel of parts to be given a new unique reference assignment.

I am having trouble trying to figure out how to read the specific reference number "06/11/07_1" so that the "1" will become an integer and can be incremented everytime there is a new reference number, and also that the program has intelligence as to what was the last reference number given so that it continues from where it left off.

Sorry if my gobble-dee-gook is confusing, but i was trying to put it in the best way i could.

If anyone can help a noob, i would greatly appreciate it.

If the program knows the last number used, such as "06/11/07_1", then extract the digits beyond the underline, convert to int, increment the int, then reformat the number.

Try something like this, I'm still new to C++, but learning. Hope this works.

int month;
int date;
int year;
int someint;

InFile >> month;
InFile.ignore(500, '/');
InFile >> day;
InFile.ignore(500,'/');
InFile >> year;
InFile.ignore(500, '_');
InFile >> someint;
//InFile is declared as the ifstream
Member Avatar for iamthwee

>If anyone can help a noob, i would greatly appreciate it

Showing us what code you have so far might be an idea hey!?

one way to implement dragon's algorithm:

#include <iostream>
#include <sstream>
using namespace std ;

enum { delimiter = '_' } ;

int digits_beyond_delimiter( const string& str )
{
  istringstream stm(str) ;
  if( stm.ignore( str.size(), '_' ) )
  {
    int number ;
    if( stm >> number ) return number ;
  }
  return -1 ; // error in string
}

string replace_number_after_delimiter( const string& str, int number )
{
  istringstream input( str ) ;
  ostringstream output ;
  char ch ;
  while( input.get(ch) )
  {
    output.put(ch) ;
    if( ch == delimiter ) break ;
  }
  output << number ;
  return output.str() ;
}


int main()
{
  const string str =  "06/11/07_13" ;
  int number = digits_beyond_delimiter( str )  ;
  cout << str << '\n' ;
  string result =  replace_number_after_delimiter( str, ++number ) ;
  cout << result << '\n' ;
}

My advice would be to put the problem aside for a month and get some basic C++ under your belt first. Look for a book called "Accelerated C++".

Hacking away at the problem one post at a time on a forum isn't going to produce a meaningful product at the end of it, and isn't going to be done any quicker either.

From what you've said, it sounds like you're modifying a rather extensive existing program, in which case your newbie-ish hackery is just going to be a future maintenance nightmare.

That is assuming your employer knows that you don't know C++, and will understand your request for learning time. If on the other hand you claimed some C++ skill and they've called your bluff, well then that's your problem to deal with. Using a forum to get others to do your job for free isn't the way to go.

Yes you are right, I am a newb, however the company does know this.. Currently studying a degree in electronics in my spare time, and we havent really gotten into depths of c++ in the course (not to mention the course is distance learning and is done in my spare time) I have been hacking away at this and a few other things like automated testing procedures(these of which aren't that bad - mainly because i see what was done in the previous ones).
I have that sam's tech yourself c++ in 21 days, is that c++ accelerated book any decent?

Anyways, the code i have thus far for where i need this to go is...

//---------------------------------------------------------------------------
void __fastcall TStockTransferForm::Button2Click(TObject *Sender)
{
TListItem *aListItem2;
TQuery *aQuery = NULL;
TQuery *aQuery2 = NULL;
AnsiString asType, asStr;
AnsiString asPartnum, asQuantity, asRefnum;
//int iRef  to be the incrementing integer..



TransferListView->Items->Clear();


aQuery2 = new TQuery( NULL );      //query to find partcode, and also SM Feeder type
aQuery2->DatabaseName = DataModuleForm->AutoQDatabase->DatabaseName;
aQuery2->SQL->Add( "select * from aq_part join aq_footprint on aq_part.part_ftprintcode = aq_footprint.ftprintcode where aq_part.partcode = :p0" );


aQuery = new TQuery( NULL );      //query to find reference layfile code
aQuery->DatabaseName = DataModuleForm->EfacsDatabase->DatabaseName;
aQuery->SQL->Add( "select * from transact where tratype = 'MTP' and traloc = 'SM-Q' and trasource = 'RLS' and traref = :p0 order by trapart asc " );


asStr = "PRO";
asStr += AnsiString::StringOfChar('0', 6-ReferenceEdit->Text.Length());
asStr += ReferenceEdit->Text;
aQuery->Params->Items[0]->AsString = asStr;
aQuery->Open();
aQuery->First();
for ( int i=0 ; i<aQuery->RecordCount ; i++ )
{
aListItem2 = TransferListView->Items->Add();
aListItem2->Caption = aQuery->FieldValues["trapart"];
aListItem2->SubItems->Add( aQuery->FieldValues[ "TRAQUANT" ] );


aQuery2->Params->Items[0]->AsString = aQuery->FieldValues["trapart"];
aQuery2->Open();
aQuery2->First();


if ( aQuery2->RecordCount )
{
aListItem2->SubItems->Add( aQuery2->FieldValues[ "FTPRINTTYPE" ] );
}
else
{
aListItem2->SubItems->Add( "NA" );
}
aListItem2->SubItems->Add( 1 );
aQuery->Next();



asPartnum =  aQuery->FieldValues[ "trapart" ];
asQuantity = aQuery->FieldValues[ "TRAQUANT" ];



asRefnum = DateToStr(Date()) + "_" + iRef;
TransferStrings->Lines->Add( asPartnum + ",  " + asQuantity + ",  " + asRefnum );


}
delete aQuery;
delete aQuery2;
}

Tis a bunch of SQL and database stuff as you can "c"...Tbh, i know "mimmicking isn't the best way as you don't really learn the theory behind everything, but i think i have done pretty well so far.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.