Incrementing a count

B

bthumber

I'm not sure if I should ask this question or in the C# group, but here goes...
I had an application method that counts the total number of records that
like for example buffal. From 0-99 things work find, see the code:

int count = (int)Session["hostCount"];

if ((count >= 0) && (count <= 98))
{
count++;

SequenceNumbers sn = new SequenceNumbers();
lblSubStr.Text = sn.GetNumberSequence(count);
}

// first record would be buffal01, last record buffal99, next record should
be buffala1.

If that test fails the sequence of characters and numbers runs, a1, a2,
a3...z9. At this point there are 99 records in the database and the "count"
is 99. If I start the count at 99 then increment if by it will be 100 and the
sequence will start at l2, so I need to reset the count to start at 0 so that
the next record buffala1, see code:

else if ((count >= 0) && (count <= 233))

{// got to increment this somewhere
count = 0;

AlphaNumberSeq ans = new AlphaNumberSeq();
lblSubStr.Text = ans.GetAlphaNumberSeq(count);

}

How can I start the AlphaNumberSeq to zero and increment the count each time?
 
G

Guest

I'm not sure if I should ask this question or in the C# group, but here goes...
I had an application method that counts the total number of records that
like for example buffal. From 0-99 things work find, see the code:

        int count = (int)Session["hostCount"];

        if ((count >= 0) && (count <= 98))
        {
            count++;

            SequenceNumbers sn = new SequenceNumbers();
            lblSubStr.Text = sn.GetNumberSequence(count);
        }

// first record would be buffal01, last record buffal99, next record should
be buffala1.

If that test fails the sequence of characters and numbers runs, a1, a2,
a3...z9. At this point there are 99 records in the database and the "count"
is 99. If I start the count at 99 then increment if by it will be 100 and the
sequence will start at l2, so I need to reset the count to start at 0 so that
the next record buffala1, see code:

        else if ((count >= 0) && (count <= 233))

        {// got to increment this somewhere
            count = 0;

            AlphaNumberSeq ans = new AlphaNumberSeq();
            lblSubStr.Text = ans.GetAlphaNumberSeq(count);

        }

How can I start the AlphaNumberSeq to zero and increment the count each time?

Probably you just need to -98 (see the last line)

int count = (int)Session["hostCount"];
if ((count >= 0) && (count <= 98))
{
count++;
SequenceNumbers sn = new SequenceNumbers();
lblSubStr.Text = sn.GetNumberSequence(count);
}

else if ((count >= 0) && (count <= 233))
{
AlphaNumberSeq ans = new AlphaNumberSeq();
lblSubStr.Text = ans.GetAlphaNumberSeq(count-98);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top