Código De Um Produto...
#1
Posted 23/07/2003, 17:27
Deixa eu explicar o que quero...
Para o cadastramento de produtos em um site, utilizo o banco Access.
Criei uma coluna nele para o "código" ou "id" deste produto, onde o access preenche automaticamente com números aleatórios...
Gostaria de saber, se tem como este número ser criado pela própria página ASP onde estará o furmulário de cadastro.... e que esse número criado nunca se repita, para não haver complicações no banco.
Espero que me ajudem...
#2
Posted 24/07/2003, 01:20
Da sim, se vc deixar o campo como número,
A função pra gerar strings aleatórios, achei essa aqui...
' ..:: Random String Generator ::..
' By Nick Blower, Redeggs Web Design ©
' scripts@redeggs.com | www.redeggs.com
Function RndStringGen(str_lenght, str_whatcase, str_numberbias) 'define function and passed parameters
'What Case
'0=All lower case
'1=All Upper case
'2=Random Mixure
'Check validity of passed parameters
If Len(str_lenght) = 0 Or IsNumeric(str_lenght) = False Then str_lenght = 10 End If
str_lenght = CLng(str_lenght)
If str_lenght < 1 Or str_lenght > 1000 Then str_lenght = 10 End If
If Len(str_numberbias) = 0 Or IsNumeric(str_numberbias) = False Then str_numberbias = 5 End If
str_numberbias = CSng(str_numberbias)
If str_numberbias < 0 Or str_numberbias > 10 Then str_numberbias = 5 End If
str_numberbias = str_numberbias / 10 'make to value below 1 so it is of the same magnatude as the random string
'create string using a Do Loop
str_counter = 0
Do Until str_counter = str_lenght
Randomize
If rnd < str_numberbias Then 'work out which statement to do
Randomize
str_chracters = str_chracters & Chr((((57 - 48) * rnd) + 48)) 'numeric characters
Else
Randomize
str_chracters = str_chracters & Chr((((122 - 97) * rnd) + 97)) 'alpha characters
End If
str_counter = CInt(str_counter) + 1
Loop
'-------------------------------------------------
If str_whatcase = 1 Then 'make all alpha characters upper case
str_chracters_final = UCase(str_chracters)
ElseIf str_whatcase = 2 Then 'random chance of upper case / lower case
For i = 1 to Len(str_chracters)
j = Mid(str_chracters, i, 1) 'next character in the string
Randomize
If rnd < 0.5 Then '50% change of being each case - ignored if not alpha
j = UCase(j)
Else
j = LCase(j)
End If
str_chracters_mixed = str_chracters_mixed & j 'add the character to the string
Next
str_chracters_final = str_chracters_mixed
Else 'default action - Lower case
str_chracters_final = LCase(str_chracters)
End If
RndStringGen = str_chracters_final
End Function
Examples:
RndStringGen(10, 0, 5) = String 10 characters long, lower case, 50% alpha, 50% numeric
RndStringGen(100, 1, 8) = String 100 characters long, upper case, 20% aplha, 80% numeric
RndStringGen(1, 2, 0) = String 1 character long, random mixed case, 100% aplha, 0% numeric
RndStringGen(10, 0, 10) = String 10 characters long, lower case, 0% aplha, 100% numeric
Use o código em vermelho para chamar a função, os outros são exemplos...!
Se vc precisar ajuda pra inserir o código no bd, posta ae no fórum.....
Falow ae....
#3
Posted 24/07/2003, 12:39
No meu formulário de cadastro vou colocar um campo oculto onde estará o id dele (que a própria página já criou).
Mas nenhum número poderá se repetir, para não ficar mais de um produto com o mesmo número...
#4
Posted 24/07/2003, 12:40
#5
Posted 25/07/2003, 01:05
mas pq vc naum usa autonumeração normal, tipo não aleatorio?
0 user(s) are reading this topic
0 membro(s), 0 visitante(s) e 0 membros anônimo(s)