+ Post New Thread
Results 1 to 5 of 5
Coding Thread, More VB6 Help in Coding and Web Development; Can somebody tell me why this isn't working: Code: Private Sub cmdBookAdd_Click() Dim iCounter As Integer If iCounter = 0 ...
  1. #1

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    240

    More VB6 Help

    Can somebody tell me why this isn't working:

    Code:
    Private Sub cmdBookAdd_Click()
    Dim iCounter As Integer
    
    If iCounter = 0 Then
        cmdBookAdd.Caption = "Save"
        rsBook.AddNew
        SetBookText
        iCounter = 1
    Else
        cmdBookAdd.Caption = "Add"
        SetBookData
        rsBook.Update
        iCounter = 0
    End If
    End Sub
    I want it to add a new record, but it doesn't work - anything obvious?

  2. #2

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    240
    Code:
    Private Sub SetBookText()
    Dim iCounter As Integer
    
    For iCounter = 0 To 6
        'If the recordset is NOT empty then put it in the box
        If rsBook(iCounter) <> "" Then
            txtBook(iCounter).Text = rsBook(iCounter)
        'Else the text box is set to blank
        Else
            txtBook(iCounter).Text = ""
        End If
    Next iCounter
    End Sub
    Code:
    Private Sub SetBookData()
    'This function puts new data into the book table
    Dim iCounter As Integer
    For iCounter = 0 To 6
        rsBook(iCounter) = txtBook(iCounter).Text
    Next iCounter
    End Sub
    Sorry - might be useful if I include the private functions it calls.

  3. #3

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,216
    Thank Post
    2,767
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    Code:
     
    Private Sub cmdBookAdd_Click()
    Dim iCounter As Integer
    
    iCounter = 0   ' <--- This was not set to 0 to initialise it
    
    If iCounter = 0 Then
        cmdBookAdd.Caption = "Save"
        rsBook.AddNew
        SetBookText
        iCounter = 1
    Else
        cmdBookAdd.Caption = "Add"
        SetBookData
        rsBook.Update
        iCounter = 0
    End If
    End Sub
    Not sure if setting iCounter to zero to start with will help

  4. #4

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    240
    Quote Originally Posted by mac_shinobi View Post
    Code:
     
    Private Sub cmdBookAdd_Click()
    Dim iCounter As Integer
    
    iCounter = 0   ' <--- This was not set to 0 to initialise it
    
    If iCounter = 0 Then
        cmdBookAdd.Caption = "Save"
        rsBook.AddNew
        SetBookText
        iCounter = 1
    Else
        cmdBookAdd.Caption = "Add"
        SetBookData
        rsBook.Update
        iCounter = 0
    End If
    End Sub
    Not sure if setting iCounter to zero to start with will help
    No, that wasn't it - but it did prompt me to check something. I hadn't defined the variable as a static so each time it was forgetting what value it was holding. The solution was to change:

    Code:
    Dim iCounter As Integer
    to...

    Code:
    Static iCounter As Integer
    Tested it and it works fine now. Thanks

  5. #5

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,216
    Thank Post
    2,767
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    Quote Originally Posted by Hightower View Post
    No, that wasn't it - but it did prompt me to check something. I hadn't defined the variable as a static so each time it was forgetting what value it was holding. The solution was to change:

    Code:
    Dim iCounter As Integer
    to...

    Code:
    Static iCounter As Integer
    Tested it and it works fine now. Thanks
    your welcome - haven't done or used vb6 for a long time now so its a very rusty subject for me now lol
    Last edited by mac_shinobi; 27th April 2009 at 01:43 PM.

SHARE:
+ Post New Thread

Similar Threads

  1. Adding components in VB6
    By iking in forum How do you do....it?
    Replies: 1
    Last Post: 15th July 2009, 10:37 AM
  2. VB6 Properties
    By Hightower in forum Coding
    Replies: 7
    Last Post: 27th April 2009, 10:54 AM
  3. VB6 Help
    By Hightower in forum Coding
    Replies: 8
    Last Post: 18th April 2009, 02:30 PM
  4. Vb6 components on CC3
    By iking in forum Network and Classroom Management
    Replies: 2
    Last Post: 26th October 2008, 05:39 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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