0
저는 VB에 익숙하지 않습니다. 다른 밤에 수업에서 만든 BASIC256 프로그램을 확장하려고합니다. 성공적으로 응용 프로그램의 콘솔 버전 (아래 코드) 및 Windows 폼 버전을 만들었습니다. 텍스트 상자에 오류 검사를 만드는 데 도움이 필요합니다. TextBox1 빈 필드를 방지하려면 찾고 있어요. TextBox3의 경우 소수점 이하 2 자리 이하의 양수가 필요합니다. 또한 코드가 지나치게 복잡하다는 것을 알고 있으며, 어떤 제안도 크게 감사 할 것입니다.여러 텍스트 상자 필드에 대한 오류 검사 만들기 VB20010
콘솔 코드
Module Module1
Sub Main()
Dim check_num(10) As String
Dim description(10) As String
Dim amount(10) As Decimal
Dim total_bal(10) As Decimal
Dim pointer As Integer
Dim x As Integer
pointer = 0
start:
Console.Clear()
Console.WriteLine("Enter check number for a check")
Console.WriteLine("Enter B for a balance inquiry")
Console.WriteLine("Enter C for a bank charge")
Console.WriteLine("Enter D for a deposit")
Console.WriteLine("Enter F if you are finished")
Console.WriteLine("Enter choice: ")
check_num(pointer) = Console.ReadLine()
Select Case check_num(pointer)
Case "B", "b"
x = 0
For x = 0 To 10
If total_bal(x) = 0 Then
x = x - 1
If x < 0 Then
x = 0
End If
Else
If total_bal(x) <> 0 Then
GoTo cont
End If
End If
Console.WriteLine("Balance is: {0}", total_bal(x))
Console.WriteLine("Press any key to continue...")
Console.ReadKey(True)
GoTo start
cont:
Next x
Case "D", "d"
x = 0
For x = 0 To 10
If total_bal(x) = 0 Then
Console.WriteLine("Amount of deposit: ")
amount(x) = Console.ReadLine()
Console.WriteLine("Descripiton of transaction: ")
description(x) = Console.ReadLine()
If x = 0 Then
total_bal(x) = total_bal(x) + amount(x)
Else
total_bal(x) = total_bal(x - 1) + amount(x)
End If
GoTo start
End If
Next x
Case "F", "f"
End
Case Else
x = 0
For x = 0 To 10
If total_bal(x) = 0 Then
Console.WriteLine("Amount of debit: ")
amount([x]) = Console.ReadLine()
Console.WriteLine("Descripiton of transaction: ")
description$([x]) = Console.ReadLine()
If x = 0 Then
total_bal(x) = total_bal(x) - amount(x)
Else
total_bal(x) = total_bal(x - 1) - amount(x)
End If
GoTo start
End If
Next x
End Select
GoTo start
End Sub
End Module
Windows는 특정 텍스트 상자에 사용 어떤 버튼에 체크를 추가, 코드 TextBox1에 대한
Public Class Form1
Dim check_num(10) As String
Dim description(10) As String
Dim amount(10) As Decimal
Dim total_bal(10) As Decimal
Dim pointer As Integer = 0
Dim x As Integer
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
Label3.Visible = True
TextBox3.Visible = True
Label2.Visible = True
TextBox1.Visible = True
Button1.Visible = True
End If
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
Label3.Visible = True
TextBox3.Visible = True
Label2.Visible = True
TextBox1.Visible = True
Button1.Visible = True
End If
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
If RadioButton3.Checked = True Then
Label3.Visible = True
TextBox3.Visible = True
Label2.Visible = True
TextBox1.Visible = True
Button1.Visible = True
End If
End Sub
Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
If RadioButton4.Checked = True Then
Label3.Visible = False
TextBox3.Visible = False
Label2.Visible = False
TextBox1.Visible = False
Button1.Visible = False
End If
x = 0
For x = 0 To 10
If total_bal(x) = 0 Then
x = x - 1
If x < 0 Then
x = 0
End If
GoTo Line1
End If
Next x
Line1:
Label4.Visible = True
TextBox2.Visible = True
TextBox2.Text = total_bal(x).ToString("n2")
MessageBox.Show("Press OK to clear the screen.")
Label4.Visible = False
TextBox2.Visible = False
RadioButton4.Checked = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButton1.Checked = True Then
x = 0
For x = 0 To 10
If total_bal(x) = 0 Then
If TextBox3.Text <> String.Empty Then
If Not Decimal.TryParse(TextBox3.Text, amount(x)) Then
MessageBox.Show("Please use 12345.67 format only.")
TextBox3.Focus()
Else
amount(x) = TextBox3.Text
description(x) = TextBox1.Text
GoTo Line1
End If
End If
End If
Next x
Line1:
If x = 0 Then
total_bal(x) = total_bal(x) - amount(x)
Else
total_bal(x) = total_bal(x - 1) - amount(x)
End If
MessageBox.Show("Check Number " & description(x) & " was withdrawn" & vbCrLf & "in the amount of $" & amount(x))
End If
If RadioButton2.Checked = True Then
x = 0
For x = 0 To 10
If total_bal(x) = 0 Then
If TextBox3.Text <> String.Empty Then
If Not Decimal.TryParse(TextBox3.Text, amount(x)) Then
MessageBox.Show("Please use 12345.67 format only.")
TextBox3.Focus()
Else
amount(x) = TextBox3.Text
description(x) = TextBox1.Text
GoTo Line2
End If
End If
End If
Next x
Line2:
If x = 0 Then
total_bal(x) = total_bal(x) - amount(x)
Else
total_bal(x) = total_bal(x - 1) - amount(x)
End If
MessageBox.Show("A fee for " & description(x) & " was withdrawn" & vbCrLf & "in the amount of $" & amount(x))
End If
If RadioButton3.Checked = True Then
x = 0
For x = 0 To 10
If total_bal(x) = 0 Then
If TextBox3.Text <> String.Empty Then
If Not Decimal.TryParse(TextBox3.Text, amount(x)) Then
MessageBox.Show("Please use 12345.67 format only.")
TextBox3.Focus()
Else
amount(x) = TextBox3.Text
description(x) = TextBox1.Text
GoTo Line3
End If
End If
End If
Next x
Line3:
If x = 0 Then
total_bal(x) = total_bal(x) + amount(x)
Else
total_bal(x) = total_bal(x - 1) + amount(x)
End If
MessageBox.Show("A deposit for " & description(x) & " was made" & vbCrLf & "in the amount of $" & amount(x))
End If
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
Label3.Visible = False
TextBox3.Visible = False
Label2.Visible = False
TextBox1.Visible = False
Button1.Visible = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Response As Integer
Response = MessageBox.Show("Do you really want to exit?", "", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Response = vbYes Then
Me.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
Array.Clear(check_num, 0, check_num.Length)
Array.Clear(description, 0, description.Length)
Array.Clear(amount, 0, amount.Length)
Array.Clear(total_bal, 0, total_bal.Length)
End Sub
End Class