Go Back   Gaming Gutter


» Site Navigation
» Home
» FAQ
» Log in
User Name:

Password:

Not a member yet?
Register Now!
» Advertisement
» Recent Threads
Go to first new post umm... can i post this?!?
01-05-2009 06:38 PM
Last post by wtfwtfwtg
Today 09:35 PM
5 Replies, 49 Views
Go to first new post Lots of WN Painted /...
Today 07:33 PM
by donovan
Last post by jsndin
Today 09:35 PM
4 Replies, 16 Views
Go to first new post Bronze or Brains?
Today 09:30 PM
by KenK
Last post by Unregenerate Passion
Today 09:33 PM
1 Replies, 2 Views
Go to first new post [Guide] How to use NQII...
Yesterday 11:11 PM
by spyrox
Last post by spyrox
Today 09:28 PM
9 Replies, 106 Views
Go to first new post New 9/11? Different...
Today 09:13 PM
Last post by Hallandale
Today 09:27 PM
4 Replies, 17 Views
View Single Post

 
Old 12-05-2007, 06:41 PM   #9 (permalink)
PhearAlmighty
Full Member

PhearAlmighty is offline
 
Join Date: Nov 2007
Posts: 21
GPoints: 79
iTrader: 0 / 0%
PhearAlmighty Is gaining popularity
Rep Power: 0
Quote:
Originally Posted by rcadble View Post
Why not make it in complete function form? You should try make it a function where your user can just input the settings (as it is now, you'd have to make a new function every time you wanted to change the length).

Code:
Public Function GenerateCodeRcad(ByVal lngLength As Integer) As String
    Dim i As Integer
    Dim strRand As String
    Dim intRand As Integer
        Randomize
        For i = 0 To lngLength Step 1
            intRand = Int(Math.Rnd() * 3) + 1
            If intRand = 1 Then
                strRand = strRand & Int(Math.Rnd() * 10)
            ElseIf intRand = 2 Then
                strRand = strRand & Chr(Int(Math.Rnd() * (26) + 65))
            ElseIf intRand = 3 Then
                strRand = strRand & Chr(Int(Math.Rnd() * (26) + 97))
            End If
        Next
        GenerateCodeRcad = strRand
End Function
Unfortunately, the mid function is pretty slow for vb6, so using chr() with random ascii values would speed it up. (Mine averaged 0.93 microseconds faster, by testing them both 100,000 times).

rcadble:
your code generates one extra character

Code:
Public Function GenerateCodeRcad(ByVal lngLength As Integer) As String
    Dim i As Integer
    Dim strRand As String
    Dim intRand As Integer
        Randomize
        lnglenth = lnglenth - 1
        For i = 0 To lngLength Step 1
            intRand = Int(Math.Rnd() * 3) + 1
            If intRand = 1 Then
                strRand = strRand & Int(Math.Rnd() * 10)
            ElseIf intRand = 2 Then
                strRand = strRand & Chr(Int(Math.Rnd() * (26) + 65))
            ElseIf intRand = 3 Then
                strRand = strRand & Chr(Int(Math.Rnd() * (26) + 97))
            End If
        Next
        GenerateCodeRcad = strRand
End Function
  Reply With Quote
 
Powered by vBadvanced CMPS v3.1.0

All times are GMT -7. The time now is 09:37 PM.


vBulletin skin developed by: eXtremepixels
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The contents of this webpage are copyright © 2006-2008 GamingGutter.com. All Rights Reserved.

Page generated in 0.17243004 seconds (100.00% PHP - 0% MySQL) with 17 queries