Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 15th, 2005, 08:00 AM
okl okl is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: Singapore
Posts: 359 okl User rank is Private First Class (20 - 50 Reputation Level)okl User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 2 h 24 m 16 sec
Reputation Power: 4
Send a message via MSN to okl
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
%>

Reply With Quote
  #2  
Old February 15th, 2005, 10:13 AM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
Wink

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
Comments on this post
okl disagrees!

Reply With Quote
  #3  
Old February 15th, 2005, 10:20 AM
okl okl is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: Singapore
Posts: 359 okl User rank is Private First Class (20 - 50 Reputation Level)okl User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 2 h 24 m 16 sec
Reputation Power: 4
Send a message via MSN to okl
Quote:
Originally Posted by Darius
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



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!

Reply With Quote
  #4  
Old February 15th, 2005, 01:43 PM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
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

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > how to make this code shorter?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT