其他的沒法看,不過下面這句是肯定有問題的,應該連編譯都過不了:
成都創(chuàng)新互聯(lián)公司成立于2013年,是專業(yè)互聯(lián)網技術服務公司,擁有項目網站建設、成都網站設計網站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元工布江達做網站,已為上家服務,為工布江達各地企業(yè)和個人服務,聯(lián)系電話: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現(xiàn)在被存在stdin的緩沖區(qū)里沒有被取走,所以當你要輸入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)
現(xiàn)在,它可以被替換為:
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可選參數和重載
定義帶可選參數的過程的另一種方法是使用重載。如果有一個可選參數,可以定義過程的兩個重載版本,一個接受此參數,另一個則不帶參數。此方法隨可選參數數目的增加而變得更復雜。然而,這樣做的優(yōu)點是可以完全確定調用程序是否提供了每個VB.NET可選參數。
#If...Then...#Else 指令
根據條件編譯選定的 Visual Basic 代碼塊,需要有#Const 配對,一般要先用#Const 定義條件編譯器常量
'以下是例子
Module Module1
#Const i = 60
Sub Main()
#If i 30 Then
Console.WriteLine("???") '如果用#Const定義了i,該句語句才會執(zhí)行,假如用的是private i as integer=60定義,該語句不會被執(zhí)行
#End If
End Sub
End Module
一委托:此示例演示如何將方法與委托關聯(lián)然后通過委托調用該方法。
創(chuàng)建委托和匹配過程
創(chuàng)建一個名為 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
定義一個方法,該方法創(chuàng)建該委托的實例并通過調用內置的 Invoke 方法調用與該委托關聯(lián)的方法。
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
二、事件
下面的示例程序闡釋如何在一個類中引發(fā)一個事件,然后在另一個類中處理該事件。AlarmClock 類定義公共事件 Alarm,并提供引發(fā)該事件的方法。AlarmEventArgs 類派生自 EventArgs,并定義 Alarm 事件特定的數據。WakeMeUp 類定義處理 Alarm 事件的 AlarmRang 方法。AlarmDriver 類一起使用類,將使用 WakeMeUp 的 AlarmRang 方法設置為處理 AlarmClock 的 Alarm 事件。
該示例程序使用事件和委托和引發(fā)事件中詳細說明的概念。
示例
' 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