Results 1 to 4 of 4

Thread: Need help with VB.

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    1

    Need help with VB.

    Hello, I am new to this forum and to VB as well. I have this project for school that I need to code. I have had some help from another forum but there is one last thing that I can't get to work. According to VB and the other forum, I have everything correct in the code so far but I can't get an output. I need to get either of the shipping charges to display on "Shipinglabel"
    Here is the code so far:

    Code:
    ' Project name:         Shipping Project
    ' Project purpose:      Displays a shipping charge
    ' Created/revised by:   <your name> on <current date>
    
    Option Explicit On
    Option Strict On
    Option Infer Off
    
    Public Class MainForm
    
        Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
            Me.Close()
        End Sub
    
        Private Sub displayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles displayButton.Click
    
            ' Determines the shipping charge for zip entered
            'Declare Constants and Variables
    
            Const Shipcharge1 As Decimal = 32D
            Const Shipcharge2 As Decimal = 37.75D
    
            Dim Zip1 As Integer = 60618
            Dim Zip2 As Integer = 60620
            Dim zip3 As Integer = 60632
            Dim Ziptextbox As Integer
            Dim Shippinglabel As Integer
    
            'Assign user input to variables
            Integer.TryParse(CStr(Ziptextbox), Ziptextbox)
            Integer.TryParse(CStr(Shippinglabel), CInt(Shippinglabel))
    
            If Ziptextbox = Zip1 Then
                Shippinglabel = CInt(Shipcharge1)
            Else
                Shippinglabel = CInt(Shipcharge2)
            End If
    
            If Ziptextbox = Zip2 Then
                Shippinglabel = CInt(Shipcharge1)
            Else
                Shippinglabel = CInt(Shipcharge2)
            End If
    
    
            If Ziptextbox = zip3 Then
                Shippinglabel = CInt(Shipcharge1)
            Else
                Shippinglabel = CInt(Shipcharge2)
    
            End If
    
    
            'Display shipping charge
    
    
            
    
    End Sub
    
        Private Function TextBoxInteger() As String
            Throw New NotImplementedException
        End Function
    
    End Class
    Your help is appreciated!
    Last edited by gep13; Oct 6th, 2011 at 01:40 AM. Reason: Added Code Tags

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Need help with VB.

    Hello wskaggs08,

    Welcome to the forums!!

    When you are posting code into the forum, can you please remember to surround it in [code][/code] or [HIGHLIGHT=vb][/highlight] tags? It makes it a lot easier to read. I have done this for you in your above post.

    Thanks!

    Gary

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Need help with VB.

    If you want to display something then you would need a control on your form to do so. In your code 'Shippinglabel' is simply an Integer, so it just stores a number and that's it. If you want to show the user something then you would need to use an actual Label control, not just a variable with "label" in its name.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Need help with VB.

    add a textbox: Ziptextbox, + a label: Shippinglabel, then try this code:


    vb Code:
    1. ' Project name:         Shipping Project
    2. ' Project purpose:      Displays a shipping charge
    3. ' Created/revised by:   <your name> on <current date>
    4.  
    5. Option Explicit On
    6. Option Strict On
    7. Option Infer Off
    8.  
    9. Public Class MainForm
    10.  
    11.     Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
    12.         Me.Close()
    13.     End Sub
    14.  
    15.     Private Sub displayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles displayButton.Click
    16.  
    17.         ' Determines the shipping charge for zip entered
    18.         'Declare Constants and Variables
    19.  
    20.         Const Shipcharge1 As Decimal = 32D
    21.         Const Shipcharge2 As Decimal = 37.75D
    22.  
    23.         Dim Zip1 As Integer = 60618
    24.         Dim Zip2 As Integer = 60620
    25.         Dim zip3 As Integer = 60632
    26.         Dim varZiptextbox As Integer
    27.  
    28.         Integer.TryParse(Ziptextbox.Text, varZiptextbox)
    29.         Dim varShippinglabel As Decimal
    30.  
    31.  
    32.         If varZiptextbox = Zip1 OrElse varZiptextbox = Zip2 OrElse varZiptextbox = zip3 Then
    33.             varShippinglabel = CDec(Shipcharge1)
    34.         Else
    35.             varShippinglabel = CDec(Shipcharge2)
    36.         End If
    37.  
    38.         'Display shipping charge
    39.         Shippinglabel.Text = varShippinglabel.ToString("c2")
    40.  
    41.     End Sub
    42.  
    43. End Class

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