扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
Vb不是人机对话窗口,而是编程工具,可以编写代码进行调试执行或者生成可执行文件。
创新互联专注于清河企业网站建设,成都响应式网站建设,商城网站建设。清河网站建设公司,为清河等地区提供建站服务。全流程定制网站制作,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务
用Visual Studio .Net开发"Hello World!"程序:
我们知道"Hello World"一般是命令行程序,而这种程序在Visual Studio .Net中被称为"控制台程序"。下面是Visual Studio .Net编写控制台"Hello World!"程序的具体步骤:
(1)、启动Visual Studio .Net。
(2)、选择菜单【文件】|【新建】|【项目】后,弹出【新建项目】对话框。
(3)、将【项目类型】设置为【Visual Basic项目】。
(4)、将【模板】设置为【控制台应用程序】。
(5)、在【名称】文本框中输入【Hello World】。
(6)、在【位置】的文本框中输入【E:VS.NET项目】,然后单击【确定】按钮,则Visual Studio .Net会按照上面设定的参数创建一个控制台应用程序项目,具体如图01所示。
图01:"Hello World"控制台程序的【新建项目】界面
(7)、在【解决方案资源管理器】窗口中,双击Module1.vb文件,进入Module1.vb文件的编辑界面。
(8)、Visual Studio .Net已经为产生Main()函数。在系统创建的Main()函数中加入下面一行代码就可以了:
Console.WriteLine ("Hello World!")
(9)、选择【文件】|【保存Module1.vb】菜单或者按快捷键Ctrl+S,保存所做的修改。
(10)、此时单击快捷键Ctrl+F5运行程序就可以得到图02所示运行界面:
My.Computer.Audio.Play("SoundFile.wav")
SoundFile.wav是你要播放的声音文件的路径
楼主的代码看起来像是vbs,仔细调阅了很多资料,在vbs中无法实现复制文件到剪切板的功能。不过在vb6中是可以实现的,需要依靠一些api函数来完成工作。
建立一个按钮Command1,以下范例是将"C:\a.txt"复制到剪切板,要测试请先建立这个文件。
Option Explicit
Private Declare Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Const GMEM_MOVEABLE = H2
Private Const GMEM_ZEROINIT = H40
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Const CF_HDROP = HF
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type DROPFILES
pFiles As Long
pT As POINTAPI
fNC As Long
fWide As Long
End Type
Private Sub Command1_Click()
Dim FileName As String
FileName = "C:\a.txt"
If Dir(FileName) = "" Then Exit Sub
FileName = FileName vbNullChar vbNullChar
Call FileToClipboard(FileName)
End Sub
Private Sub FileToClipboard(ByVal FileName As String)
Dim dFiles As DROPFILES
Dim hMem As Long, MemPtr As Long, Len1 As Long, Len2 As Long
If OpenClipboard(Me.hWnd) = 0 Then Exit Sub
Call EmptyClipboard
Len1 = Len(dFiles)
Len2 = LenB(StrConv(FileName, vbFromUnicode))
hMem = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len1 + Len2)
MemPtr = GlobalLock(hMem)
dFiles.pFiles = Len1
Call CopyMemory(ByVal MemPtr, dFiles, Len1)
Call CopyMemory(ByVal (MemPtr + Len1), ByVal FileName, Len2)
Call GlobalUnlock(hMem)
Call SetClipboardData(CF_HDROP, hMem)
Call CloseClipboard
End Sub
代码已测试。
一、测试需要的INI文件。名称为“setinfo.ini”,存放路径为你解决方案里“Bin“文件夹的”Debug“文件夹里。
内容:
[Location]
pnlTime.Location.X=787
pnlTime.Location.Y=0
[TopMost]
Top=True
二、操作INI文件的类。新建一个类,类中内容为:
Public Class Class1
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Int32, _
ByVal lpFileName As String _
) As Int32
End Class
三、界面代码:
Imports System.IO 'for path
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
getINI()
End Sub
Private Sub getINI()
Dim iniclass As New Class1 '
Dim myBf As String 'get set_info 开辟存储的内存
myBf = New String(CChar(""), 256)
Dim myFN As String '配置文件的文件路径
myFN = Path.Combine(My.Application.Info.DirectoryPath, "setinfo.ini")
Dim myAN As String 'Application_NAME,也是Section名称
myAN = Me.TextBox1.Text
Dim myKN As String 'KEY_NAME,关键字名称
myKN = Me.TextBox2.Text
Class1.GetPrivateProfileString(myAN, myKN, "", myBf, myBf.Length, myFN) '调用读取INI文件的操作
TextBox3.Text = Microsoft.VisualBasic.Left(myBf, InStr(myBf, Chr(0)) - 1) '截取有用部分,有必要
End Sub
End Class
四、测试截图如下
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流