|
-
Apr 13th, 2007, 11:09 PM
#1
Thread Starter
Lively Member
[RESOLVED] What am I missing?
I am currently taking VB.net classes at school. I have an assignment due soon. I feel like I have all the code. But I am missing something. Sould I get a little help as to what I am missing? The problem that I am having is that I can't get my data from the main form to the summary form. It keeps saying that I have not declared the value. But if you notice on my main form, I have declared them as "Friend" which should make it possible to cross forms. Am I not correct?
Please advise. Thanks
Here is my main form code.
Code:
'Program Name: Test Taster
'Programmer: Daniel Davis
'Date: March 2007
'Description: This is a program created to run a taste test to see which drink take the best.
Public Class newtester
'Declare value
Friend ttesters As Decimal
Friend appleamount As Decimal
Friend pruneamount As Decimal
Friend appleaverage As Decimal
Friend pruneaverage As Decimal
Friend applerate As Decimal
Friend prunerate As Decimal
Friend winner As String
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Hide()
taste.Show()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' testers
ttesters += 1
'Apple Test
With Me
Try
'apple interger
applerate = Decimal.Parse(.TextBox1.Text)
If applerate < 10 Then
appleamount += applerate
appleaverage = appleamount \ ttesters
End If
'catch errors for apple
Catch TextEX As FormatException
MessageBox.Show("Must have a number between 1 and 10.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
With .TextBox1
.Focus()
.SelectAll()
End With
End Try
End With
'Prune Test
With Me
Try
'prune interger
prunerate = Decimal.Parse(.TextBox2.Text)
If prunerate < 10 Then
pruneamount += prunerate
pruneaverage = pruneamount \ ttesters
End If
'catch errors for prune
Catch TextEX As FormatException
MessageBox.Show("Must have a number between 1 and 10.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
With .TextBox1
.Focus()
.SelectAll()
End With
End Try
'winner
If appleaverage = pruneaverage Then
winner = "Both"
ElseIf appleaverage > pruneaverage Then
winner = "appleaverage"
Else
winner = "Pruneaverage"
End If
'clear boxes
.TextBox1.Clear()
.TextBox2.Clear()
.TextBox1.Focus()
End With
End Sub
End Class
Here is my summary form.
Code:
Public Class summary
Dim ttesters As Decimal
Dim appleaverage As Decimal
Dim pruneaverage As Decimal
Dim winner As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'get date from newtester form
With Me
'number of tasters
.TextBox1.Text = ttesters.newtester.tostring("D")
'average apples
.TextBox2.Text = appleaverage.newtester.tostring("D")
'average prunes
.TextBox3.Text = pruneaverage.newtester.tostring("D")
'winners
.TextBox4.Text = winner.newtester.tostring()
End With
End Sub
End Class
-
Apr 14th, 2007, 02:11 AM
#2
Hyperactive Member
Re: What am I missing?
Well you have declared the same variables in each form, this isn't required and can also be very confusing.
Next to get the values from your main form into your summary form you need to refer to the class that holds them in this case 'newtester'.
vb Code:
TextBox1.text = newtester.winner
Last edited by Tinbeard; Apr 14th, 2007 at 08:58 AM.
If my post helps , please feel free to rate it 
-
Apr 14th, 2007, 02:36 PM
#3
Thread Starter
Lively Member
Re: What am I missing?
Awww I see what I done. I had them backards. Thanks for the input. This is a great site.
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
|