|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
how to make this code shorter?
<%
dim ID ID = "024053J" num1 = mid(ID,1,1) num2 = mid(ID,2,1) num3 = mid(ID,3,1) num4 = mid(ID,4,1) num5 = mid(ID,5,1) num6 = mid(ID,6,1) num7 = mid(ID,7,1) 'response.write num1 & num2 & num3 & num4 & num5 & num6 & num7 if num1 or num2 or num3..num7 having '0' randomize the number to 1-to-9 if num7 ="A" then num7 = 1 if num7 ="B" then num7 = 2 if num7 ="C" then num7 = 3 if num7 ="D" then num7 = 4 if num7 ="E" then num7 = 5 if num7 ="F" then num7 = 6 .....until Z %> |
|
#2
|
|||
|
|||
|
dim ID
ID = "024053J" randomize for i=1 to 7 num(i) = mid(ID,i,1) if asc(num(i))>=asc("A") and asc(num(i))<= asc("Z") then num(i)=1+ cint(rnd(0)*8) end if next i |
|
#3
|
|||
|
|||
|
Quote:
hi, got an Error Type: Microsoft VBScript compilation (0x800A0401) Expected end of statement /okl/index.asp, line 29, column 5 next i ----^ how can i see the output anyway for all the num1 to num7? if they are separated? because i need to use each as individual variable. thanks! |
|
#4
|
|||
|
|||
|
If you want to use them separated you can still use:
randomize If Asc(NUM1) >= Asc("A") And Asc(NUM1) <= Asc("Z") Then NUM1 = 1 + CInt(Rnd(0) * 8) If Asc(NUM2) >= Asc("A") And Asc(NUM2) <= Asc("Z") Then NUM2 = 1 + CInt(Rnd(0) * 8) If Asc(NUM3) >= Asc("A") And Asc(NUM3) <= Asc("Z") Then NUM3 = 1 + CInt(Rnd(0) * 8) If Asc(NUM4) >= Asc("A") And Asc(NUM4) <= Asc("Z") Then NUM4 = 1 + CInt(Rnd(0) * 8) If Asc(NUM5) >= Asc("A") And Asc(NUM5) <= Asc("Z") Then NUM5 = 1 + CInt(Rnd(0) * 8) If Asc(NUM6) >= Asc("A") And Asc(NUM6) <= Asc("Z") Then NUM6 = 1 + CInt(Rnd(0) * 8) If Asc(NUM7) >= Asc("A") And Asc(NUM7) <= Asc("Z") Then NUM7 = 1 + CInt(Rnd(0) * 8) or if you want reagruped as a string dim ID, i as integer, num(10) as string, ST as string ID = "024053J" randomize ST="" for i=1 to 7 num(i) = mid(ID,i,1) if asc(num(i))>=asc("A") and asc(num(i))<= asc("Z") then num(i)=1+ cint(rnd(0)*8) end if ST=ST & num(i) next i response.write ST |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > how to make this code shorter? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|