ҡդӶ ʵŧ 纺촨շ٨絴͵ ᷹ФѺ

͵Դҷҧ Inbox Ѻ

˹ѡ
-
VB 6/VB.Net
ASP/ASP.Net
Ѻ¤
¹ҹ Flash Movie
ռͺش  
 RSS Feeds
 ǹŴ RSS Reader ...   Download  RSS Reader

Forum - www.g2gnet.com
Webmaster - www.g2gnet.com
Visitors - Session views
 5 6 1 6 0 8 4

7 ѹҤ ..2549
37 Users On-Line.
Visitors - Page views
 8 9 7 3 8 2 7
1 Ҿѹ ..2551

Google   
g2gnet.com
Ҵѡ:  

ᨡ ASP Script ѺŢѵûЪҪ

Category »  ASP/ASP.Net
: Webmaster 13/11/2553   : 17:42
(ҹ : 16150) 
ҧ¨ҡ¹ǡѺ ASP Script 繻· ... ͹͡¹ѡ ͧʹ͡§ѧꧡѹ· 55555+ ... ´ٵ¹ Script ... Ӥѭ ѵûЪҪѹѨغѹ ѡáŢ 0 Ţ 9 ˹ҹФѺ ... ѧѡ еͧŢ੾ѡá͡ҡ͹ ǹͺҼŷŢ 0 Ţ 9 ֧ŢǷ 2 - 12 ... ش¤͡äӹdzѡ 13 ѡǨͺ١ͧ (Check Digit) ... (˵: ѡ褹Ŵ ASP Script ͧ ǹ˭ PHP ѹ駹 ... ǹǼͧ ѧ繢ҷѺ෤ռѵͧ硹 - Microsoft 仵ʹŹҹ)
öͺҹ䫵觹 ...
ǹŴ ASP Script ŢѵûЪҪ

ᨡ Source Code ŢѵûЪҪ (VB6)
Source Code õǨͺŢѵûЪҪ (VB6 + VB.Net)
Ҵ Script ѹ ...

<%
' ¡ѧѧ㹡ŢѵûЪҪ·ѹ
Call RandomNumber
%>
<h1>ASP Script ŢѵûЪҪ - www.g2gnet.com</h1>
<form name="frmRandom" method="post" action="">
<% Response.Write RandomNumber %>  
<input type="submit" name="cmdRandom" id="cmdRandom" 
value="ŢѵûЪҪ" onClick="Call RandomNumber()">
</form>

<%
' ########################################################
Function RandomNumber
' ########################################################
    
    ' 㹡Ţ͹
    Randomize
    
    ' ٵáŢ  High = ٧ش  Low = ҵش
    'RandomNumber = Int((High - Low + 1) * Rnd) + Low
    
    ' 駤 False ͹
    blnFlag = False
    
    ' Ţӹǹ 12 ѡ ·ѡáͧ 0  9
    ' ͧҡùѺ鹨ҡ 1 ش 12 դ鹷 1  For
    For i = 1 To 12
        ' Not False  ԧ   (¹ blnFlag = False) ... 
        ' ʴҵ͹ҡѧҵŢѡá
        If Not blnFlag Then
            ' Ţѡá ͧդ 0  9 ... ͡÷ӫ  Repetitive
            ' ǹͺ (Loop) Ẻ For Ѻҹ 
            '  ش   (Ŵ)
            ' ѹ͹ѹФѺ ѹդ͡ҡ Loop  Exit For 
            Do
                
                ' ҵŢ 0 - 9 ... ҡ 0  9 ͧŢ
                RandomNumber = Int((9 + 1) * Rnd)
                
            ' ӨѡáͧҡѺ 0  9 (͹䢵ͧ AND)
            '   RandomNumber դ = 1
            ' ͹ 1 <> 0  1 <> 9 (True AND True = True) 
            ' ͹ "ԧ" ͡ҡ Loop
            
            '   RandomNumber դ = 9
            ' ͹ 9 <> 0  9 <> 9 (True AND False = False)
            ' ͹ "" ǹ Loop 
            Loop Until RandomNumber <> 0 And RandomNumber <> 9
            
            '  ͹ Until Ѻѹ Not
            'Loop Until Not RandomNumber = 0 And Not RandomNumber = 9
            
            '  While ͹䢵ͧѺѹѺẺ Until еͧ OR ᷹
            '   RandomNumber դ = 1
            ' ͹ 1 = 0  1 = 9 (False OR False = False)
            ' ͹ "" ͡ҡ Loop
            
            '   RandomNumber դ = 9
            ' ͹ 9 = 0  9 = 9 (False OR True = True)
            ' ͹ "ԧ" ǹ Loop 
            'Loop While RandomNumber = 0 Or RandomNumber = 9
            
            ' ѡáҵŢ 0  9 ó 
            ' ѡ仨ͧ Do Loop ա
            blnFlag = True
			
            ' Flag ǹ¹ False ҵŢѡ
            blnCheck = True
			
        End If

        ' ҡ blnFlag 繨ԧ  blnCheck 繨ԧ ʴҾش͡ҡ Loop Do While
        If blnFlag And blnCheck Then
            ' ҡѡ 2 - 12 ͧѺǹա ŧ价ӷ Else 
            blnCheck = True
        Else
            RandomNumber = RandomNumber & Int((9 + 1) * Rnd)
        End If
		
    Next

    ' ########################################################
    ' 鹤ӹdzҤҼŢ 12 ѡá ѧ
    ' Ҽѡ 1 仨֧ѡ 12 (Ѻҡ仢)
    ' ѡ 1 ٳ¹˹ѡШѡ = 13
    ' ѡ 2 ٳ¹˹ѡШѡ = 12
    ' ѡ 3 ٳ¹˹ѡШѡ = 11
    ' ѡ .. ٳ¹˹ѡШѡ = ..
    ' ѡ 12 ٳ¹˹ѡШѡ = 2
    ' ҡ鹹Ӽšäٳͧѡѹ

    ' ѡѡ  Mid(RandomNumber, Count, 1))
    ' ˹ѡͧѡ  (14 - Count)  Count 鹨ҡ 1 ش 12
    ' ѧ鹤ҹ (14 - Count) ֧鹤Ҩҡ 13, 12, 11, ..., ش 2 Ѻ
    Sum = 0 ' Clear Ҽ͹ (ͤ)
    For Count = 1 To 12
        Sum = Sum + Mid(RandomNumber, Count, 1) * (14 - Count)
    Next

    ' ########################################################
    ' 鹵͹  Ҥ Check Digit  ѡǨͺ١ͧ (ѡ 13)
    ' Ӽ (Sum)  Mod ()  11 
    ' 蹤ͤҷҨ 0, 1, 2, .. , 10 (Sum Mod 11)
    ' ҡź͡ 11 зҵ 1, 2, 3, ... , 11 (11 - (Sum Mod 11))
    ' ͡Ǣش˹觵 ¤ Right$ --> Right$(Str(11 - (Sum Mod 11)), 1)
    ' ش¹ ѡ 13  ѡǨͺ١ͧ (Check Digit) ͧ
    CheckDigit = Right(11 - (Sum Mod 11), 1)
    ' ########################################################
    
    ' ########################################################
    ' ҤҨѴ§͹㹡Ѥ ... 55555+
    '
    RandomNumber = RandomNumber & CheckDigit
    '
    ' ########################################################

End Function
%>

Conclusion:
¡ VB ѹҤѹѺ ASP ¡ 觼ҹѺҹ Tag ͧ HTML (ФѺ) 觨з ASP Script ҧҡѡ ... Ѻ ASP Script ҹ (RandomNumber) ѹ¹仨ҡͧ VB6 ... Ӥѭҡش繨ͧͧ Algorithm ҡ ѹ¹ŧ仵 ͧͷҹ¤Ѻ ... ͧ

͵ - g2gNet Dot Com
Ţ¹ҳԪ硷͹ԡ 0407314800231
CopyLeft © 2004 - 2099 g2gNet.Com All rights reserved.
Email: [email protected] . 08-6862-6560