9 Replies - 1024 Views - Last Post: 12 March 2012 - 07:35 AM Rate Topic: -----

#1 ekb9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 11-March 12

miles per gallon gui problem

Posted 11 March 2012 - 02:18 PM

I need to make a miles per gallon gui. I copied the errors that I am getting so far:

Error 3 'Cal' is not declared. It may be inaccessible due to its protection level. C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 9 9 WindowsApplication1

Error 1 'gallon' is already declared as 'Friend WithEvents gallon As System.Windows.Forms.Label' in this class. C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 2 9 WindowsApplication1

Error 2 'total' is already declared as 'Friend WithEvents total As System.Windows.Forms.Label' in this class. C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 3 9 WindowsApplication1

Error 6 Statement is not valid in a namespace. C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 22 1 WindowsApplication1


I do not understand what I am doing wrong. Help is appreciated






Public Class Form1
    Dim gallon As Double ' total gallons
    Dim total As Decimal ' total price gallons times grade price
    Dim regular As Decimal = 2.69
    Dim special As Decimal = 2.79
    Dim super As Decimal = 2.89

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Cal(Val(TextBox1.Text), Val(TextBox2.Text), 0)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Cal(Val(TextBox1.Text), Val(TextBox2.Text), 1)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Cal(Val(TextBox1.Text), Val(TextBox2.Text), 2)
    End Sub
End Class


Private Sub Cal(ByVal num1 As Integer, ByVal num2 As Integer, ByVal ops As Integer)



    Select Case ops
        Case 0
            textbox2.Text = gallons * regular
        Case 1
            textbox2.Text = gallons * special
        Case 2
            textbox2.Text = gallons * super
    End Select

End Sub



End Class






Is This A Good Question/Topic? 0
  • +

Replies To: miles per gallon gui problem

#2 Toadill  Icon User is offline

  • D.I.C Regular

Reputation: 40
  • View blog
  • Posts: 346
  • Joined: 08-January 12

Re: miles per gallon gui problem

Posted 11 March 2012 - 02:34 PM

I don't get your code why are you doing this inside a class?

Try making this a function, make all your variables global so they can be seen by all subs.
Private Sub Cal(ByVal num1 As Integer, ByVal num2 As Integer, ByVal ops As Integer)


Was This Post Helpful? 0
  • +
  • -

#3 ekb9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 11-March 12

Re: miles per gallon gui problem

Posted 11 March 2012 - 02:38 PM

How do I make my variables global? I changed my last private sub to a function but it still says that the statement is not valid in namespace
Was This Post Helpful? 0
  • +
  • -

#4 Toadill  Icon User is offline

  • D.I.C Regular

Reputation: 40
  • View blog
  • Posts: 346
  • Joined: 08-January 12

Re: miles per gallon gui problem

Posted 11 March 2012 - 02:56 PM

'declarations
    Dim gallon As Double ' total gallons
    Dim total As Decimal ' total price gallons times grade price
    Dim regular As Decimal = 2.69
    Dim special As Decimal = 2.79
    Dim super As Decimal = 2.89
    Dim intReturn as Integer

Private Sub Form_load
    
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        intReturn = Cal(Val(), Val(TextBox2.Text), 0)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
       intReturn = Cal(Val(TextBox1.Text), Val(TextBox2.Text), 1)
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        intReturn = Cal(Val(TextBox1.Text), Val(TextBox2.Text), 2)
End Sub

Function Sum(ByVal num1 As Integer, ByVal num2 As Integer, ByVal ops As Integer) As Integer
    Select Case ops
        Case 0
            Return gallons * regular
        Case 1
            Return gallons * special
        Case 2
            Return gallons * super
    End Select
End Function



You are not using VB.Net are you?

Also something I just noticed, you will want to return a decimal to get the dollar amount.

This post has been edited by Toadill: 11 March 2012 - 02:55 PM

Was This Post Helpful? 0
  • +
  • -

#5 ekb9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 11-March 12

Re: miles per gallon gui problem

Posted 11 March 2012 - 03:16 PM

I just plugged in the code you sent to see if that worked at all, and it will debug but it doesn't do anything
Was This Post Helpful? 0
  • +
  • -

#6 Toadill  Icon User is offline

  • D.I.C Regular

Reputation: 40
  • View blog
  • Posts: 346
  • Joined: 08-January 12

Re: miles per gallon gui problem

Posted 11 March 2012 - 03:18 PM

Okay tell me you are using VB6.0 and not VB.Net
Which?
Was This Post Helpful? 0
  • +
  • -

#7 ekb9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 11-March 12

Re: miles per gallon gui problem

Posted 11 March 2012 - 03:22 PM

Visual Basic 2010
Was This Post Helpful? 0
  • +
  • -

#8 Toadill  Icon User is offline

  • D.I.C Regular

Reputation: 40
  • View blog
  • Posts: 346
  • Joined: 08-January 12

Re: miles per gallon gui problem

Posted 11 March 2012 - 03:30 PM

This is the wrong place to post 2008 - 2010 are both .NET
Was This Post Helpful? 0
  • +
  • -

#9 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 543
  • View blog
  • Posts: 2,896
  • Joined: 19-May 09

Re: miles per gallon gui problem

Posted 11 March 2012 - 07:57 PM

Toadill, if you see the word "Handles" in a piece of code, it's vb.Net. Another giveaway is "System.Windows.Forms.Label".
Was This Post Helpful? 1
  • +
  • -

#10 Toadill  Icon User is offline

  • D.I.C Regular

Reputation: 40
  • View blog
  • Posts: 346
  • Joined: 08-January 12

Re: miles per gallon gui problem

Posted 12 March 2012 - 07:35 AM

View PostBobRodes, on 11 March 2012 - 09:57 PM, said:

Toadill, if you see the word "Handles" in a piece of code, it's vb.Net. Another giveaway is "System.Windows.Forms.Label".


Yes this is what actually made me take notice, this was originally in the VB6.0 section. This thread can be locked because he started a new thread, in the .NET section.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1