Formatting numbers in a string

  • Thread starter Thread starter rb608
  • Start date Start date
R

rb608

I'm in the process of creating a form to allow me to more quickly
catalog & caption some photos; and for a novice VB user, I'm doing
okay I guess. I have set up fields for the image path, prefix,
sequence number, and file type. e.g.
Path = C:\MyDocuments\MyPhotos\Vacation\
Prefix = ThemePark
Sequence = 001
File type = .jpg

By concatenating all of these fields, I can have the form pull up the
image file with Me!frmImgFile.Picture = Me!txtPath & Me!txtPrefix & Me!
txtSequence & Me!txtFiletype.

So far, so good.

Then I got to where I wanted to have the form step to the next image
sequentially, by adding 1 to the txtSequence field, so I changed the
sequence field format from text to number. Here's where I hit the
limits of my knowledge.

The file names in the image folder have a three-digit format, i.e.
ThemePark001.jpg, ThemePark002.jpg, etc. In concatenating the
sequence number, I'm stuck on how to force that three-digit format in
the concatenation so that I don't get ThemePark1.jpg when I need
ThemePark001.jpg.

I've considered the "blunt instrument" approach of concatenating a
zero or two depending on the magnitude of the sequence number, but I'm
thinking there must be something more elegant and simple.

TIA,
Joe F.
 
This may not be more elegant or simple but it works:

strNewSequence = Right("000" & (CInt(strOldSequence)+1),3)
 
I'm in the process of creating a form to allow me to more quickly
catalog & caption some photos; and for a novice VB user, I'm doing
okay I guess. I have set up fields for the image path, prefix,
sequence number, and file type. e.g.
Path = C:\MyDocuments\MyPhotos\Vacation\
Prefix = ThemePark
Sequence = 001
File type = .jpg

By concatenating all of these fields, I can have the form pull up the
image file with Me!frmImgFile.Picture = Me!txtPath & Me!txtPrefix & Me!
txtSequence & Me!txtFiletype.

So far, so good.

Then I got to where I wanted to have the form step to the next image
sequentially, by adding 1 to the txtSequence field, so I changed the
sequence field format from text to number. Here's where I hit the
limits of my knowledge.

The file names in the image folder have a three-digit format, i.e.
ThemePark001.jpg, ThemePark002.jpg, etc. In concatenating the
sequence number, I'm stuck on how to force that three-digit format in
the concatenation so that I don't get ThemePark1.jpg when I need
ThemePark001.jpg.

I've considered the "blunt instrument" approach of concatenating a
zero or two depending on the magnitude of the sequence number, but I'm
thinking there must be something more elegant and simple.

TIA,
Joe F.

If [Sequence] is Text datatype:
Format(Val([Sequence]) + 1,"000")

If [Sequence] is Number datatype:
Format([Sequence] +1,"000")
 

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

Back
Top