Click here to Skip to main content
14,835,369 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I fix my code in VB.net, I am suppose to use 2 radio buttons to calculate the curve length of a SAG vertical curve and crest vertical curve. I set my variable A (Algerbraric grade difference) and V(design speed) as "Single" because those are user inputs. S is a given equation for sight difference which is needed to calculate "L" (curve length).
I have been trying to figure out why my debugging won't work.
Apparently, there are build errors in there and I can't figure them out. perhaps I am lacking something inside the button1.click? Would love any feedback I can get please!

What I have tried:

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim A, V As Single
        Dim S, L As Double


        A = A_val.Text
        V = V_val.Text

        S = 3.675 * V + 0.096 * (V) ^ 2
        L_val.Text = Val(L)
    End Sub

    Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RB_L.CheckedChanged
        Dim A, V As Single
        Dim chk, L As Double

        chk = 3.675 * V + 0.096 * (V) ^ 2
        
        If chk < L Then
        L = (A * (chk ^ 2)) / 1329
        End If

        If chk > L Then
            L = 2 * chk - (1329 / A)
        End If

        L_val.Text = Val(L)

    End Sub

    Private Sub RB_L1_CheckedChanged(sender As Object, e As EventArgs) Handles RB_L1.CheckedChanged
        Dim A, V As Single
        Dim chk, L As Double


        chk = 3.675 * V + 0.096 * (V) ^ 2

        If chk < L Then
        L = (A * chk ^ 2) / (400 + 3.5 * chk)
        If chk > L Then
            L = (2 * chk - (400 + 3.5 * chk) / A)
        End If

        L_val.Text = Val(L)

    End Sub


    Private Sub Clr_Click(sender As Object, e As EventArgs) Handles Clr.Click
        A_val.Text = ""
        V_val.Text = ""
        L_val.Text = ""
    End Sub
End Class
Posted
Updated 5-Nov-20 9:49am
v3

You can't debug until your code compiles cleanly: it isn't until then that an EXE file is generated, and you need one of those in order to run your application, either directly or within the debugger.

What you have are syntax errors - and quite a few logic and typing errors - which you need to fix before you can go any further.

Start by looking at the "Errors" pane, and read the first one carefully, then double click it - that will take you to the line it found the problem on. The message you read will describe the problem, and is generally pretty accurate and useful. It's probably complaining about this line (among others):
VB
If chk L Then
Which is pretty much meaningless as is: "chk L" is not a condition at all; it can't be "resolved" to a "yes or no" answer. Did you mean "is chk the same as L"?, or "is chk greater than L?", or what - we have no idea and - to be brutally honest - from the rest of the code it doesn't look like you do either!

DO yourself a favour, and start again: read your homework question carefully, and think about what it want's you to do before trying it manually on paper. Then start working out what you need to do i order to move that to a computer - just jumping straight into code is a big mistake and will waste a whole load more time than you will save!

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
   
You forgot the following lines in the last two Subs:
A = A_val.Text
V = V_val.Text
   
Thank you @OrigincalGriff! I didn't notice that when I copied and pasted the code the chk > L was missing. I guess the format on this browser doesn't allow me to paste that "less than sign". The prompt of this project is, we just need the user to input 2 variables, and the program should calculate the curve length depending on which radio button they pick. (Below is the prompt for the project, and the variable K in here is not relevant to the code I have been informed)
https://learn-us-east-1-prod-fleet01-xythos.s3.amazonaws.com/5eb1a317e2761/8424399?response-cache-control=private%2C%20max-age%3D21600&response-content-disposition=inline%3B%20filename%2A%3DUTF-8%27%27Project%25201.pdf&response-content-type=application%2Fpdf&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20201105T180000Z&X-Amz-SignedHeaders=host&X-Amz-Expires=21600&X-Amz-Credential=AKIAZH6WM4PL5SJBSTP6%2F20201105%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=4bb4e9b1e572e83a973d1f5f714672a93eb81a30aed9c28fd11c1d85a87753ad
   
When you add A = A_val.Text and V = V_val.Text into the radio buttons, VB.net says it's not needed with a white dotted underline. @RickZeeland
   
Comments
CHill60 5-Nov-20 16:42pm
   
If you want to respond to a post use the "Have a Question or Comment" link next to it. Stop posting comments as solutions- the poster will not be notified of your response

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900