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
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:
frmAverage.txtNumber(i - 1) = Str(Number(i))
Re: Moving VB6 code from module to form
Normally it's better to have code in a code module rather than a form. Why do you want to move the code?
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
Re: Moving VB6 code from module to form
Which line gives the error?
Re: Moving VB6 code from module to form
The title highlighted is:
Private Sub cmdOperation_Click(Index As Integer) along with the word - average
Re: Moving VB6 code from module to form
I'm confused. I don't see the word "average" anyplace in post #1 except for a comment.
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
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:
For i = 1 To 3
txtNumber(i - 1) = Str(Number(i))
Next
BTW if you surround your code with vbcode tags it will be easier for us to read.
Re: Moving VB6 code from module to form
THanks Marty
Thats excellent - will do in future.
Have a good day.
tracey
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.