vb.net - 输入字符串的格式不正确 文本框 vb Visual Basic 2010
问题描述
我不知道该做什么了,我只是按照一个教程来确保我输入正确?但它一直说输入字符串的格式不正确,我试图总计饮料请帮助我已经第三次重新启动这个项目
解决方案
您正在尝试将空字符串转换为 Double,但这是不可能的。您应该:
这是使用后者的示例:
Dim cider_soda As Double
If (Not Double.TryParse(tx1.Text, cider_soda)) Then
MessageBox.Show("The value in tx1 cannot be converted to a Double.")
End If
如果您想在文本为空的情况下进行具体区分,请使用 String.IsNullOrWhitespace (文档):
Dim cider_soda As Double
If (String.IsNullOrWhitespace(tx1.Text)) Then
MessageBox.Show("The value in tx1 cannot be empty.")
ElseIf (Not Double.TryParse(tx1.Text, cider_soda)) Then
MessageBox.Show("The value in tx1 cannot be converted to a Double.")
End If
推荐阅读
- python - 有人可以解释一下 x[0][0][0] 是如何工作的,其中 x 是 string ,比如 python 中的 x =“This is text file”?
- windows - 升级时根据活动文件类型关联设置任务值
- confluence-rest-api - 用于在 Cloud Confluence 上创建空间的 Python 脚本
- tensorflow - 如何使用 tensorboard 以 Eager 模式可视化 tensorflow 1.15 中的网络图?
- azure-devops - 概述(列出)关闭一个订阅中具有相同域名的组织
- angular - 角 - 茉莉花:由于间谍而无法测试方法
- python - Python/SQL 错误,错误未注册
- apt - 可重现的 Debian 安装
- node.js - .save() 函数不保存所有信息
- snowflake-cloud-data-platform - Snowflake 替代 MYSQL FORMAT 函数