VBset focusget focus𣿸ôãʲôã

˰ɣӦgotfocus
setfocus ǷҲʹĳý㣬
gotfocus ¼Ҳǵĳýʱᷢʲô¡
ӣ
Text1.SetFocus
.....
Private Sub Command1_GotFocus()
   .....
End Sub 


ҪC̵ǰļ½һΪAbc.txt˳ļӦʹ_____䣺
[A] Open "C:Abc.txt" For Output As #1
[B] Open "C:\Abc.txt" For Append As #1
(˵һԵԭ) 

Aȷ
䶼Խ˳ļAC̵ǰļнļBC̸Ŀ¼ļ


vbȡ α⿼⣩
30*12=360ļҪÿļȡһrݣrÿļͬ
31302928·ݺһ̬飬ʲô
vbȡ360ļеırʱ˳洢һĵУ1971-2000
30ݣʵ

Щļ·أ1·ݵļ31еģôÿζȡļ
һмɡǣôÿһܵ໥ִɣ翪ͷַ
ڣôͿҿͷ2ַתֵУֻСϼơСơ֮ġ
֮ҪҵırλܵиͬɣˣĻϵ
Ҳû취ϵ˵ʲôVB ^_^  
һ£ʵҪ֪ĳжҲѣ
֪19712ж
ts=day(cdate("1971-3-1")-1)
˼·ǣһµһټһ죬µһ.... 


vb checklistboxģ

òVBûĿؼɣListBoxȻStyleΪ1-CheckBox
ǲǷҪ


ʣôʮƵ1VBָʽΪ01ллң

ֻʾʱõ01Ч
Private Sub Command1_Click()
   Dim n As Byte
   n = Val(InputBox("һ015"))
   MsgBox "תΪǰ0ʮ" & Right("0" & Hex(n), 2)
End Sub
 0-15־ͻʾΪ
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F


VBıȡSQLпֵ
RT,ȡSQLݿеһֶ,myRsһ¼.
Text1.Text = myRs(2)
ܶ,myRs(2)Ϊֵʱ,"ʵʱ94,ЧʹNULL".ôѽ?
ԭΪеĿֵ,ıҲʾΪֵ. 

Text1.Text = "" & myRs(2)
Ͳ 
ʵõĽ֮κNullֵԶתΪַ򲻻κӰ
죬κпܳNullֵĵطʹãͿԲùݿֶǷNull
ֵˣҲʹж䣬ֵֶΣ val("0" & myRs(2)) ֱӰNullֵ
ת0㣬Ӱ죬ΪΪֵ0123=123


VBıʧȥ󣬼ǲֵҲãҲãУ
ʾرСΪţҲҪ

Private Sub Text1_LostFocus()
   If IsNumeric(Text1.Text) Then
      MsgBox ""
   Else
      MsgBox ""
   End If
End Sub


VBļϵͳؼʵԶ£
˵ļбؼдa.txtļȻб༭Ϊb.txtļͬһ·£
ʱļбвԶʾb.txtļĴڣֻѡһ·ص·±
ļܹʾʿʹʲôʵԶʾôлл 

ڱb.txtļˢһļб򼴿ɣ
File1.Refresh


VB־!!!...
λְæ VBһ,һطס,ܲ...Ҳԭ...
VBdataؼ,ʾaccessѧ༶ȵ,û,Ȼôд
ť¼,(,ɾ,,ѯ¼),Ӽ¼ť,ȷʱ  ,
ԵʹЧ
Private Sub OkBttn_Click()
Data1.Recordset = Update(һ)
Ӱť
Private Sub AddBttn_Click()
  Data1.Recordset.AddNew
  Txh.SetFocus
  AddBttn.Visible = 0
  DelBttn.Visible = 0
  EditBttn.Visible = 0
  OkBttn.Visible = -1
  CancelBttn.Visible = -1
End Sub
ȷť
Private Sub OkBttn_Click()
Data1.Recordset = Update
AddBttn.Visable = -1
DelBttn.Visable = -1
EditBttn.Visable = -1
OkBttn.Visable = 0
CancelBttn.Visable = 0
End Sub
(ťӼ¼,ɾ¼,޸ļ¼,ȷ,ȡ) 
ⲹ䣺"Ӽ¼ť",˵гʱ 
Ϊǲ Data1.Recordset.Update 
гʱӵļ¼ȷ ʾ δҵ Ա

UpdateRecordsetķʹøʽǣ
Data1.Recordset.Update
Data1.Recordset = UpdateǰUpdateΪˣνġԵʹЧ˼ 
شVisable ҪΪ Visible


һVB   һû110루abc 
MSGBOX "û" ȷ MSGbox"ӭϵͳ"ڶ壨LOGO ʾһ
ͼƬ 5 Ǹ򵥵гμ^0^  лл

 form1 form2 form3
form1textһcommand
Private Sub Command1_Click()
   If Text1.Text = "110" And Text2.Text = "abc" Then
      MsgBox "ӭϵͳ"
      Form2.Show
      Unload Me
   Else
      MsgBox "û"
   End If
End Sub
form2ͼƬٷһtimerIntervalΪ5000
Private Sub Timer1_Timer()
   Form3.Show
   Unload Me
End Sub


vbshellcmd..cmdҲõӢ""ŵ..shellҲҪ""ţ
Ļvbʱͻᷢ..Ӧΰshell桰ŵĻɱĺѽ
Чһ
Ҫܲ滻ɱķѽ

"ַҪ"ţ"Ŵ棬
msgbox "abc""def""ghi"  ʾ  abc"def"ghi
 msgbox "abc"def"ghi" Ǵ


ͼ Ҫʵֽpicture1F϶picture2 е  ͼζpictureԼص
Ǵͽ...ܰҰѳд  лл

Ĵ԰Picture1ϵλã
Dim xx As Single, yy As Single
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   xx = X: yy = Y
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   If Button = 1 Then Picture1.Move Picture1.Left + X - xx, Picture1.Top + Y - yy
End Sub


VBѭ
Private Sub Command1_Click()
  Dim Path As String
  i = i - 1
  If i <= 1 Then i = 3
  Path = App.Path & "\Pic\00" & i & ".jpg"
  Image1.Picture = LoadPicture(Path)
End Sub
Private Sub Command2_Click()
Dim Path As String
   i = i + 1
Path = App.Path & "\Pic\00" & i & ".jpg"
   Image1.Picture = LoadPicture(Path)
   If i >= 3 Then i = 1
   End Sub
Ŀ:
ʵ3ͼƬѭţСһšһšť
Ŀǰ޷ʵѭô޸ģ

ΪiǾֲÿεťʱiԶʼΪ0ҪΪȫֱ
ҲӳⲿһУ
dim i as long
⣬
If i <= 1 Then i = 3
ҪΪ
If i < 1 Then i = 3
001.jpgͼƬʾġ
If i >= 3 Then i = 1
ҪΪ
If i > 3 Then i = 1
Ҫŵ
i = i + 1
棬i=3ʱi+1=4Ϊ004.jpg
£
Dim i As Long
Private Sub Command1_Click()
   Dim Path As String
   i = i - 1
   If i < 1 Then i = 3
   Path = App.Path & "\Pic\00" & i & ".jpg"
   Image1.Picture = LoadPicture(Path)
End Sub
Private Sub Command2_Click()
   Dim Path As String
   i = i + 1
   If i > 3 Then i = 1
   Path = App.Path & "\Pic\00" & i & ".jpg"
   Image1.Picture = LoadPicture(Path)
End Sub


VBtxtUrl.Textгְmapʵľ ôͰtxtUrl.Textгְmapľ 浽c1.txt
ǰ᣺txtUrl.Textлֶ
ĿģtxtUrl.Textгְmapʵľ ôͰtxtUrl.Textгְmapľ 浽c1.txt

ҪԶеĻҪֶťģҪԶУҪһTimerؼintervalΪ50005һΣҲԼ
Private Sub Timer1_Timer()
   If InStr(txtUrl.Text, "map") > 0 Then
      Open "c:\1.txt" For Append As #1
      Print #1, txtUrl.Text
      Close #1
      txtUrl.Text = ""
   End If
End Sub
⣬ǼٶtxtUrlǵıǶı򣬶ҪеĳлĳУ£
Private Sub Timer1_Timer()
   Dim s() As String, i As Long
   Open "c:\1.txt" For Append As #1
   s = Split(txtUrl.Text, vbCrLf)
   For i = 0 To UBound(s)
      If InStr(s(i), "map") > 0 Then
         Print #1, s(i)
      End If
   Next
   Close #1
   txtUrl.Text = ""
End Sub 


VB 򵥴
VBͼ
*********  *
 *******  ***
  *****  *****
   ***  *******
    *  *********
 for next 

Dim i As Long
For i = 1 To 5
   Print Space(i - 1) & String(11 - i * 2, "*") & Space(1) & String(i * 2 - 1, "*")
Next


vb νȡַ֮
2 Model  '3'  '5axis_with_holes'
ȡ'3'ڵ 3  '5axis_with_holes' ڵ 5axis_with_holes֣

Private Sub Command1_Click()
   Dim a As String, i As Long, j As Long
   a = "2 Model  '3'  '5axis_with_holes'"
   i = InStr(a, "'")
   j = InStr(i + 1, a, "'")
   MsgBox Mid(a, i + 1, j - i - 1) 'ʾ 3
   i = InStr(j + 1, a, "'")
   j = InStr(i + 1, a, "'")
   MsgBox Mid(a, i + 1, j - i - 1) 'ʾ 5axis_with_holes
End Sub


˿ؼbackcolorֵΪvbRed֪ʱֵǶ٣ֵָ&H8000000F&
ʽġʲô취ȡֵ

Text1.BackColor = vbRed
MsgBox "&H" & Right(String(8, "0") & Hex(Text1.BackColor), 8) & "&"
ɫֵ80ͷWindowsϵͳԤɫɫťɫȵȣ
۵öġ00ͷʵɫλɫRGBʮֵ


vbһС,Ұҿ˰
ұЩ
Data1.RecordSource = "select * from ռ¼ where " & Format(Data1.Recordset(""), "m") 

Data1.RecordSource = "select * from [ռ¼] where month([])=month(Now())"
SQLȫġ⣬SQLпֱʹô󲿷VBFormat()month()
Now()ȵȡУݿеıֶǺֵģü[]


ȥVB MonthViewؼ
vbͨıMonthViewؼȡʱ䣬Ѿʵˣǵе
ʱ򣬵ҵһıֲѡʱǲʱʱʲô
ȥMonthViewؼǰǲͨѡʱ䡣

MonthViewؼDTPickerؼ⣬Ҳõıı취


listboxѡһһlistboxÿӦֵ ôӦ
ֵȻ󰴼Ӧֵ 

listbox itemdataԣlistboxÿһѡԶӦһitemdataֵ磬listbox
list1ԭʼݣlist2ѡֵ
Private Sub Form_Load()
   Dim i As Long
   For i = 0 To 9
      List1.AddItem "ֵ" & i
      List1.ItemData(List1.NewIndex) = i
   Next
End Sub
Private Sub List1_Click()
   List2.AddItem List1.ItemData(List1.ListIndex)
End Sub 


vb txtݰʽʾ
Ŀ¼и123.txtݸʽ£
100@0@300@400@500@60@700
140@206@350@400@300@600@450
100@200@300@400@500@0@5300
100@200@300@400@500@6@ 0

ʡ28У
ntextؼ7textؼΪһУ32Уһе7textؼֱΪh11, h12, 
h13,h14,h15,h16,h17, ڶеΪh221, h222, h223,h224,h225,h226,h227Դƣ
ʵЧΪ123.txt@ļĸʽֱʾtextؼУ磺100ʾ
h11, 0ʾh12, 300ʾh13, 400ʾh15, 500ʾh15, 60ʾh16, 700ʾ
h17, еҲԴƣ
ע123.txt@źͺ

textؼӦһؼźô200textҪ200ниֵ̫鷳ˣӦ
ڴϷһtextboxؼΪhindexΪ0ǹؼȻ룺
Private Sub Form_Load()
   Dim i As Long, j As Long, ss As String, s() As String
   For i = 1 To 223
      Load h(i)
   Next
   Open App.Path & "\123.txt" For Input As #1
   For j = 0 To 31
      Line Input #1, ss
      s = Split(ss, "@")
      For i = 0 To 6
         h(j * 7 + i).Text = s(i)
         h(j * 7 + i).Move i * 900 + 100, j * 350 + 100, 855, 315
         h(j * 7 + i).Visible = True
      Next
   Next
   Close #1
End Sub
⣬ôݵĴûñؼ򵥵ö


VBForm_KeyDown¼?лл!
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  Print Chr(KeyCode)
 '¼Form_KeyPress, Chr(KeyCode)Ϳ׼ȷطĸĴСд
 'û¼,ôǻ᷵شдĸ,Ϊʲô!÷...
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
Print Chr(KeyAscii)
End Sub 

keycodekeyasciiֲͬĸŶkeycodeǼ룬ÿӦһ̶룬Ҳ
˵AֱӰǰ˴дٰ߰Shiftٰkeycodeһ
̶ֵ65(A)keyasciiAscii룬ҲͨϵַAʱ򣬸
״̬Ĳͬkeyascii᷵65(A)97(a)һ£ʹkeypress¼ȡð
ַҪkeydown¼


VBadodc1еļ¼ƵrsУôд
ⲹ䣺ֱѵһеadodc1ݸڶڵadodc1ôд 
дģPublic Adodc2 As AdodcǲСӦ

ڵڶ
set adodc1.recordset=form1.adodc1.recordset
ɰѵһڵadodc1ļ¼ݵڵadodc1
ƵrsҲһĵ
dim rs as recordset
set rs=adodc1.recordset 


vbôRichTextBox1д
ʾݣһƪ£ô ôд  ɲһı棿 

RichTextBox1.Text = "abcdef"

a = "abcdef"
RichTextBox1.Text = a

RichTextBox1.FileName = "c:\123.txt"
ô


ʣVB̽*.txtļеݶ뵽ά飿
˵һļ1.txtǣ
1   0.6
2   0.3
4   0.7 



жǲ֪ģһάС
Ҫһз±1ڶз±2. 
лҪ!!! 

Private Sub Command1_Click()
Dim s() As String, r() As String, i As Long, t As String
Open "c:\1.txt" For Input As #1
i = 0
Do Until EOF(1)
   Line Input #1, t
   Do While InStr(t, "  ")
      t = Replace(t, "  ", " ")
   Loop
   r = Split(t, " ")
   If UBound(r) = 1 Then
      ReDim Preserve s(1 To 2, i)
      s(1, i) = r(0)
      s(2, i) = r(1)
      i = i + 1
   End If
Loop
Close #1
For i = 0 To UBound(s, 2)
   Print s(1, i), s(2, i)
Next
End Sub


ҼͼƬ,߱ļ,VB滻Ĺ(:ҰѼŴVBͼƬ
滻ش,ҵĵ ȵ,)ȻVBֱ𽨸  List1  Picture1
Command1 ʾ VBļͼƬ,һͼƬ,Ȼ
ͼƬĻͳ Picture1ʾ(ʾͼƬĴСպõ
 Picture1ĴСһ  ҰPicture1ó 100x100  Ȼ
ͼƬ200x200Ĵ50x50ĴС  ŪPicture1 ʾĶԶ
 100x100ĴС ) ȻCommand1  Զ ͼƬת ش
 ҵĵȵ,,, 

ͼƬã
Picture1.PaintPicture LoadPicture("ͼƬ.jpg"), 0, 0, Picture1.Width, Picture1.Height
Picture1.Picture = Picture1.Image
ͼƬʱã
SavePicture Picture1.Picture, "Ҫ滻ͼƬ.jpg"
ڲ֪νĴôʽⲿֲ˵


д֤°ͺղĳ
ıText1һڵ6żťCommand1ֽΪ
֮ͷıText2С
Ҫ
1дPrime(n)̡úʵжnǷΪ
True򷵻FalseҪı亯nʹLong͡
2Text18Text2ʾΪ8=3+5,8=5+3ֻҪһ飩
3һҪС6Text2
!ţ

Private Sub Command1_Click()
   Dim x As Long, y As Long
   x = Val(Text1.Text)
   If x < 6 Or x Mod 2 <> 0 Then
      Text2.Text = "!"
   Else
      For y = 2 To x - 2
         If Prime(y) And Prime(x - y) Then
            Text2.Text = x & "=" & y & "+" & x - y
            Exit For
         End If
      Next
      If y > x - 2 Then Text2.Text = ""
   End If
End Sub
Function Prime(n As Long) As Boolean
   Dim i As Long
   For i = 2 To n - 1
      If n Mod i = 0 Then Exit For
   Next
   Prime = i = n
End Function
Ѳȷ


VB̬ؼ
һLabel1(0 to 15)Ŀؼ
еÿԪ:
Width =200
Height =200
BackColor = QBColor(Ե±)
Visible = True
һŷForm1,Ϊ100
Ҫֻôʵ 

ȫֻôǲܵģһLabelؼҰIndexΪ0ǹؼȻ
Private Sub Form_Load()
   Dim i As Long
   For i = 1 To 15
      Load Label1(i)
   Next
   For i = 0 To 15
      Label1(i).BackColor = QBColor(i)
      Label1(i).Move i * 300, 100, 200, 200
      Label1(i).Visible = True
   Next
End Sub


VBͼִһϼƺвضʽ''Ĳѯߵȣлл
ҵĳǡSELECT AVG(ɼ) AS ƽ,.ѧ, FROM ,ɼ WHERE .ѧ='" & n & "'and ɼ.ѧ=.ѧ group by .ѧ;
ҳ˸ַʼʱûдgroup by group by аƽ ѧ д
ǰֻдƽ group by гѧ ȣ
еʱ˵ʲôûڴĲ Ĵ󡣡
˭Ը£лл~~ 

"SELECT AVG(ɼ) AS ƽ,.ѧ FROM ,ɼ WHERE .ѧ='" & n & "' and ɼ.ѧ=.ѧ group by .ѧ"
ֶܳбУΪѯʽ޷ȷǷΨһԣʹʵΨһģ
ҪҪ
"SELECT AVG(ɼ) AS ƽ,.ѧ, FROM ,ɼ WHERE .ѧ='" & n & "' and ɼ.ѧ=.ѧ group by .ѧ,"
'andҪÿո' and
Уѧֶǲֵ͵ģǾҪΪ
WHERE .ѧ=" & n & " and .....

