转换值从窗口到另一个窗口 [英] transformation values form window to another

查看:57
本文介绍了转换值从窗口到另一个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 


我的问题是我有三种形式,前两种形式有文本框和按钮,在最后一种形式有标签到在将它们转换为单一类型后,显示form1和form2中文本框值的总和结果。我使用
me.close来关闭第一个表单并打开下一个表格,这里问题是退出,vs工作室说有文本框类型从字符串转换为单个的问题,但当我删除我.close应用程序成功运行。 


代码为:


form1:


form2。显示()

Me.close()


form2:


  Dim a,b As Single

        a = Form1.TextBox1.Text

        b = TextBox1.Text

        Form3.Label1.Text = a + b

        Form3.Show()

       我。关闭()


请帮我修复!!!




解决方案


 


我的问题是我有三种形式,前两种形式有文本框和按钮,在最后一种形式中有标签显示转换后form1和form2中文本框值的总和结果他们到单一类型。我使用
me.close来关闭第一个表单并打开下一个表格,这里问题是退出,vs工作室说有文本框类型从字符串转换为单个的问题,但当我删除我.close应用程序成功运行。 


代码为:


form1:


form2。显示()

Me.close()


form2:


  Dim a,b As Single

        a = Form1.TextBox1.Text

        b = TextBox1.Text

        Form3.Label1.Text = a + b

        Form3.Show()

       我。关闭()


请帮我修复!!!





您好


关于风格的真实回合就是这样。无论如何,这里有一些Form1,Form2和Form3的代码可以满足您的要求。


FORM1

 Option Strict On 
Option Explicit On
Public Class Form1
Private Sub Button1_Click(sender As Object,e As EventArgs)Handles Button1.Click
Dim f2 As New Form2 with {。 CarryValue = TextBox1.Text}
f2.Show()
隐藏()
结束次级
结束等级

FORM2

 Option Strict On 
Option Explicit On
Public Class Form2
Property CarryValue As String
Private Sub Button1_Click(发送者作为对象,e作为EventArgs)处理Button1.Click
Dim f3 As New Form3 {C.CarryValue1 = CarryValue,.CarryValue2 = TextBox1.Text}
f3.Show()
隐藏()
结束次级
结束等级

FORM3


< pre class ="prettyprint lang-vb"> Option Strict On
Option Explicit On
P ublic Class Form3
Property CarryValue1 As String
Property CarryValue2 As String
Private Sub Form3_Load(sender As Object,e As EventArgs)Handles MyBase.Load
Label1.Text =(GetSingle( CarryValue1)+ GetSingle(CarryValue2))。ToString
End Sub
函数GetSingle(s As String)As Single
Dim v As Single
If Single.TryParse(s,v)然后返回v
返回0
结束函数
结束类


请注意,我在"CarryValue"周围使用变量名称的变体你可能需要使用你自己的,这样你就可以跟踪每个人在做什么。另请注意,我使用了Hide而不是Close来关闭表单,就像可以结束应用程序一样。



Hi , 

My problem is that i have three forms , in the first two form there is textbox and button , in the the last form there is label to show the result of the summation of the value of the textbox in form1 and form2 after converted them to single type. I used me.close to close first form and open the next one and here the problem is exit , the vs studio said that there is probelm of conversion of type of textbox from string to single, but when i delete the me.close the app work successfully. 

the code is :

form1:

form2.Show()
Me.close()

form2:

 Dim a, b As Single
        a = Form1.TextBox1.Text
        b = TextBox1.Text
        Form3.Label1.Text = a + b
        Form3.Show()
        Me.Close()

please help me fix it!!!

解决方案

Hi , 

My problem is that i have three forms , in the first two form there is textbox and button , in the the last form there is label to show the result of the summation of the value of the textbox in form1 and form2 after converted them to single type. I used me.close to close first form and open the next one and here the problem is exit , the vs studio said that there is probelm of conversion of type of textbox from string to single, but when i delete the me.close the app work successfully. 

the code is :

form1:

form2.Show()
Me.close()

form2:

 Dim a, b As Single
        a = Form1.TextBox1.Text
        b = TextBox1.Text
        Form3.Label1.Text = a + b
        Form3.Show()
        Me.Close()

please help me fix it!!!

Hi

A real round about style is that. Anyway, here is some code for each of Form1, Form2 and Form3 that does what you ask.

FORM1

Option Strict On
Option Explicit On
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim f2 As New Form2 With {.CarryValue = TextBox1.Text}
        f2.Show()
        Hide()
    End Sub
End Class

FORM2

Option Strict On
Option Explicit On
Public Class Form2
    Property CarryValue As String
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim f3 As New Form3 With {.CarryValue1 = CarryValue, .CarryValue2 = TextBox1.Text}
        f3.Show()
        Hide()
    End Sub
End Class

FORM3

Option Strict On
Option Explicit On
Public Class Form3
    Property CarryValue1 As String
    Property CarryValue2 As String
    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label1.Text = (GetSingle(CarryValue1) + GetSingle(CarryValue2)).ToString
    End Sub
    Function GetSingle(s As String) As Single
        Dim v As Single
        If Single.TryParse(s, v) Then Return v
        Return 0
    End Function
End Class

Notice that I have used variations on variable names around 'CarryValue' you will probably need to use your own so you can keep track of what each is doing. Notice also, I have used Hide rather than Close as closing the Forms like that can End the application.


这篇关于转换值从窗口到另一个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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