Results 1 to 3 of 3

Thread: Cint or Cdbl question

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    63

    Resolved Cint or Cdbl question

    here's the code for the button in question:

    Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click
    Dim BattingAverage As Double
    BattingAverage = txtHits.Text / txtBat.Text
    Dim strAverage As String = "Your Batting Average is " & BattingAverage
    lstAverage.Items.Add(strAverage)
    End Sub


    My teachers instructions says you need to convert your numeric text input to numbers using Cint or Cdbl and I'm not sure this is right. Can anyone help me?
    Thank you very much
    Last edited by Cassy; Oct 17th, 2004 at 01:44 PM.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Cint or Cdbl question

    VB Code:
    1. Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click
    2.         Dim BattingAverage As Double
    3.         BattingAverage = CInt(txtHits.Text)/CInt( txtBat.Text)
    4.         Dim strAverage As String = "Your Batting Average is " & BattingAverage
    5.         lstAverage.Items.Add(strAverage)
    6.     End Sub
    Tengo mas preguntas que contestas

  3. #3
    PowerPoster SuperSparks's Avatar
    Join Date
    May 2003
    Location
    London, England
    Posts
    265
    And if you have Option Strict On, then you'll need to convert the double to a string as well:

    VB Code:
    1. Dim strAverage As String = "Your Batting Average is " & CStr(BattingAverage)
    2.  
    3. or:
    4.  
    5.  Dim strAverage As String = "Your Batting Average is " & Convert.ToString(BattingAverage)
    Nick.

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