8 Replies - 3331 Views - Last Post: 11 February 2012 - 10:47 PM Rate Topic: -----

#1 SRMSU  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-February 12

Declaring Constant VB 2010

Posted 11 February 2012 - 02:22 PM

Having problem declaring constant on Visual Basic.

rents is $200 per hour and is charge by minutes

this is what I have so far.
const TOTAL_CHARGE_GROUP as Interger = 200 ©
Is This A Good Question/Topic? 0
  • +

Replies To: Declaring Constant VB 2010

#2 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 205
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Declaring Constant VB 2010

Posted 11 February 2012 - 02:29 PM

what's the error you're getting??

It seems to work fine. Though you have a small syntax error in the code you have posted.

Const TOTAL_CHARGE_GROUP As Integer = 200

Was This Post Helpful? 1
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: Declaring Constant VB 2010

Posted 11 February 2012 - 02:30 PM

Looks good to me. But you said you're having a problem, can you elaborate on that a bit?
Was This Post Helpful? 0
  • +
  • -

#4 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Declaring Constant VB 2010

Posted 11 February 2012 - 03:19 PM

I don't think you can have that in your Integer's value.
Was This Post Helpful? 1
  • +
  • -

#5 SRMSU  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-February 12

Re: Declaring Constant VB 2010

Posted 11 February 2012 - 05:49 PM

Thanks guys...

I am working on the following program for abt 12 hrs so far and cannot get it to work. I am new on this.

This is what I have so far.


A local recording studio rents its facilities for $200 per hour. Management charges only for the number of minutes used. Create a project in which the input is the name of the group and the number of minutes it used in the studio. Your program calculates the appropiate charges, accumulates the total charges for all groups and the number of groups that used the studio.


public Class Studio
    'Declare the constants.
    Private TotalNumberSumInteger, AveragesumInteger As Integer
    Private GroupSumInteger, MinCountInteger As Integer
    Const STUDIO_RENT_INTEGER As Integer = 200


    Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
        'Print the form.
        PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
        PrintForm1.Print()

    End Sub

    Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
        'Calculate charges for all groups.
        Dim TotalNumber As Integer
        Dim GroupCharges As Integer
        Dim TotalNumberInteger, AverageInteger, TotalChargesInteger, GroupInteger, MinInteger As Integer


        'Convert input values to numeric variables.
        GroupInteger = Integer.Parse(GroupChargesTextBox.Text)

        MinInteger = Integer.Parse(MinTextBox.Text)

        ' Calculate Value.

        TotalChargesInteger = GroupInteger * MinInteger

        'Format and display answers.
        TotalNumberGroupTextBox.Text = TotalNumberInteger.ToString("C")
        AverageTextBox.Text = AverageInteger.ToString("N")
        TotalChargesTextBox.Text = TotalChargesInteger.ToString("C")
    End Sub
    Private Sub ClearButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ClearButton.Click

        ' Clear previous amounts from the form.
        TotalNumberGroupTextBox.Clear()
        AverageTextBox.Clear()
        GroupChargesTextBox.Clear()
        MinTextBox.Clear()
        GroupChargesTextBox.Clear()
        TotalNumberGroupTextBox.Clear()
        With GroupTextBox
            .Clear()
            .Focus()
        End With
    End Sub
    Private Sub ExitButton_Click(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles ExitButton.Click

        ' Exit the project.
        Me.Close()

This post has been edited by smohd: 11 February 2012 - 08:07 PM
Reason for edit:: Code tags added. Please use [code] tags when posting codes

Was This Post Helpful? 0
  • +
  • -

#6 SRMSU  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-February 12

Re: Declaring Constant VB 2010

Posted 11 February 2012 - 06:25 PM

View PostCharlieMay, on 11 February 2012 - 02:30 PM, said:

Looks good to me. But you said you're having a problem, can you elaborate on that a bit?


Thanks Charlie...

I am working on the following program for abt 12 hrs so far and cannot get it to work. I am new on this.

This is what I have so far.


A local recording studio rents its facilities for $200 per hour. Management charges only for the number of minutes used. Create a project in which the input is the name of the group and the number of minutes it used in the studio. Your program calculates the appropiate charges, accumulates the total charges for all groups and the number of groups that used the studio.


public Class Studio
'Declare the constants.
Private TotalNumberSumInteger, AveragesumInteger As Integer
Private GroupSumInteger, MinCountInteger As Integer
Const STUDIO_RENT_INTEGER As Integer = 200


Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
'Print the form.
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()

End Sub

Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
'Calculate charges for all groups.
Dim TotalNumber As Integer
Dim GroupCharges As Integer
Dim TotalNumberInteger, AverageInteger, TotalChargesInteger, GroupInteger, MinInteger As Integer


'Convert input values to numeric variables.
GroupInteger = Integer.Parse(GroupChargesTextBox.Text)

MinInteger = Integer.Parse(MinTextBox.Text)

' Calculate Value.

TotalChargesInteger = GroupInteger * MinInteger

'Format and display answers.
TotalNumberGroupTextBox.Text = TotalNumberInteger.ToString("C")
AverageTextBox.Text = AverageInteger.ToString("N")
TotalChargesTextBox.Text = TotalChargesInteger.ToString("C")
End Sub
Private Sub ClearButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ClearButton.Click

' Clear previous amounts from the form.
TotalNumberGroupTextBox.Clear()
AverageTextBox.Clear()
GroupChargesTextBox.Clear()
MinTextBox.Clear()
GroupChargesTextBox.Clear()
TotalNumberGroupTextBox.Clear()
With GroupTextBox
.Clear()
.Focus()
End With
End Sub
Private Sub ExitButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ExitButton.Click

' Exit the project.
Me.Close()

This post has been edited by smohd: 11 February 2012 - 08:10 PM
Reason for edit:: Code tags added. Please use [code] tags when posting codes

Was This Post Helpful? 0
  • +
  • -

#7 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: Declaring Constant VB 2010

Posted 11 February 2012 - 06:51 PM

Other than declaring the const, where are you using it? I'm not seeing it anywhere after declaring it.
Was This Post Helpful? 0
  • +
  • -

#8 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Declaring Constant VB 2010

Posted 11 February 2012 - 08:33 PM

Quote

Create a project in which the input is the name of the group and the number of minutes it used in the studio

That is the input of the project, name and minutes. But is is not what you are doing:
'Convert input values to numeric variables.
GroupInteger = Integer.Parse(GroupChargesTextBox.Text)
MinInteger = Integer.Parse(MinTextBox.Text)

You are taking charges from user?!! That is the one you are required to calculate.

Quote

Your program calculates the appropiate charges, accumulates the total charges for all groups and the number of groups that used the studio.

You have a lot of class variables there but I dont see you use any. Also is this how you calculate charge per time used?
TotalChargesInteger = GroupInteger * MinInteger

The assignment said that the studio takes 200 per hour but it do it in minute, so you have to find how much per minute the studio takes for the service and then times minutes used.
Then you have to count number of groups that used the studio, so probably you will need a class variable to count groups which increases every time user enter another group.

Also your program needs to total all charges, so again another variable to add every charges taken from a group.

TODO:
I will give you some ideas to start with from how I understand the assignment, but first do the following:
- You have a lot of unused variables, get rid of them.
- Note the corrections I did above

Now:
- Your program needs only two class variables, for starting, one to count groups and the next one to count total charges. And may be a constant for charge per minute.

- In your CalculateButton create the following variables:name of the group, minute used, charge.

- The take name and minute used from user input, and calculate charges by multiplying minute used and charges per minute.

- Add the charge to the total charge and increment the count for groups.

- Display the output required and you are done....

This post has been edited by smohd: 11 February 2012 - 08:35 PM

Was This Post Helpful? 0
  • +
  • -

#9 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Declaring Constant VB 2010

Posted 11 February 2012 - 10:47 PM

View PostSRMSU, on 12 February 2012 - 11:25 AM, said:

View PostCharlieMay, on 11 February 2012 - 02:30 PM, said:

Looks good to me. But you said you're having a problem, can you elaborate on that a bit?


Thanks Charlie...

I am working on the following program for abt 12 hrs so far and cannot get it to work. I am new on this.

This is what I have so far.


A local recording studio rents its facilities for $200 per hour. Management charges only for the number of minutes used. Create a project in which the input is the name of the group and the number of minutes it used in the studio. Your program calculates the appropiate charges, accumulates the total charges for all groups and the number of groups that used the studio.


public Class Studio
'Declare the constants.
Private TotalNumberSumInteger, AveragesumInteger As Integer
Private GroupSumInteger, MinCountInteger As Integer
Const STUDIO_RENT_INTEGER As Integer = 200


Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
'Print the form.
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()

End Sub

Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
'Calculate charges for all groups.
Dim TotalNumber As Integer
Dim GroupCharges As Integer
Dim TotalNumberInteger, AverageInteger, TotalChargesInteger, GroupInteger, MinInteger As Integer


'Convert input values to numeric variables.
GroupInteger = Integer.Parse(GroupChargesTextBox.Text)

MinInteger = Integer.Parse(MinTextBox.Text)

' Calculate Value.

TotalChargesInteger = GroupInteger * MinInteger

'Format and display answers.
TotalNumberGroupTextBox.Text = TotalNumberInteger.ToString("C")
AverageTextBox.Text = AverageInteger.ToString("N")
TotalChargesTextBox.Text = TotalChargesInteger.ToString("C")
End Sub
Private Sub ClearButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ClearButton.Click

' Clear previous amounts from the form.
TotalNumberGroupTextBox.Clear()
AverageTextBox.Clear()
GroupChargesTextBox.Clear()
MinTextBox.Clear()
GroupChargesTextBox.Clear()
TotalNumberGroupTextBox.Clear()
With GroupTextBox
.Clear()
.Focus()
End With
End Sub
Private Sub ExitButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ExitButton.Click

' Exit the project.
Me.Close()

1. In your code, you don't actually calculate an average - this variable has not been assigned a value, therefore. If you don't use it, why have it there?
2.I advise encasing the Integer.Parse() bits in Try...Catch... statements - that way if an exception occurs in the Parse() at least it will be caught and you can prevent ugly .NET framework error messages. Exceptions can be raised in Integer.Parse if:
  • the number is nothing
  • it is outside of the Integer MinValue or MaxValue
  • it is not in the correct format.

3.You don't use the constant you declared!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1