转换此代码有点帮助 [英] A little help converting this code

查看:75
本文介绍了转换此代码有点帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个项目,并且有一些代码可以正常用作控制台应用程序。现在我需要将其转换为Windows窗体应用程序并遇到问题。我已经工作了几天,作为一个不是经验丰富的程序员的人,我将不胜感激任何帮助



我尝试过:



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:

.

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

推荐答案

Google 是你的朋友: VB NET GUI开发教程 [ ^ ]。
Google is your friend: VB NET GUI development tutorial[^].


给你一个方法:



- 你创建一个表格

- 你放置3个文本框(每个文件框一个)本表格中的A,B,C表格

- 您在表格上放置一个标签(用于显示结果)

- 您放置一个按钮(用于计算)在表格上

- 你创建一个类似Sub Main的脚本,应该用Button.Click-Event调用(例如)

- 在这个脚本中你读了文本 - 将3个文本框的值放入变量中,进行计算并将结果分配给Label.Text-Property



您是否尝试按照描述进行此操作?

如果有任何问题,请随时询问/他们。
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.


这篇关于转换此代码有点帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆