Results 1 to 3 of 3

Thread: [RESOLVED] Storing Access 07 data on VB 08

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    8

    Resolved [RESOLVED] Storing Access 07 data on VB 08

    I know that this is a stupid question but I really cannot work out how I can store data that's been read from a database as a variable that I can then work with in vb.

    I've linked the two using the standard data sourcing method and I now need to use the data that is read in to it on another form.

    The idea of this is that I'm creating a wage calculator and the employees are stored in a database and can be viewed on a vb form, however, I now need to use the data of their pay/hr to be used on another form to calculate the wage.

    I have tried to declare a public variable across the two separate forms, and on the button that takes you to the other to set this variable as the contents of the text box which is displaying the pay/hr using the following code:


    Public Class ManageUsers
    Public HrlyRate As Decimal 'Declaring global variable to use between forms


    'Some other code in between relating to rest of the stuff on the form



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    RatePerHourTextBox.Text = HrlyRate 'Saving private variable to global variable
    Calculation.Show()
    End Sub
    End Class




    Then on the other form I have used this code to do the calculation:



    Public Class Calculation


    Private Sub calculation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    'Coding for when the user clicks the 'Calculate' button
    Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCalculate.Click
    Dim decIncome, decDeductions, decAmount As Decimal 'Creates three variables as real numbers

    decIncome = ManageUsers.HrlyRate 'Sets income as hourly rate from other form
    decDeductions = decIncome * 0.22 'Calculates decution of tax at 22%
    decAmount = decIncome - decDeductions 'The final amount being Income subtract Deductions

    lblIncFig.Text = Format(decIncome, "currency") 'This formats the output labels to £XXX.XX
    lblDedFig.Text = Format(decDeductions, "currency")
    lblFinFig.Text = Format(decAmount, "currency")

    End Sub

    Private Sub EmployeeBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Me.Validate()
    Me.EmployeeBindingSource.EndEdit()
    Me.TableAdapterManager.UpdateAll(Me.Payroll_CheckerDataSet)

    End Sub

    End Class












    I'm still really new to this program and this is needed before tomorrow, so if I could have an idiot answer that I could follow please and asap!!

    Much appreciated

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Storing Access 07 data on VB 08

    I'm not sure what the actual question is. You created a variable (which isn't global, it is just a public member variable of the form), then accessed it in a different form. Is that not working? What about it is not working?

    I see one possible problem, which is that you are referencing ManageUsers.HrlyRate, which means that you are reading the variable from the default instance of the ManageUsers form. If you are not setting the variable in the ManageUsers form, then you are reading the wrong variable. Default instances are EVIL!! They were introduced in VB2005 to make .NET act more like VB6, and have been causing chaos ever since. ManageUsers is not just the name of the class, it is also a specific instance of the form. If you are showing a different instance of the form, then you are NOT showing the default instance, in which case you would be reading the variable from the default instance, while setting the variable in a different instance. Those would be two different things.

    Of course, since I don't know that you are NOT using the default instance, and since I don't know what the problem is, that could be totally wrong, too.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    8

    Re: Storing Access 07 data on VB 08

    I found the answer just now, with having spent about 5hrs on it. After having an hour break, came back to it and what it is, is I've RatePerHourTextBox.Text = HrlyRate

    As it reads that from right to left and doesn't have a value beforehand it becomes nothing. So when I then read it in the other form as ManageUsers.HrlyRate there's obviously nothing in the variable.

    Yup, you've probably guessed it if you're reading this - switch the two around to HrlyRate = RatePerHourTextBox.Text and it's problem solved :|

    Sometimes I really hate programming....

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width