Results 1 to 11 of 11

Thread: Moving VB6 code from module to form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Location
    UK
    Posts
    93

    Resolved Moving VB6 code from module to form

    Hello

    Quick question...

    I am trying to move this code from a module to my form, but as soon as I change the frmAverage to Average - I get the message Compile error invalid qualifier. I have a public variable of Average declared in my module so can you tell me what I'm doing wrong?

    Private Sub cmdOperation_Click(Index As Integer)
    Select Case Index
    Case 0 'The TOTAL button
    txtNumber(3).Visible = True 'Place the text box in the right place
    txtNumber(3).Top = cmdOperation(Index).Top
    txtNumber(3).Text = Str(TotalNumber) 'The module function call
    Case 1 ' The AVERAGE button
    txtNumber(3).Visible = True 'Place the text box in the right place
    txtNumber(3).Top = cmdOperation(Index).Top
    txtNumber(3).Text = Str(AverageValue) 'The module function call
    Case 2 'The SORT button
    txtNumber(3).Visible = False
    SortNumbers
    For i = 1 To 3
    frmAverage.txtNumber(i - 1) = Str(Number(i))
    Next


    Case 3 'The CLOSE button
    End 'To end the application
    End Select
    End Sub

    Thanks for your help......

    Tracey
    Last edited by Tazmania; Apr 23rd, 2006 at 03:46 PM. Reason: Resolved

  2. #2
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: Moving VB6 code from module to form

    I think you need to rename the line of your code below as Average rather than using frmAverage. Just try

    VB Code:
    1. frmAverage.txtNumber(i - 1) = Str(Number(i))

  3. #3

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Location
    UK
    Posts
    93

    Re: Moving VB6 code from module to form

    This is for a VB6 course I am doing and it is in the instructions.....

    I tried changing tit to Average but it did not like it which is why I raised the post. The error I got when trying to do this was compile error invalid qualifier.

    Where am I going wrong?

    Thanks
    Last edited by Tazmania; Apr 23rd, 2006 at 08:26 AM. Reason: correcting

  5. #5

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Location
    UK
    Posts
    93

    Re: Moving VB6 code from module to form

    The title highlighted is:
    Private Sub cmdOperation_Click(Index As Integer) along with the word - average

  7. #7

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Location
    UK
    Posts
    93

    Re: Moving VB6 code from module to form

    Hi Marty

    I changed the code from :

    Private Sub cmdOperation_Click(Index As Integer)
    Select Case Index
    Case 0 'The TOTAL button
    txtNumber(3).Visible = True 'Place the text box in the right place
    txtNumber(3).Top = cmdOperation(Index).Top
    txtNumber(3).Text = Str(TotalNumber) 'The module function call
    Case 1 ' The AVERAGE button
    txtNumber(3).Visible = True 'Place the text box in the right place
    txtNumber(3).Top = cmdOperation(Index).Top
    txtNumber(3).Text = Str(AverageValue) 'The module function call
    Case 2 'The SORT button
    txtNumber(3).Visible = False
    SortNumbers
    For i = 1 To 3
    frmAverage.txtNumber(i - 1) = Str(Number(i))
    Next


    Case 3 'The CLOSE button
    End 'To end the application
    End Select
    End Sub

    to

    Private Sub cmdOperation_Click(Index As Integer)
    Select Case Index
    Case 0 'The TOTAL button
    txtNumber(3).Visible = True 'Place the text box in the right place
    txtNumber(3).Top = cmdOperation(Index).Top
    txtNumber(3).Text = Str(TotalNumber) 'The module function call
    Case 1 ' The AVERAGE button
    txtNumber(3).Visible = True 'Place the text box in the right place
    txtNumber(3).Top = cmdOperation(Index).Top
    txtNumber(3).Text = Str(AverageValue) 'The module function call
    Case 2 'The SORT button
    txtNumber(3).Visible = False
    SortNumbers
    For i = 1 To 3
    Average.txtNumber(i - 1) = Str(Number(i))
    Next


    Case 3 'The CLOSE button
    End 'To end the application
    End Select
    End Sub

    In the course work I have I was told to move some code from the module to the form and remove the form reference which I thought was the frmAverage code but when changing the code from frmaverage to Average, I then got the compile error.

    Is what i was trying to do wrong?

    The code I moved fromt he module to the form was

    For i = 1 To 3
    frmAverage.txtNumber(i - 1) = Str(Number(i))
    Next

    Thanks

    Tracey

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

    Re: Moving VB6 code from module to form

    Oh, I think I see. Are you under the impression that "frm" is a reference to a form and because of that you simply removed "frm" when you moved the code? In any case frmAverage is the name of the form and when you had the code in the module you wanted to refer to the textbox on that form you so had to tell VB where the textbox is by prepending the name of the form and doing frmAverage.txtNumber. Once the code is moved to frmaverage you don't need to tell VB where the code is (since it assumes the current module) so all you need to do is...

    VB Code:
    1. For i = 1 To 3
    2.    txtNumber(i - 1) = Str(Number(i))
    3. Next

    BTW if you surround your code with vbcode tags it will be easier for us to read.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Location
    UK
    Posts
    93

    Re: Moving VB6 code from module to form

    THanks Marty

    Thats excellent - will do in future.

    Have a good day.

    tracey

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

    Re: Moving VB6 code from module to form

    Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer.

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