Click here to Skip to main content
13,046,281 members (115,281 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I have a problem. I have been programming an activation type of security protection for my

software but i ran into problems when i try to generate an alphanumeric key with

conditions. i cant seem to be able to make the keys to be valid with the condition.

Basically i can get the 25 keys but all of them seem to be returning 1 (ones) instead of 0

(zero which what i want. below is my sample code may be someone can tell me what i am doing

wrong, by the way i did google, woogle,bing, bang, yahoo, yadoo etc but no go.

code: generate the keys

Public Function GenerateCode() As Object
        Dim IntRnd As Object
        Dim IntStep As Object
        Dim StrName As Object
        Dim IntNameLength As Object
        Dim IntLength As Object
        Dim StrInputString As Object

      'set the char needed
     IntLength = Len(StrInputString)
'set the length
   IntNameLength = 25
   StrName = ""
    For IntStep = 1 To IntNameLength
            IntRnd = Int((IntLength * Rnd()) + 1)
            StrName = StrName & Mid(StrInputString, IntRnd, 1)
        Return StrName
    End Function

code: here where i put the condition and here where it giving me hell

Public Function GetPID()
        Dim pid As String = String.Empty
        Dim digitalPid As Byte()
        Dim sequenceNumber As Integer = 0
        Dim upgradeFlag As Boolean = False
        Dim isOem As Boolean = False
        Dim oemID As String = Nothing
        Dim builder As New StringBuilder(&H18, &H18)
        digitalPid = New Byte(&H100 - 1) {}
        Buffer.BlockCopy(BitConverter.GetBytes(digitalPid.Length), 0, digitalPid, 0, 4)
        Dim num As Integer
 dim key as string 
redo1: key = generatecode()
        num = setcon(key, con1, con2)
if num = 0 then
return key 
goto redo1:
end if
      End Function
the damn thing keeps returning 1 instead of 0. I do know i can simply change to 1 and be

off the issue. but if is that easy to generate 1 then isnt it easy just to break it. oh yeah

the whole thing hangs when i generate the code???
if i loop it, its able to get a 0 but i cant take the key thats in the loop??
any idea or comment is much appreciated, i do not need the coding just the logic should do,

i should be able to find my way around...
Posted 25-Sep-11 1:54am
SAKryukov 25-Sep-11 12:12pm
What is that return value 0 or 1?
theonebit 26-Sep-11 0:24am
when i loop such as

Collapse | Copy Code
do until num = 0
key = generatecode()
num = setcon(key, con1, con2)

return num

i will get a zero but i need the key to that zero num?
how do i get the key

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 25 Sep 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100