其他的没法看,不过下面这句是肯定有问题的,应该连编译都过不了:
成都创新互联公司成立于2013年,是专业互联网技术服务公司,拥有项目网站建设、成都网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元工布江达做网站,已为上家服务,为工布江达各地企业和个人服务,联系电话:18982081108
Dim querystring As String = "update 班级信息表 set 班级名称="TextBox1.Text",班级编号="TextBox2.Text""
改称这样试试:
Dim querystring As String
querystring = "update 班级信息表 set 班级名称=" chr(39) TextBox1.Text chr(39) ", 班级编号=" chr(39) TextBox2.Text chr(39)
你这个问题是这样的呀:
因为你输入了10+10以后你为了结束是不是又打了个回车?那就是\n了,
但是这个\n现在被存在stdin的缓冲区里没有被取走,所以当你要输入Y或者N的时候,again将stdin的\n取走了,而没有给你输入的机会。
所以你应该是
printf("Please enter Y or N\n");
scanf("%c", again); //取走\n
scanf("%c",again); //记录Y或者N
这样就可以了。
不一样的,主要的关键字差不多,语法有一些有变化
vb.net与vb语法的一个很大不同——oop设计
例如
sMyString = Mid(sMyString,3,4)
现在,它可以被替换为:
sMyString = sMyString.substring(3,4)
VB.NET可选参数的默认值必须是一个常数表达式。
过程定义中跟在可选参数后的每个参数也都必须是可选的。
下面的语法显示带VB.NET可选参数的过程声明:
Sub sub name(ByVal parameter 1 As data type 1,
Optional ByVal parameter 2 As data type 2 = default value)
调用带VB.NET可选参数的过程
过程在运行时无法检测到给定的参数是否已被省略,或者调用代码是否已显式提供默认值。如果需要弄清楚这一点,可以设置一个不可能的值作为默认值。下面的过程定义了可选参数 office,并测试其默认值 QJZ 以查看它在调用中是否已被省略:
Visual Basic
Sub notify(ByVal company As String, Optional ByVal office As String = "QJZ")
If office = "QJZ" Then
Debug.WriteLine("office not supplied -- using Headquarters")
office = "Headquarters" End If
' Insert code to notify headquarters or specified office.
End Sub
如果可选参数是像 String 这样的引用类型,只要它不是该变量所预期的值,就可以使用 Nothing 作为默认值。
VB.NET可选参数和重载
定义带可选参数的过程的另一种方法是使用重载。如果有一个可选参数,可以定义过程的两个重载版本,一个接受此参数,另一个则不带参数。此方法随可选参数数目的增加而变得更复杂。然而,这样做的优点是可以完全确定调用程序是否提供了每个VB.NET可选参数。
#If...Then...#Else 指令
根据条件编译选定的 Visual Basic 代码块,需要有#Const 配对,一般要先用#Const 定义条件编译器常量
'以下是例子
Module Module1
#Const i = 60
Sub Main()
#If i 30 Then
Console.WriteLine("???") '如果用#Const定义了i,该句语句才会执行,假如用的是private i as integer=60定义,该语句不会被执行
#End If
End Sub
End Module
一委托:此示例演示如何将方法与委托关联然后通过委托调用该方法。
创建委托和匹配过程
创建一个名为 MySubDelegate 的委托。
Delegate Sub MySubDelegate(ByVal x As Integer)
声明一个类,该类包含与该委托具有相同签名的方法。
Class class1
Sub Sub1(ByVal x As Integer)
MsgBox("The value of x is: " CStr(x))
End Sub
End Class
定义一个方法,该方法创建该委托的实例并通过调用内置的 Invoke 方法调用与该委托关联的方法。
Protected Sub DelegateTest()
Dim c1 As New class1
' Create an instance of the delegate.
Dim msd As MySubDelegate = AddressOf c1.Sub1
' Call the method.
msd.Invoke(10)
End Sub
二、事件
下面的示例程序阐释如何在一个类中引发一个事件,然后在另一个类中处理该事件。AlarmClock 类定义公共事件 Alarm,并提供引发该事件的方法。AlarmEventArgs 类派生自 EventArgs,并定义 Alarm 事件特定的数据。WakeMeUp 类定义处理 Alarm 事件的 AlarmRang 方法。AlarmDriver 类一起使用类,将使用 WakeMeUp 的 AlarmRang 方法设置为处理 AlarmClock 的 Alarm 事件。
该示例程序使用事件和委托和引发事件中详细说明的概念。
示例
' EventSample.vb.
'
Option Explicit
Option Strict
Imports System
Imports System.ComponentModel
Imports Microsoft.VisualBasic
Namespace EventSample
' Class that contains the data for
' the alarm event. Derives from System.EventArgs.
'
Public Class AlarmEventArgs
Inherits EventArgs
Private _snoozePressed As Boolean
Private nrings As Integer
'Constructor.
'
Public Sub New(snoozePressed As Boolean, nrings As Integer)
Me._snoozePressed = snoozePressed
Me.nrings = nrings
End Sub
' The NumRings property returns the number of rings
' that the alarm clock has sounded when the alarm event
' is generated.
'
Public ReadOnly Property NumRings() As Integer
Get
Return nrings
End Get
End Property
' The SnoozePressed property indicates whether the snooze
' button is pressed on the alarm when the alarm event is generated.
'
Public ReadOnly Property SnoozePressed() As Boolean
Get
Return _snoozePressed
End Get
End Property
' The AlarmText property that contains the wake-up message.
'
Public ReadOnly Property AlarmText() As String
Get
If _snoozePressed Then
Return "Wake Up!!! Snooze time is over."
Else
Return "Wake Up!"
End If
End Get
End Property
End Class
' Delegate declaration.
'
Public Delegate Sub AlarmEventHandler(sender As Object, _
e As AlarmEventArgs)
' The Alarm class that raises the alarm event.
'
Public Class AlarmClock
Private _snoozePressed As Boolean = False
Private nrings As Integer = 0
Private stopFlag As Boolean = False
' The Stop property indicates whether the
' alarm should be turned off.
'
Public Property [Stop]() As Boolean
Get
Return stopFlag
End Get
Set
stopFlag = value
End Set
End Property
' The SnoozePressed property indicates whether the snooze
' button is pressed on the alarm when the alarm event is generated.
'
Public Property SnoozePressed() As Boolean
Get
Return _snoozePressed
End Get
Set
_snoozePressed = value
End Set
End Property
' The event member that is of type AlarmEventHandler.
'
Public Event Alarm As AlarmEventHandler
' The protected OnAlarm method raises the event by invoking
' the delegates. The sender is always this, the current instance
' of the class.
'
Protected Overridable Sub OnAlarm(e As AlarmEventArgs)
RaiseEvent Alarm(Me, e)
End Sub
' This alarm clock does not have
' a user interface.
' To simulate the alarm mechanism it has a loop
' that raises the alarm event at every iteration
' with a time delay of 300 milliseconds,
' if snooze is not pressed. If snooze is pressed,
' the time delay is 1000 milliseconds.
'
Public Sub Start()
Do
nrings += 1
If stopFlag Then
Exit Do
Else
If _snoozePressed Then
System.Threading.Thread.Sleep(1000)
If (True) Then
Dim e As New AlarmEventArgs(_snoozePressed, nrings)
OnAlarm(e)
End If
Else
System.Threading.Thread.Sleep(300)
Dim e As New AlarmEventArgs(_snoozePressed, nrings)
OnAlarm(e)
End If
End If
Loop
End Sub
End Class
' The WakeMeUp class has a method AlarmRang that handles the
' alarm event.
'
Public Class WakeMeUp
Public Sub AlarmRang(sender As Object, e As AlarmEventArgs)
Console.WriteLine((e.AlarmText + ControlChars.Cr))
If Not e.SnoozePressed Then
If e.NumRings Mod 10 = 0 Then
Console.WriteLine(" Let alarm ring? Enter Y")
Console.WriteLine(" Press Snooze? Enter N")
Console.WriteLine(" Stop Alarm? Enter Q")
Dim input As String = Console.ReadLine()
If input.Equals("Y") Or input.Equals("y") Then
Return
Else
If input.Equals("N") Or input.Equals("n") Then
CType(sender, AlarmClock).SnoozePressed = True
Return
Else
CType(sender, AlarmClock).Stop = True
Return
End If
End If
End If
Else
Console.WriteLine(" Let alarm ring? Enter Y")
Console.WriteLine(" Stop Alarm? Enter Q")
Dim input As String = Console.ReadLine()
If input.Equals("Y") Or input.Equals("y") Then
Return
Else
CType(sender, AlarmClock).Stop = True
Return
End If
End If
End Sub
End Class
' The driver class that hooks up the event handling method of
' WakeMeUp to the alarm event of an Alarm object using a delegate.
' In a forms-based application, the driver class is the
' form.
'
Public Class AlarmDriver
Public Shared Sub Main()
' Instantiates the event receiver.
Dim w As New WakeMeUp()
' Instantiates the event source.
Dim clock As New AlarmClock()
' Wires the AlarmRang method to the Alarm event.
AddHandler clock.Alarm, AddressOf w.AlarmRang
clock.Start()
End Sub
End Class
End Namespace