可以。
扩展:
Visual Studio是一款世界主流的编程开发软件平台,可以编写VB.NET、C++、C#、C、Python、HTLM、JSP、PHP等很多种编程语言,支持很多种语言的运行库。
那我们如何用VS2017编写VB.NET语言呢?
首先,先下载支持VB的运行库。打开VS2017Community,点击“通过Windows平台开发”,安装。
打开VS2017,点右上角的“文件”→“新建”→“项目”。
就到了新建项目的窗口,这时你可以选择各种编程语言进行编程。点击Visual Basic,选择“Windows窗体应用”,点“确定”即可。
单击窗体里的“工具栏”,可进入选择控件的页面。
双击控件进入代码输入框,我们可以在里面输入VB.NET的代码。
'//首先你需要在Form1上面创建一个名称为Text1的TextBox'//一个名为Command1的按钮和一个名为Command2的按钮
'//一个名为Picture1的PictureBox
'//然后再创建一个Form2,上面必须有一个名为Text1的TextBox
'//Form2上面也要有一个名为Command1的按钮和一个名为Command2的按钮
'//然后将下面的代码找对地方复制过去就行了
'//再添加一个Form3
'//关于Tab顺序的问题,你自己去调每个可 *** 作控件的TabIndex
'//Form2的TextBox需要填上完整路径比如:C:\桌面\text_XXXX.txt
'//另外如果可以能不能留下你的邮箱······ 这样发真的很麻烦···
'////////////////////////////////////////////////////////////////////////////////////////////////////////////Form1
Dim teum As String
Option Explicit
Private Sub Check1_Click(index As Integer) '//检测点击的哪一个复选框
If p = True Then
p = False
Exit Sub
End If
If Check1(index).Value = 1 Then
teum = Text1.text '//记录未排序的结果
Else
Text1.text = teum '//将未排序的结果返还给文本框
model = 0
End If
Select Case index
Case 1
Call click(Check1(1))
model = 1
Case 2
Call click(Check1(2))
model = 2
End Select
End Sub
Private Sub Command1_Click() '//生成乘法表(这个地方推荐你改改··· 我不知道你打算把这个打印出来的乘法表放哪里···)
If checkNumLen(Form1.Text1.text) = False Then
Exit Sub
End If
Load Form3
End Sub
Private Sub Command2_Click() '//打开生成文件窗口,并将其设置为模式窗口
Form2.Show vbModal
End Sub
Private Sub Form_Load()
model = 0
End Sub
Private Sub Text1_Change()
Text1.BackColor = vbWhite
End Sub '/////////////////////////////////////////////////////////////////////////////////////////////////////////////Form2
Option Explicit
Private Sub Command1_Click()
Dim file As String
Dim s As String
Dim txt As String
p = True
If Form1.Text1.text = "" Then
MsgBox "被写入的数据不能为空!", vbCritical, "提示:"
p = False
Exit Sub
ElseIf checkNumLen(Text1.text) = False Then
Form1.Text1.BackColor = &HC0C0FF
MsgBox "被写入数据不符合条件!", vbCritical, "提示:"
p = False
Exit Sub
End If
If model = 0 Then
s = "【未排序的】"
ElseIf model = 1 Then
s = "【从小到大排序的】"
ElseIf model = 2 Then
s = "【从大到小排序的】"
End If
If Text1.text = "" Then
MsgBox "请输入文件路径!", vbCritical, "提示:"
p = False
ElseIf Dir(Text1.text) = "" Then
MsgBox Text1.text & vbCrLf & "文件不存在!", vbExclamation, "提示:"
p = False
Else
file = Text1.text
txt = Form1.Text1.text
If MsgBox("确定要写入当前数据?" & vbCrLf & "当前数据是" & s, vbExclamation + vbOKCancel, "提示:") = vbOK Then
Open file For Output As #1 '//打开目标文件,访问方式:顺序访问
Write #1, Val(txt)
Close #1 '//关闭目标文件
MsgBox "写入完毕!", vbInformation, "提示:"
End If
End If
End Sub
Private Sub Command2_Click()
Dim file As String
Dim txt As String
Dim txtread As String
If Text1.text = "" Then
MsgBox "请输入文件路径!", vbCritical, "提示:"
Exit Sub
ElseIf Dir(Text1.text) = "" Then
MsgBox Text1.text & vbCrLf & "文件不存在!", vbExclamation, "提示:"
Exit Sub
Else
file = Text1.text
txt = Form1.Text1.text
Open file For Input As #1 '//打开目标文件,访问方式:顺序访问
Do
Line Input #1, txtread
txt = txt & txtread
Loop Until EOF(1) = True
Close #1 '//关闭目标文件
End If
If txt = "" Then
MsgBox "文件为空!", vbExclamation, "提示:"
ElseIf IsNumeric(txt) = False Then
MsgBox "文件内包含非法字符", vbCritical, "提示:"
ElseIf Len(txt) < 3 Then
MsgBox "文件内容不足三位数字", vbCritical, "提示:"
ElseIf IsNumeric(Mid(txt, 3, 1)) = False Then
MsgBox "文件内容第3位不是数字!", vbCritical, "提示:"
Else
MsgBox "文件符合要求!", vbInformation, "提示:"
End If
End Sub '///////////////////////////////////////////////////////////////////////////////////////////////////////////////Form3
Option Explicit
Private Sub Form_Load()
Dim num As Integer
Dim i As Integer
Dim j As Integer
Dim space As String
Show
num = Val(Mid(Form1.Text1.text, 3, 1)) Mod 2
If num = 0 Then
For i = 1 To 9
For j = 1 To i
If j = 2 And i = 4 Or j = 2 And i = 3 Then
space = " "
Else
space = " "
End If
Print j & "×" & i & "=" & j * i & space
Next j
Next i
Else
For i = 9 To 1 Step -1
For j = 1 To i
If j = 2 And i = 4 Or j = 2 And i = 3 Then
space = " "
Else
space = " "
End If
Print j & "×" & i & "=" & j * i & space
Next j
Next i
End If
End Sub '///////////////////////////////////////////////////////////////////////////////模块文件
Option Explicit
Public p As Boolean
Public model As Integer
Public Function sort(content As String, style As Integer) '//排序函数,content 必选参数,需要排序的内容;style 必选参数,用于规定排序方式
Dim a(9) As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim t As Integer
For i = 0 To Len(content) - 1 '//给排序数组用赋值
a(i) = Val(Mid(content, i + 1, 1))
Next i
'//排序方法:选择排序
If style = 1 Then '//从小到大
For j = 0 To Len(content) - 2
For k = j + 1 To Len(content) - 1
If a(j) > a(k) Then
t = a(j)
a(j) = a(k)
a(k) = t
End If
Next k
Next j
ElseIf style = 2 Then '//从大到小
For j = 0 To Len(content) - 2
For k = j + 1 To Len(content) - 1
If a(j) < a(k) Then
t = a(j)
a(j) = a(k)
a(k) = t
End If
Next k
Next j
End If
For i = 0 To Len(content) - 1 '//排序将结果交给文本框
sort = sort & a(i)
Next i
End Function
Public Function checkNumLen(content As String) '//条件检测函数,content 必选参数,需要排序的内容
Dim i As Integer
If Len(Form1.Text1.text) < 8 Or Len(Form1.Text1.text) > 10 Then
If p = False Then
Form1.Text1.BackColor = &HC0C0FF
MsgBox "请输入8~10位的正整数", vbCritical, "提示:"
model = 0
Form1.Text1.SetFocus
p = True
For i = 1 To Form1.Check1.UBound
Form1.Check1(i).Value = 0
Next i
p = False
End If
Else
checkNumLen = True
End If
End Function
Public Function click(Obj As Object) '//点击检测函数
Dim i As Integer
If checkNumLen(Form1.Text1.text) = False Then
Exit Function
Else
If Obj.Value = 1 Then
For i = 1 To Form1.Check1.UBound
If i <> Obj.index Then
Form1.Check1(i).Value = 0
End If
Next i
Form1.Text1.text = sort(Form1.Text1.text, Obj.index) '//调用排序函数
End If
End If
Form1.Text1.SetFocus
Form1.Text1.SelStart = Len(Form1.Text1.text)
End Function
要在VS中使用VB,您需要安装Visual Studio,它是一个集成开发环境(IDE),可以提供强大的工具,帮助您开发和调试VB应用程序。Visual Studio还可以让您使用其他语言,如C#,C++和F#,所以它可以为您提供一个强大的工具,无论您想要创建什么样的应用程序。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)