7 Replies - 237 Views - Last Post: 09 December 2012 - 01:18 PM Rate Topic: -----

#1 Sand-Man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 13-November 12

Simple Boolean Logic

Posted 09 December 2012 - 12:43 PM

hey guys, ive made this form with two textbox's called ( age and RHR ) im asking the client two insert two values and see whether and then hit continue, it seems right but when the two message boxes come up the program gets an error. i cant understand what the error means. i know its probably something silly but yeah. All help appreciated :D


Public Class HeartData

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

        If age.Text = "" Then
            MsgBox("Please Insert Your Age")
            A1 = False
        End If

        If RHR.Text = "" Then
            MsgBox("Please Insert Your Resting Heart Rate")
            A2 = False
        Else : A2 = True
        End If
        If Age.Text < 0 Then
            MsgBox(" Invalid Age ")
            A1 = False
        Else : A1 = True
        End If
        If Age.Text > 50 Then
            MsgBox(" Your Too Old To Be Using My Program ")
            A1 = False
        Else : A1 = True
        End If

        If A1 And A2 = True Then
            MsgBox(" Thank You For Your Support")
            HeartForm.Show()
            Me.Hide()

        End If

    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Simple Boolean Logic

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8377
  • View blog
  • Posts: 31,142
  • Joined: 12-June 08

Re: Simple Boolean Logic

Posted 09 December 2012 - 12:45 PM

Quote

the program gets an error. i cant understand what the error means.

It's helpful to us to know what the error text is...
Was This Post Helpful? 0
  • +
  • -

#3 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: Simple Boolean Logic

Posted 09 December 2012 - 12:59 PM

I'll take a wild guess, but imagine scenario with your code, where user enters "lucky3" in Age TextBox, and clicks the Button1. How would your code evaluate if "lucky3" is smaller then 0?
Was This Post Helpful? 1
  • +
  • -

#4 Sand-Man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 13-November 12

Re: Simple Boolean Logic

Posted 09 December 2012 - 01:05 PM

thats a really good point, lucky3. how could i make it so that when letters are entered it also become invalid?

and Modi123_1 the error is this :
" Conversion from string "" to type 'Double' is not valid. " but i think thats linked to what lucky3 said .
Was This Post Helpful? 0
  • +
  • -

#5 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Simple Boolean Logic

Posted 09 December 2012 - 01:07 PM

Assuming the user does not enter Age or RHR...

You ask the user to enter age, then RHR, and then don't give him a chance to enter it, but go ahead and try to convert an empty string to a double.
Was This Post Helpful? 1
  • +
  • -

#6 Sand-Man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 13-November 12

Re: Simple Boolean Logic

Posted 09 December 2012 - 01:12 PM

lar3ry, i understand what your trying to say but how would i fix this?
Was This Post Helpful? 0
  • +
  • -

#7 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Simple Boolean Logic

Posted 09 December 2012 - 01:17 PM

View PostSand-Man, on 09 December 2012 - 02:05 PM, said:

and Modi123_1 the error is this :
" Conversion from string "" to type 'Double' is not valid. " but i think thats linked to what lucky3 said .

It's ALWAYS a good idea to use Option Strict On (place it above your Class statement). It will tell you what data types are being used incorrectly. Fixing errors pointed out by the editor goes a long way toward a functioning program.

View PostSand-Man, on 09 December 2012 - 02:12 PM, said:

lar3ry, i understand what your trying to say but how would i fix this?

There are a number of ways. Probably the best is to check both TextBoxes for valid input, put up an appropriate MsgBox, and exit the subroutine. The user would them be able to enter the data and hit the button again.
Was This Post Helpful? 2
  • +
  • -

#8 Sand-Man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 13-November 12

Re: Simple Boolean Logic

Posted 09 December 2012 - 01:18 PM

aaah ok i understand thank you, ill post back if its working
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1