RE: Adding Characters to a string
From: Tom Lavedas (tlavedas_at_hotmail.remove.com)
Date: 07/01/04
- Next message: Marty List: "Re: Running as service"
- Previous message: GTS: "Running as service"
- In reply to: Michael Bouchard: "Adding Characters to a string"
- Next in thread: Michael Bouchard: "Re: Adding Characters to a string"
- Reply: Michael Bouchard: "Re: Adding Characters to a string"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 1 Jul 2004 06:13:01 -0700
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: Marty List: "Re: Running as service"
- Previous message: GTS: "Running as service"
- In reply to: Michael Bouchard: "Adding Characters to a string"
- Next in thread: Michael Bouchard: "Re: Adding Characters to a string"
- Reply: Michael Bouchard: "Re: Adding Characters to a string"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|