【问题标题】:How do I use "Mod" command for this program我如何为这个程序使用“Mod”命令
【发布时间】:2015-12-28 22:55:30
【问题描述】:

这是我正在尝试编写代码的程序,但我只是不知道如何显示第一个数字和第二个数字。

Public Class Program

Private Sub btnDigit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDigit.Click
    Dim I As Decimal
    Dim digits As Decimal

    I = Val(Me.txtinput.Text)

    digits = 

    Me.lblanswerfirstdigit.Text =
    Me.lblanswerlastdigit.Text = 
End Sub

我尽了最大的努力,但我还不擅长。

【问题讨论】:

  • 想做什么? ,为什么MOD?如果你只想得到第一个和第二个数字..你可以使用vb.net的LEFTMID函数
  • 那我该怎么做呢?我是 VB 新手,不知道如何应用 LEFT 和 MID 函数 @JapzDivino
  • 在答案中查看我的示例
  • 为什么你的标签叫“lastdigit”,但用户界面显示的是第二个数字?

标签: vb.net vba visual-studio


【解决方案1】:

做这样的事情

lblanswerfirstdigit.Text = txtinput.Text.Chars(0) 'get the 1st char
lblanswerlastdigit.Text = txtinput.Text.Chars(1)  'get the 2nd char

建议使用 Try...Catch 块(或更简单的 If 检查),以防止出现 1 位数字时出错

【讨论】:

    【解决方案2】:

    我认为您不需要使用 MOD ,因为该函数用于执行模除。

    如果您想获得第一个,最后一个甚至是中间。你可以使用vb.net的LEFT, RIGHT, and MID函数

        LEFT(StringHere, LenghtHere)
        RIGHT(StringHere, LenghtHere)
        MID(StringHere, StarHere,LenghtHere)
    

    类似:

        Me.lblanswerfirstdigit.Text = LEFT(Me.txtinput.Text, 1) 'get the first
        Me.lblanswerlastdigit.Text = RIGHT(Me.txtinput.Text, 1) 'get the last
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-18
      • 2015-09-06
      • 2017-10-28
      • 2017-07-10
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      相关资源
      最近更新 更多