Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on a project and have some code that works correctly as a console application. Now i need to convert it to a Windows Form Application and have been having trouble. I've been working on it for a fews days, and as someone who is not an experienced programmer I would appreciate any help

What I have tried:

.
VB
Sub Main()
    	Dim Real_1 As Double = 0
    	Dim Real_2 As Double = 0
    	Dim Imag As Double = 0
    	Dim Flag As String
    	Dim A As Double = 0
    	Dim B As Double = 0
    	Dim C As Double = 0
    	Dim D As Double = 0
    	Dim DD As Double = 0

    	Console.WriteLine("This program computes both roots of a quadratic equation given A, B anc C")
    	Console.ReadLine()

    	Do
        	Console.WriteLine("Do you want to run the program?")
        	Flag = Console.ReadLine()

        	If Flag = "Y" Then
            	Console.WriteLine("Enter A")
            	A = Console.ReadLine

            	Console.WriteLine("Enter B")
            	B = Console.ReadLine()

            	Console.WriteLine("Enter C")
            	C = Console.ReadLine()

            	D = (B ^ 2 - 4 * A * C)
            	If D < 0 Then
                	DD = (4 * A * C - B ^ 2) ^ (0.5)

                	Imag = DD / (2 * A)
                	Real_1 = -B / (2 * A)
                	Real_2 = -B / (2 * A)

            	End If
            	If D = 0 Then
                	Imag = 0
                	Real_1 = -B / (2 * A)
                	Real_2 = -B / (2 * A)

            	End If
            	If D > 0 Then
                	Imag = 0
                	Real_1 = (-B + D ^ (0.5)) / (2 * A)
                	Real_2 = (-B - D ^ (0.5)) / (2 * A)

            	End If
            	Console.WriteLine("Solution 1 is = " & Real_1 & ("") & "+J" & Imag)
            	Console.ReadLine()

            	Console.WriteLine("Solution 2 is = " & Real_2 & ("") & "-J" & Imag)
            	Console.ReadLine()

        	Else
            	Environment.Exit(0)


        	End If
    	Loop

	End Sub

End Module
Posted
Updated 28-Jul-16 22:00pm
v2
Comments
ZurdoDev 28-Jul-16 15:31pm    
Where are you stuck?
OriginalGriff 28-Jul-16 15:33pm    
What have you tried?
Where are you stuck?
Because you don't just convert code to swap from a procedural console app to an event driven Windows app...

Google is your friend: VB NET GUI development tutorial[^].
 
Share this answer
 
To give you an approach :

- you create a Form
- you place 3 Textboxes (one for each of you variables A,B,C) on this Form
- you place a Label (for displaying the result) on the Form
- you place a Button (for the calculation) on the Form
- you create a Script like your Sub Main which should be called with the Button.Click-Event (for example)
- in this Script you read the Text-Values of your 3 Textboxes into your Variables, do your calculation and assign the result to the Label.Text-Property

Would you try to do this like described ?
If there a any questions, feel free to ask it/them.
 
Share this answer
 

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