Nuno Posted February 28, 2014 at 12:56 PM Report #547112 Posted February 28, 2014 at 12:56 PM Boa tarde! Bem precisava de fazer o seguinte. Preciso de uma função para gerar um código de barras aleatório diferente daqueles que já existem numa base de dados. o meu problema é que na base de dados em questão existem códigos com letras e assim obtenho um erro na consulta. Alguma ideia?
mlcalves Posted February 28, 2014 at 02:04 PM Report #547115 Posted February 28, 2014 at 02:04 PM Boas. Não tenho mt experiência mas penso que podes adicionar uma coluna nessa tabela da bd, para adicionar um id numérico a todos os campos já existentes . primary key e auto increment
Nuno Posted February 28, 2014 at 02:21 PM Author Report #547116 Posted February 28, 2014 at 02:21 PM Shared Function GetRandomCode(ByVal length As Int16) As String Dim num_characters As Integer Dim i As Integer Dim txt As String = String.Empty Dim ch As Integer num_characters = 20 Randomize() For i = 1 To num_characters ch = Int((26 + 26 + 10) * Rnd()) If ch < 26 Then txt = txt & Chr(ch + Asc("A")) ElseIf ch < 2 * 26 Then ch = ch - 26 txt = txt & Chr(ch + Asc("a")) Else ch = ch - 26 - 26 txt = txt & Chr(ch + Asc("0")) End If Next i Return txt End Function Com esta funçao já funciona, depois e so fazer uma consulta na bd, caso exista mando gerar outro, caso não exista tá novo... 🙂
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now