|
-
Oct 5th, 2011, 10:14 PM
#1
Thread Starter
New Member
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
-
Oct 6th, 2011, 01:41 AM
#2
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
-
Oct 6th, 2011, 02:01 AM
#3
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.
-
Oct 6th, 2011, 02:16 AM
#4
Re: Need help with VB.
add a textbox: Ziptextbox, + a label: Shippinglabel, then try this code:
vb 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 varZiptextbox As Integer
Integer.TryParse(Ziptextbox.Text, varZiptextbox)
Dim varShippinglabel As Decimal
If varZiptextbox = Zip1 OrElse varZiptextbox = Zip2 OrElse varZiptextbox = zip3 Then
varShippinglabel = CDec(Shipcharge1)
Else
varShippinglabel = CDec(Shipcharge2)
End If
'Display shipping charge
Shippinglabel.Text = varShippinglabel.ToString("c2")
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|