|
-
Apr 22nd, 2006, 08:56 AM
#1
Thread Starter
Lively Member
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
-
Apr 22nd, 2006, 10:05 AM
#2
Hyperactive Member
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))
-
Apr 22nd, 2006, 10:42 AM
#3
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?
-
Apr 23rd, 2006, 08:21 AM
#4
Thread Starter
Lively Member
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
-
Apr 23rd, 2006, 11:18 AM
#5
Re: Moving VB6 code from module to form
Which line gives the error?
-
Apr 23rd, 2006, 01:42 PM
#6
Thread Starter
Lively Member
Re: Moving VB6 code from module to form
The title highlighted is:
Private Sub cmdOperation_Click(Index As Integer) along with the word - average
-
Apr 23rd, 2006, 01:45 PM
#7
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.
-
Apr 23rd, 2006, 02:31 PM
#8
Thread Starter
Lively Member
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
-
Apr 23rd, 2006, 02:43 PM
#9
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.
-
Apr 23rd, 2006, 02:51 PM
#10
Thread Starter
Lively Member
Re: Moving VB6 code from module to form
THanks Marty
Thats excellent - will do in future.
Have a good day.
tracey
-
Apr 23rd, 2006, 02:54 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|