Re: Adding Characters to a string
From: Michael Bouchard (mbouchard_at_xNOSPAMx.ci.charlotte.nc.us)
Date: 07/01/04
- Next message: Torgeir Bakken \(MVP\): "Re: Passing double quotes with wsharguments"
- Previous message: S Shearman: "Passing double quotes with wsharguments"
- In reply to: Tom Lavedas: "RE: Adding Characters to a string"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 1 Jul 2004 15:26:24 -0400
Thanks Tom,
I was just trying to find a cleaner way to do it. Not only does that clean
up the script it also helps me learn how to do things better. When I look
back at some of my first scripts. Ack.
Thanks again,
Mike
"Tom Lavedas" <tlavedas@hotmail.remove.com> wrote in message
news:4CFD57B6-9D62-4C78-ADC8-464C2BF3416A@microsoft.com...
> Maybe ...
>
> CheckString = "565495423564898562124165"
>
> If Len(CheckString) <> 29 then
> If Len(CheckString) = 24 then
> MyVar = Mid(CheckString,1,4)
> for i = 5 to 21 Step 4
> MyVar = MyVar & "-" & Mid(CheckString,i,4)
> Next
> Msgbox MyVar & vbcr & "5654-9542-3564-8985-6212-4165"
> Else
> 'Something here
> End If
> Else
> 'Something here
> End if
>
> Or maybe this, which may be a few microsecconds faster ;-) ...
>
> CheckString = "565495423564898562124165"
>
> If Len(CheckString) <> 29 then
> If Len(CheckString) = 24 then
> Dim aTemp(5)
> n = 0
> for i = 1 to 21 Step 4
> aTemp(n) = Mid(CheckString,i,4)
> n = n + 1
> Next
> MyVar = Join(aTemp, "-")
> Msgbox MyVar & vbcr & "5654-9542-3564-8985-6212-4165"
> Else
> 'Something here
> End If
> Else
> 'Something here
> End if
>
> Though your approach is okay, too.
>
> Tom Lavedas
> ===========
>
> "Michael Bouchard" wrote:
>
> > I am prompting technicians for a serial number at the begining of an
install
> > and wanted to try to make sure that the serial number was formated
> > correctly.
> >
> > The script below works but I am just wondering if there is a better way
to
> > add the - to the string
> >
> > Thanks,
> >
> > Mike
> >
> > CheckString = "565495423564898562124165"
> >
> > If Len(CheckString) <> 29 then
> > If Len(CheckString) = 24 then
> > MyVar = Mid(CheckString,1,4)
> > MyVar = MyVar & "-" & Mid(CheckString,5,4)
> > MyVar = MyVar & "-" & Mid(CheckString,9,4)
> > MyVar = MyVar & "-" & Mid(CheckString,13,4)
> > MyVar = MyVar & "-" & Mid(CheckString,17,4)
> > MyVar = MyVar & "-" & Mid(CheckString,21,4)
> > Msgbox MyVar & vbcr & "5654-9542-3564-8985-6212-4165"
> > Else
> > 'Something here
> > End If
> > Else
> > 'Something here
> > End if
> >
> >
> >
- Next message: Torgeir Bakken \(MVP\): "Re: Passing double quotes with wsharguments"
- Previous message: S Shearman: "Passing double quotes with wsharguments"
- In reply to: Tom Lavedas: "RE: Adding Characters to a string"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|