Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7010349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:58:46+00:00 2026-05-27T21:58:46+00:00

I have some code where I am trying to use variables in a tabpage.

  • 0

I have some code where I am trying to use variables in a tabpage. The first tabpage only has one text box for user entry (miles.text) and a button to do a calculation: traveltime = mileage/speed. The value from miles.text is stored into a variable called mileage while the speed used is stored in a variable called speed (me.speedtextbox.text).

Ordinarily, doing val(variable.text) works like a charm and it’s not doing it in this case. When the user enters 100 for the mileage, it should be divided by 65 (the number in the database) and, therefore, the answer should be 1.53 hours. In my case, I’m getting “infinity” and whenever I do anything else with the variable, I get “when casting from a number, the value must be a number less than infinity.” But it is! It’s only 65 and I double-checked that the dataset said that too, which it does. Not sure why I am getting this error…thank you!

Public Class Form1

    Private Property Traveltime As Decimal

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'fooDataSet.testdata' table. You can move, or remove it, as needed.
        Me.TestdataTableAdapter.Fill(Me.foouDataSet.testdata)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mileage As Integer
        Dim speed As Integer


        mileage = Val(miles.Text)
        speed = Val(Me.SpeedTextBox.Text)
        traveltime = mileage / speed

        txttraveltime.text = Traveltime.ToString

    End Sub

    Private Sub txtrate_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txttraveltime.TextChanged

    End Sub
End Class

So I did a test program where it did only one thing and that was to simply read one data column in a one row database and store it to a local variable and multiply it by 1.60 except now I am getting “reference to a non-shared member requires an object reference” and it doesn’t seem to recognize Me.Speed when I declare it. What am I doing wrong?

Public Class Form1

    Dim Speed As Object
    Dim Me.Speed As New Speed

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Me.Speed = CDec(fooDataSet.testdataRow.Item("speed"))*1.60
        Speedtextbox.text = Me.Speed.tostring

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'fooDataSet.testdata' table. You can move, or remove it, as needed.
        Me.TestdataTableAdapter.Fill(Me.fooDataSet.testdata)

    End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:58:47+00:00Added an answer on May 27, 2026 at 9:58 pm

    I discovered what the problem was.

    To store a field from a one-line database to a local variable for calculations, apparently it has to happen in the form1_load event, after the dataadapter fill statement, like so:

    Me.TestdataTableAdapter.Fill(Me.foouDataSet.testdata)
      speed = Me.fooDataSet.testdata(0).speed
    

    and just DIM speed as Decimal after the Public Class line. The same could be done for any other field you want to work with in a similar kind of single datarow:

    yourvarname = Me.yourdatasetname.yourtablename(0).the_database_field_you_want_to_fetch
    

    (Wow! Did I just write something textbooky? LOL)

    Then, after the button click, to do a calculation, it is:

    traveltime = CDec(miles.Text/ speed) 
    txttraveltime.Text = traveltime.ToString
    

    making sure to DIM traveltime as Decimal.

    Works! The problem was the (0) to indicate row 0 (because it’s only one row.) Thank you everyone for your help, especially Competent_Tech. I learned something and I’m happy that I could get back to you guys and share.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to implement unit testing and currently have some code that does
I have some jquery code which I am trying to translate to YUI. I
Trying to get comfortable with jQuery and I have encountered some sample code that
I am now trying to understand some code and I have found a pattern,
I am trying to reduce some code here. I will explain how I have
I am trying to setup a few fixes in some code that have caught
I have a mobile platform that I am trying to write some communications code
I'm trying to port some of my c++ code into c. I have the
i have noticed that every area has some tools you can use to make
I have some database information stored in config.inc.php and i'm trying to use it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.