LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-17-2011, 05:49 PM   #1
BMan8577
Member
 
Registered: Apr 2011
Posts: 73

Rep: Reputation: 0
Exclamation I am trying to create an if statement (this is for Visual Basic).


This is for my Visual Basic .NET Framework class. I just need some guidance on how I can create an IF Statement with price according to the quantity purchased. For example, I need something like (If Qty = 1-5 then QtyPrice = $50) now this is where I am confused on how to do the If statement. This is the last part I need help on someone please help. And I need a try catch block for any errors. What am I doing wrong??? Thanks everyone.


Public Class Form1

Dim Qty As Integer
Dim QtyPrice As Decimal
Dim SubTotal As Decimal
Const TaxRate As Decimal = 0.07
Dim TaxAmount As Decimal
Dim OrderTot As Decimal
Dim TotItems As Integer
Dim DailyTot As Decimal

Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click

CustName.Text = ""
Address.Text = ""
City.Text = ""
State.Text = ""
Zip.Text = ""
Item.Text = ""
Quantity.Text = ""
Price.Text = ""
SubTot.Text = ""
SalesTax.Text = ""
OrderTotal.Text = ""

GroupBox1.Visible = False
End Sub

Private Sub CustName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustName.TextChanged
If CustName.Text <> "" And Address.Text <> "" And City.Text <> "" And State.Text <> "" And Zip.Text <> "" Then
GroupBox1.Visible = True

End If
End Sub

Private Sub Address_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Address.TextChanged
If CustName.Text <> "" And Address.Text <> "" And City.Text <> "" And State.Text <> "" And Zip.Text <> "" Then
GroupBox1.Visible = True

End If
End Sub

Private Sub City_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles City.TextChanged
If CustName.Text <> "" And Address.Text <> "" And City.Text <> "" And State.Text <> "" And Zip.Text <> "" Then
GroupBox1.Visible = True

End If
End Sub

Private Sub State_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles State.TextChanged
If CustName.Text <> "" And Address.Text <> "" And City.Text <> "" And State.Text <> "" And Zip.Text <> "" Then
GroupBox1.Visible = True


End If
End Sub

Private Sub Zip_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Zip.TextChanged
If CustName.Text <> "" And Address.Text <> "" And City.Text <> "" And State.Text <> "" And Zip.Text <> "" Then
GroupBox1.Visible = True

End If
End Sub

Private Sub CalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CalcButton.Click


Qty = Integer.Parse(Quantity.Text)
QtyPrice = Integer.Parse(Price.Text)
SubTotal = Qty * QtyPrice
SubTot.Text = SubTotal.ToString
TaxAmount = TaxRate * SubTotal
SalesTax.Text = TaxAmount.ToString
OrderTot = TaxAmount + SubTotal
OrderTotal.Text = OrderTot.ToString

End Sub

End Class
 
Old 09-17-2011, 08:16 PM   #2
BMan8577
Member
 
Registered: Apr 2011
Posts: 73

Original Poster
Rep: Reputation: 0
Whatever suggestions I can get would be helpful. If someone could point me in the right direction I can figure it out from there. Thanks.
 
Old 09-17-2011, 10:06 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Can the customer modify Quantity? If so, you should write a subroutine for Quantity_TextChanged, or whatever the event might be, that parses the quantity value, checks to see if it falls within one or more value ranges, then sets Price.Text or QtyPrice accordingly. I actually don't know VB and I don't have a way to run it; I just inferred this from looking at your code.
Kevin Barry
 
Old 09-18-2011, 12:38 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
You have some large 'if' statements already, would explain further what is the issue with this one? Are you saying you do not know where in the code to place it?
 
Old 09-18-2011, 01:15 AM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
When posting code, please use code tags; that way indentations are maintained which will make it easier to read.
Type [code], paste your code after that and type [/code] at the end of your code

Code:
Public Class Form1

    Dim Qty As Integer
    Dim QtyPrice As Decimal
    Dim SubTotal As Decimal
    Const TaxRate As Decimal = 0.07
    Dim TaxAmount As Decimal
    Dim OrderTot As Decimal
    Dim TotItems As Integer
    Dim DailyTot As Decimal

    Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click

        CustName.Text = ""
        Address.Text = ""
        City.Text = ""
        State.Text = ""
        Zip.Text = ""
        Item.Text = ""
        Quantity.Text = ""
        Price.Text = ""
        SubTot.Text = ""
        SalesTax.Text = ""
        OrderTotal.Text = ""

        GroupBox1.Visible = False
    End Sub

    Private Sub CustName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustName.TextChanged
        If CustName.Text <> "" And Address.Text <> "" And City.Text <> "" And State.Text <> "" And Zip.Text <> "" Then
            GroupBox1.Visible = True

        End If
    End Sub

    Private Sub Address_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Address.TextChanged
        If CustName.Text <> "" And Address.Text <> "" And City.Text <> "" And State.Text <> "" And Zip.Text <> "" Then
            GroupBox1.Visible = True

        End If
    End Sub

    Private Sub City_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles City.TextChanged
        If CustName.Text <> "" And Address.Text <> "" And City.Text <> "" And State.Text <> "" And Zip.Text <> "" Then
            GroupBox1.Visible = True

        End If
    End Sub

    Private Sub State_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles State.TextChanged
        If CustName.Text <> "" And Address.Text <> "" And City.Text <> "" And State.Text <> "" And Zip.Text <> "" Then
            GroupBox1.Visible = True


        End If
    End Sub

    Private Sub Zip_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Zip.TextChanged
        If CustName.Text <> "" And Address.Text <> "" And City.Text <> "" And State.Text <> "" And Zip.Text <> "" Then
            GroupBox1.Visible = True

        End If
    End Sub

    Private Sub CalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CalcButton.Click


        Qty = Integer.Parse(Quantity.Text)
        QtyPrice = Integer.Parse(Price.Text)
        SubTotal = Qty * QtyPrice
        SubTot.Text = SubTotal.ToString
        TaxAmount = TaxRate * SubTotal
        SalesTax.Text = TaxAmount.ToString
        OrderTot = TaxAmount + SubTotal
        OrderTotal.Text = OrderTot.ToString

    End Sub

End Class
I'm not a VB coder (ages ago that I did something in VBA)
Based on this piece of code
Code:
    Private Sub State_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles State.TextChanged
        If CustName.Text <> "" And Address.Text <> "" And City.Text <> "" And State.Text <> "" And Zip.Text <> "" Then
            GroupBox1.Visible = True


        End If
    End Sub
I would make something like
Code:
    Private Sub Quantity_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Quantity.TextChanged
        Qty = Integer.Parse(Quantity.Text)
        If Qty > 0 And Qty <= 5 Then
' update the item price here
            Price.Text = "5"
        End If
        If Qty > 5 And Qty <= 50 Then
' update the item price here
            Price.Text = "3"
        End If
    End Sub
Not the most perfect code but it shows the idea.
Not sure if VB understand '<=' (less than or equal) and also not sure how to use 'else' in VB.

Last edited by Wim Sturkenboom; 09-18-2011 at 01:18 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Stupid Question: Microsoft Visual Studio 6.0 (A.K.A. Visual Basic 6) Will it run? S0RD3N Linux - Software 8 05-07-2008 08:42 PM
running Visual Basic/Visual Fox Pro in Linux? depam Linux - Software 9 02-11-2006 03:42 PM
Visual Basic 6 dwig365 Linux - Software 1 08-28-2004 02:33 PM
Visual Basic? Anyone? Mega Man X Programming 3 03-19-2004 05:08 AM
Visual Basic Finnae707 Programming 12 06-17-2003 04:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration