Results 1 to 20 of 20

Thread: [RESOLVED] load limited times

  1. #1

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Resolved [RESOLVED] load limited times

    Hi! i was wondering if i can put a limit on how many times my main form is loaded. after it has been loaded 10 or how many every times i would like it to call this form.
    Thanks
    VB Code:
    1. Private Sub Command1_Click()
    2. If Text1.Text = "11" Or Text2.Text = "11" Then
    3. 'Save the text inside the textboxes
    4. SaveSetting "MyApp", "General", "User", Text1.Text
    5. SaveSetting "MyApp", "General", "User2", Text2.Text
    6. MsgBox "Thanks for Registering!", vbExclamation, "Register"
    7. 'Unload Form
    8. Unload Me
    9. Else
    10. MsgBox "Arrr... Wrong. Try again.", vbInformation, "Register"
    11. Text1.SetFocus
    12. End If
    13. End Sub
    14.  
    15. Private Sub Command2_Click()
    16. 'Get rid of all text
    17. Text2.Text = ""
    18. Text1.Text = ""
    19. SaveSetting "MyApp", "General", "User2", Text2.Text
    20. SaveSetting "MyApp", "General", "User", Text1.Text
    21. 'Reset the Register
    22. Hidden.Text = "d"
    23. SaveSetting "MyApp", "General", "Reset", Hidden.Text
    24. 'Unload form
    25. Unload Me
    26. End Sub
    27.  
    28. Private Sub Command3_Click()
    29. MsgBox "Sample on How to Make a Registration Form For Your Programme" & _
    30. vbCrLf & "By Reynard Chan, Age 12" & _
    31. vbCrLf & "Made with Visual Basic 6" & _
    32. vbCrLf & "Located at: www.planet-source-code.com/vb/" & _
    33. vbCrLf & "Please send comments at that site or: [email]@dbzfreak.cjb.net[/email]", vbInformation, "Register Sample"
    34. End Sub
    35.  
    36. Private Sub Form_Load()
    37. 'Check if reseted
    38. Hidden.Text = GetSetting("MyApp", "General", "Reset", Hidden.Text)
    39. 'Check if registered or not.
    40. Text2.Text = GetSetting("MyApp", "General", "User2", Text2.Text)
    41. Text1.Text = GetSetting("MyApp", "General", "User", Text1.Text)
    42. If Text1.Text = "Reynard Chan" Or Text2.Text = "ED23498-28" Then
    43. MsgBox "You've registered the programme! Woopee! ", vbInformation, "Registered!"
    44. Else
    45. MsgBox "Please register this programme now", vbExclamation, "Unregistered"
    46. End If
    47. End Sub
    Last edited by bammoeller; May 23rd, 2006 at 11:34 AM.

  2. #2

  3. #3

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: load limited times

    Correct after limit is up i want it to load the form above
    Thanks

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: load limited times

    Create a Sub Main in a code module and make Sub Main the Startup Object. Then every time the program is run use GetSetting and SaveSetting to keep a count of the number of runs and if it's > 10 the load your alternate form from Sub Main, otherwise load your main form from Sub Main.

    To guard against someone using RegEdit to decrement the run count, you should store the value encrypted and also have code that says "If there is no registry entry (because it's been deleted) load the alternate form

  5. #5

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: load limited times

    if you have the time could you give me an example of what you are saying thanks martin

  6. #6

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: load limited times

    I guess this will work Thanks
    VB Code:
    1. retvalue = GetSetting("A", "0", "RunCount")
    2.     Activate$ = Val(retvalue) + 1
    3.     SaveSetting "A", "0", "RunCount",Activate$
    4.  
    5.  
    6.     If Activate$ < 20 Then
    7.        
    8.     End If
    9.  
    10.    
    11.     If Activate$ > 19 Then
    12.        
    13.         Call Command1_Click
    14.        
    15.      
    16.     End If

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: load limited times

    I would change your code a little as shown. The check for zero handles the case where someone has deleted the Registry entry.
    VB Code:
    1. Dim retvalue As Integer
    2.  
    3. retvalue = GetSetting("A", "0", "RunCount",[HL="#FFFF80"]0[/HL])
    4.     Activate$ = retvalue + 1
    5.     SaveSetting "A", "0", "RunCount",Activate$
    6.  
    7.  
    8.     If Activate$ < 20 Then
    9.        
    10.     End If
    11.  
    12.    
    13.     If Activate$ > 19 [HL="#FFFF80"]Or Activate$ = 0[/HL] Then
    14.        
    15.         Call Command1_Click
    16.        
    17.      
    18.     End If

  8. #8

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: load limited times

    Thanks for the tip! after the limit is reached it calls this source
    VB Code:
    1. Private Sub Command1_Click()
    2. If Text1.Text = "username" Or Text2.Text = "activation code" Then
    3. 'Save the text inside the textboxes
    4. SaveSetting "MyApp", "General", "User", Text1.Text
    5. SaveSetting "MyApp", "General", "User2", Text2.Text
    6. MsgBox "Thanks for Registering!", vbExclamation, "Register"
    7. 'Unload Form
    8. Unload Me
    9. Else
    10. MsgBox "Arrr... Wrong. Try again.", vbInformation, "Register"
    11. Text1.SetFocus
    12. End If
    13. End Sub

    how can i make it to where you only have to register it one time? The issue is the register this product form will come up everytime the software is loaded, even after the software has been registered. could you enlightened on how i can get around this?
    Thanks for your fast replys

  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: load limited times

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim strRegistered As String
    3.  
    4. strRegistered = GetSetting("MyApp", "General","Registered","No"
    5. If strRegistered = "Yes" Then
    6.     Exit Sub
    7. End If
    8. SaveSetting("MyApp", "General","Registered","Yes"
    9.  
    10. If Text1.Text = "username" Or Text2.Text = "activation code" Then
    11. 'Save the text inside the textboxes
    12. SaveSetting "MyApp", "General", "User", Text1.Text
    13. SaveSetting "MyApp", "General", "User2", Text2.Text
    14. MsgBox "Thanks for Registering!", vbExclamation, "Register"
    15. 'Unload Form
    16. Unload Me
    17. Else
    18. MsgBox "Arrr... Wrong. Try again.", vbInformation, "Register"
    19. Text1.SetFocus
    20. End If
    21. End Sub

  10. #10

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: load limited times

    Thanks for the help! wonder why it errors? Thanks
    VB Code:
    1. Dim strRegistered As String
    2.  
    3.  ' this line strRegistered = GetSetting("MyApp", "General","Registered","No"
    4. If strRegistered = "Yes" Then
    5.     Exit Sub
    6. End If
    7. ' this line SaveSetting("MyApp", "General","Registered","Yes"
    8.  
    9. If Text1.Text = "username" Or Text2.Text = "activation code" Then
    10. 'Save the text inside the textboxes
    11. SaveSetting "MyApp", "General", "User", Text1.Text
    12. SaveSetting "MyApp", "General", "User2", Text2.Text
    13. MsgBox "Thanks for Registering!", vbExclamation, "Register"
    14. 'Unload Form
    15. Unload Me
    16. Else
    17. MsgBox "Arrr... Wrong. Try again.", vbInformation, "Register"
    18. Text1.SetFocus

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: load limited times

    Quote Originally Posted by bammoeller
    Thanks for the help! wonder why it errors?
    What is the error and on what line is it occuring?

  12. #12

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: load limited times

    ' this line SaveSetting("MyApp", "General","Registered","Yes"
    ' this line strRegistered = GetSetting("MyApp", "General","Registered","No"
    The lines are red
    Thanks for the super fast responce hack

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: load limited times

    Are you talking about the lines that you have commented out?

  14. #14
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: load limited times

    Somehow the closing parenthesis ")" at the end of each line was left off so it should be

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim strRegistered As String
    3.  
    4. strRegistered = GetSetting("MyApp", "General","Registered","No"[HL="#FFFF80"])[/HL]
    5. If strRegistered = "Yes" Then
    6.     Exit Sub
    7. End If
    8. SaveSetting("MyApp", "General","Registered","Yes"[HL="#FFFF80"])[/HL]
    9.  
    10. If Text1.Text = "username" Or Text2.Text = "activation code" Then
    11. 'Save the text inside the textboxes
    12. SaveSetting "MyApp", "General", "User", Text1.Text
    13. SaveSetting "MyApp", "General", "User2", Text2.Text
    14. MsgBox "Thanks for Registering!", vbExclamation, "Register"
    15. 'Unload Form
    16. Unload Me
    17. Else
    18. MsgBox "Arrr... Wrong. Try again.", vbInformation, "Register"
    19. Text1.SetFocus
    20. End If
    21. End Sub

  15. #15

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: load limited times

    oh ok thanks Martin and hack

  16. #16

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: load limited times

    VB Code:
    1. Dim strRegistered As String
    2.  
    3. strRegistered = GetSetting("MyApp", "General","Registered","No")
    4. If strRegistered = "Yes" Then
    5.     Exit Sub
    6. End If
    7. [COLOR=Red]SaveSetting("MyApp", "General","Registered","Yes")
    8. [/COLOR]
    9. If Text1.Text = "username" Or Text2.Text = "activation code" Then
    10. 'Save the text inside the textboxes
    11. SaveSetting "MyApp", "General", "User", Text1.Text
    12. SaveSetting "MyApp", "General", "User2", Text2.Text
    13. MsgBox "Thanks for Registering!", vbExclamation, "Register"
    14. 'Unload Form
    15. Unload Me
    16. Else
    17. MsgBox "Arrr... Wrong. Try again.", vbInformation, "Register"
    18. Text1.SetFocus
    19. End If
    I dunno its still fire red lol

  17. #17
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: load limited times

    GetSetting requires parentheses, SaveSetting does not. This should work (and display) just fine
    VB Code:
    1. SaveSetting "MyApp", "General", "Registered", "Yes"

  18. #18

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: load limited times

    Thanks!!!!

  19. #19

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: load limited times

    Shucks now it does absolutely nothing when i click on the command button
    VB Code:
    1. Dim strRegistered As String
    2.  
    3. strRegistered = GetSetting("MyApp", "General", "Registered", "No")
    4. If strRegistered = "Yes" Then
    5.     Exit Sub
    6. End If
    7. SaveSetting "MyApp", "General", "Registered", "Yes"
    8. If Text1.Text = "1" Or Text2.Text = "1" Then
    9. 'Save the text inside the textboxes
    10. SaveSetting "MyApp", "General", "User", Text1.Text
    11. SaveSetting "MyApp", "General", "User2", Text2.Text
    12. MsgBox "Thanks for Registering!", vbExclamation, "Register"
    13. 'Unload Form
    14. Unload Me
    15. Else
    16. MsgBox "Arrr... Wrong. Try again.", vbInformation, "Register"
    17. Text1.SetFocus
    18. End If

  20. #20
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] load limited times

    Put a break on it and step through to see what it is doing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width