注册 登录
编程论坛 VB.NET论坛

求教inputbox和msgbox的问题

fenghaofan 发布于 2016-03-31 12:27, 4373 次点击
我用inputbox输入内容,判断值是否为空,若空,则msgbox警告不能为空值。接下来的步骤是我想msgboxresult为retry,则返回到inputbox,若为cancel则exit sub
程序代码:

dim input as string
input= inputbox"请输入内容"
if input ="" then
msgbox("内容不能为空"5)
..........
end if

......省略号部分我再网上找了个select case的语句,
case 0     msgboxresult.retry=true
input= inputbox("请输入内容")
case 1   msgboxresult.cancle=true
 exit sub


请高手帮我看看能不能改进下,总感觉比较繁琐。特别是红字的部分不能用什么函数直接返回到inputbox界面。虚心请教各位,谢谢
3 回复
#2
xiangyue05102016-04-01 16:22
Case后面必然会有一句代码的,除非是不执行任何操作。不清楚你想要精简到什么层度
另外,你这段是retry之后重新输入,还是需要判断的,用input= inputbox("请输入内容")就不能判断了
建议改成

dim input as string
TRYAGAIN:
input= inputbox("请输入内容")

……
case 0     msgboxresult.retry=true
Goto TRYAGAIN
case 1   msgboxresult.cancle=true
 exit sub
#3
fenghaofan2016-04-01 21:10
程序代码:
Dim statusbox As String
        statusbox = InputBox("请扫描二维码", "二维码字符串输入框", 1)
        If statusbox = "" Then
            Select Case MsgBox("请输入有效的二维码字符串", MsgBoxStyle.OkCancel)
                Case MsgBoxResult.Ok
                    GoTo 。。。。。。
                Case MsgBoxResult.Cancel
                    Exit Sub
            End Select

        End If

我该怎么修改才能goto到inputbox让重新输入呢?
#4
不说也罢2016-04-02 19:22
二楼和你讲得很清楚啦:
程序代码:

        Dim statusbox As String
TRYAGAIN:
        statusbox = InputBox("请扫描二维码", "二维码字符串输入框", 1)
        If statusbox = "" Then
            Select Case MsgBox("请输入有效的二维码字符串", MsgBoxStyle.OkCancel)
                Case MsgBoxResult.Ok
                    GoTo TRYAGAIN
                Case MsgBoxResult.Cancel
                    Exit Sub
            End Select

        End If



当然也可以写成其他形式
1