3 Replies - 229 Views - Last Post: 09 August 2011 - 08:19 PM Rate Topic: -----

#1 jones246  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-August 11

VB 8 problem with If statement

Posted 09 August 2011 - 06:23 PM

Hi

My first post I think as this is my second attempt to post.
I am new to VB and amd using VB8 sp1.
I am doing a project for college and all is going ok but for this if statement. the last lbl_output should returd "TAPE" but it always returns "DVD". any help would be great as I am at this for ever.

Public Class frm_databackup
    Dim Cd As Single
    Dim DVD As Single
    Dim Tape As Single

Private Sub btn_calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_calculate.Click
        If txt_input.Text <= 700 Then
            lbl_output.Text = " CD"
        ElseIf txt_input.Text > 700 <= 4812.8 Then
            lbl_output.Text = "DVD"
        ElseIf txt_input.Text > 4812.8 Then
            lbl_output.Text = " TAPE"
        End If

    End Sub


This post has been edited by no2pencil: 09 August 2011 - 06:32 PM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: VB 8 problem with If statement

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1379
  • View blog
  • Posts: 4,444
  • Joined: 25-September 09

Re: VB 8 problem with If statement

Posted 09 August 2011 - 06:29 PM

You are comparing a string as you would a value AND you need to qualify each comparison

If CInt(txt_input.Text) > 700 AND CInt(txtInput.Text) <= 4812.8 Then
lbl_output.Text = "DVD"


Remember 700 is not "700" one is numeric and one is a string representing a number. Therefore you will need to convert it.
Was This Post Helpful? 1
  • +
  • -

#3 jones246  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-August 11

Re: VB 8 problem with If statement

Posted 09 August 2011 - 07:43 PM

Hi CharlieMay

Your code worked and I thank you for that.

I have a lot to learn.

Best regards

jones246
Was This Post Helpful? 0
  • +
  • -

#4 Elda  Icon User is offline

  • D.I.C Regular

Reputation: 31
  • View blog
  • Posts: 314
  • Joined: 30-December 10

Re: VB 8 problem with If statement

Posted 09 August 2011 - 08:19 PM

A credit to Sir Charlie... :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1